Skip to content

Commit

Permalink
Merge pull request #148 from German-Immersive-Railroading-Community/f…
Browse files Browse the repository at this point in the history
…eat/remoteActivator

Feat/remote activator
  • Loading branch information
MrTroble authored Oct 4, 2022
2 parents bda9adc + 904a595 commit 08cb363
Show file tree
Hide file tree
Showing 17 changed files with 837 additions and 238 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/checkstyle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
on: pull_request

jobs:
checkstyle_job:
runs-on: ubuntu-latest
name: Checkstyle job
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Run check style
uses: nikitasavinov/checkstyle-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
checkstyle_config: checkstyle.xml
reporter: "github-pr-review"
tool_name: "Checkstyle"
level: "error"
fail_on_error: true
399 changes: 399 additions & 0 deletions GIRCFormatter.xml

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## [Update]

* feat: Added remote activator

## [1.19.1-Forge]

* Updated to Forge version 1.19.1-42.0.1
Expand Down
59 changes: 59 additions & 0 deletions checkstyle.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Checkstyle//DTD Checkstyle Configuration 1.3//EN" "https://checkstyle.org/dtds/configuration_1_3.dtd">

<!--
This configuration file was written by the eclipse-cs plugin configuration editor
-->
<!--
Checkstyle-Configuration: GIRCCheckStyle
Description: none
-->
<module name="Checker">
<property name="severity" value="warning"/>
<property name="fileExtensions" value="java"/>
<module name="TreeWalker">
<module name="ConstantName"/>
<module name="AbbreviationAsWordInName"/>
<module name="IllegalIdentifierName"/>
<module name="PackageName"/>
<module name="ClassTypeParameterName"/>
<module name="LocalVariableName"/>
<module name="MethodTypeParameterName"/>
<module name="TypeName"/>
<module name="MethodName"/>
<module name="MemberName"/>
<module name="InterfaceTypeParameterName"/>
<module name="LambdaParameterName">
<property name="format" value="^[a-z_][a-zA-Z0-9]*$"/>
</module>
<module name="StaticVariableName"/>
<module name="RecordTypeParameterName"/>
<module name="ParameterName"/>
<module name="CatchParameterName"/>
<module name="PatternVariableName"/>
<module name="RecordComponentName"/>
<module name="LocalFinalVariableName"/>
<module name="RedundantImport"/>
<module name="UnusedImports"/>
<module name="Indentation">
<property name="arrayInitIndent" value="8"/>
</module>
<module name="SingleSpaceSeparator"/>
<module name="AnnotationUseStyle"/>
<module name="AnnotationLocation"/>
<module name="FinalParameters">
<property name="severity" value="warning"/>
<property name="tokens" value="METHOD_DEF,CTOR_DEF,LITERAL_CATCH,FOR_EACH_CLAUSE"/>
</module>
<module name="MissingOverride"/>
<module name="BooleanExpressionComplexity"/>
<module name="FinalClass"/>
<module name="HideUtilityClassConstructor"/>
</module>
<module name="LineLength">
<property name="max" value="120"/>
</module>
<module name="FileTabCharacter">
<property name="fileExtensions" value="java"/>
</module>
</module>
18 changes: 9 additions & 9 deletions src/main/java/eu/gir/gircredstone/GIRCRedstoneMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@

@Mod(GIRCRedstoneMain.MODID)
public class GIRCRedstoneMain {
public GIRCRedstoneMain() {
GIRCInit.init();
}
public static final Logger LOGGER = LogManager.getLogger();
public static final String MODID = "gircredstone";

public GIRCRedstoneMain() {
GIRCInit.init();
}

public static final Logger LOGGER = LogManager.getLogger();

public static final String MODID = "gircredstone";

}
58 changes: 30 additions & 28 deletions src/main/java/eu/gir/gircredstone/block/BlockRedstoneAcceptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,34 @@
import net.minecraft.world.level.block.state.properties.BooleanProperty;

public class BlockRedstoneAcceptor extends Block {

public static final BooleanProperty POWER = BooleanProperty.create("power");

public BlockRedstoneAcceptor(final Properties p_49795_) {
super(p_49795_);
this.registerDefaultState(this.defaultBlockState().setValue(POWER, false));
}

@Override
public boolean isSignalSource(final BlockState p_149744_1_) {
return true;
}

@Override
public int getSignal(final BlockState p_180656_1_, final BlockGetter p_180656_2_, final BlockPos p_180656_3_, final Direction p_180656_4_) {
return this.getDirectSignal(p_180656_1_, p_180656_2_, p_180656_3_, p_180656_4_);
}

@Override
public int getDirectSignal(final BlockState blockState, final BlockGetter p_176211_2_, final BlockPos p_176211_3_, final Direction p_176211_4_) {
return blockState.getValue(POWER) ? 15 : 0;
}

@Override
protected void createBlockStateDefinition(final Builder<Block, BlockState> builder) {
builder.add(POWER);
}


public static final BooleanProperty POWER = BooleanProperty.create("power");

public BlockRedstoneAcceptor(final Properties properties) {
super(properties);
this.registerDefaultState(this.defaultBlockState().setValue(POWER, false));
}

@Override
public boolean isSignalSource(final BlockState blockState) {
return true;
}

@Override
public int getSignal(final BlockState blockState, final BlockGetter world, final BlockPos pos,
final Direction direction) {
return this.getDirectSignal(blockState, world, pos, direction);
}

@Override
public int getDirectSignal(final BlockState blockState, final BlockGetter world,
final BlockPos pos, final Direction direction) {
return blockState.getValue(POWER) ? 15 : 0;
}

@Override
protected void createBlockStateDefinition(final Builder<Block, BlockState> builder) {
builder.add(POWER);
}

}
97 changes: 51 additions & 46 deletions src/main/java/eu/gir/gircredstone/block/BlockRedstoneEmitter.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,50 +16,55 @@
import net.minecraft.world.phys.BlockHitResult;

public class BlockRedstoneEmitter extends Block implements EntityBlock {

public BlockRedstoneEmitter(final Properties p_49795_) {
super(p_49795_);
}

@Override
public InteractionResult use(final BlockState state, final Level world, final BlockPos pos, final Player player, final InteractionHand hand, final BlockHitResult hit) {
if (world.isClientSide)
return InteractionResult.PASS;
if (player.getItemInHand(hand).getItem().equals(GIRCInit.RS_LINKER.get()))
return InteractionResult.PASS;
final BlockEntity entity = world.getBlockEntity(pos);
if (entity instanceof TileRedstoneEmitter) {
final TileRedstoneEmitter emitter = (TileRedstoneEmitter) entity;
final BlockPos linkedpos = emitter.getLinkedPos();
if (linkedpos == null) {
player.sendSystemMessage(MutableComponent.create(new TranslatableContents("em.notlinked")));
} else {
if (player.isCrouching()) {
emitter.unlink();
player.sendSystemMessage(MutableComponent.create(new TranslatableContents("em.unlink", linkedpos.getX(), linkedpos.getY(), linkedpos.getZ())));
} else {
player.sendSystemMessage(MutableComponent.create(new TranslatableContents("lt.linkedpos", linkedpos.getX(), linkedpos.getY(), linkedpos.getZ())));
}
}
return InteractionResult.SUCCESS;
}
return InteractionResult.FAIL;
}

@Override
public void neighborChanged(final BlockState state, final Level world, final BlockPos pos, final Block blockIn, final BlockPos fromPos, final boolean isMoving) {
if (world.isClientSide)
return;
final BlockEntity entity = world.getBlockEntity(pos);
if (entity instanceof TileRedstoneEmitter) {
final TileRedstoneEmitter emitter = (TileRedstoneEmitter) entity;
emitter.redstoneUpdate(world.hasNeighborSignal(pos));
}
}

@Override
public BlockEntity newBlockEntity(final BlockPos arg0, final BlockState arg1) {
return new TileRedstoneEmitter(arg0, arg1);
}


public BlockRedstoneEmitter(final Properties properties) {
super(properties);
}

@Override
public InteractionResult use(final BlockState state, final Level world, final BlockPos pos,
final Player player, final InteractionHand hand, final BlockHitResult hit) {
if (world.isClientSide)
return InteractionResult.PASS;
if (player.getItemInHand(hand).getItem().equals(GIRCInit.RS_LINKER.get()))
return InteractionResult.PASS;
final BlockEntity entity = world.getBlockEntity(pos);
if (entity instanceof TileRedstoneEmitter) {
final TileRedstoneEmitter emitter = (TileRedstoneEmitter) entity;
final BlockPos linkedpos = emitter.getLinkedPos();
if (linkedpos == null) {
player.sendSystemMessage(
MutableComponent.create(new TranslatableContents("em.notlinked")));
} else {
if (player.isCrouching()) {
emitter.unlink();
player.sendSystemMessage(MutableComponent.create(new TranslatableContents(
"em.unlink", linkedpos.getX(), linkedpos.getY(), linkedpos.getZ())));
} else {
player.sendSystemMessage(MutableComponent.create(new TranslatableContents(
"lt.linkedpos", linkedpos.getX(), linkedpos.getY(), linkedpos.getZ())));
}
}
return InteractionResult.SUCCESS;
}
return InteractionResult.FAIL;
}

@Override
public void neighborChanged(final BlockState state, final Level world, final BlockPos pos,
final Block blockIn, final BlockPos fromPos, final boolean isMoving) {
if (world.isClientSide)
return;
final BlockEntity entity = world.getBlockEntity(pos);
if (entity instanceof TileRedstoneEmitter) {
final TileRedstoneEmitter emitter = (TileRedstoneEmitter) entity;
emitter.redstoneUpdate(world.hasNeighborSignal(pos));
}
}

@Override
public BlockEntity newBlockEntity(final BlockPos pos, final BlockState state) {
return new TileRedstoneEmitter(pos, state);
}

}
65 changes: 40 additions & 25 deletions src/main/java/eu/gir/gircredstone/init/GIRCInit.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import eu.gir.gircredstone.block.BlockRedstoneAcceptor;
import eu.gir.gircredstone.block.BlockRedstoneEmitter;
import eu.gir.gircredstone.item.Linkingtool;
import eu.gir.gircredstone.item.RemoteActivator;
import eu.gir.gircredstone.tile.TileRedstoneEmitter;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.CreativeModeTab;
Expand All @@ -22,29 +23,43 @@
import net.minecraftforge.registries.RegistryObject;

public class GIRCInit {

public static final DeferredRegister<Item> ITEM_REGISTRY = DeferredRegister.create(ForgeRegistries.ITEMS, GIRCRedstoneMain.MODID);
public static final DeferredRegister<Block> BLOCK_REGISTRY = DeferredRegister.create(ForgeRegistries.BLOCKS, GIRCRedstoneMain.MODID);
public static final DeferredRegister<BlockEntityType<?>> TILEENTITY_REGISTRY = DeferredRegister.create(ForgeRegistries.BLOCK_ENTITY_TYPES, GIRCRedstoneMain.MODID);

public static RegistryObject<Block> RS_ACCEPTOR = internalRegisterBlock("acceptor", () -> new BlockRedstoneAcceptor(BlockBehaviour.Properties.of(Material.METAL).strength(1.5f, 6.0f).requiresCorrectToolForDrops()));
public static RegistryObject<Block> RS_EMITTER = internalRegisterBlock("emitter", () -> new BlockRedstoneEmitter(BlockBehaviour.Properties.of(Material.METAL).strength(1.5f, 6.0f).requiresCorrectToolForDrops()));

public static RegistryObject<Item> RS_LINKER = ITEM_REGISTRY.register("linker", () -> new Linkingtool(new Properties().tab(CreativeModeTab.TAB_REDSTONE)));

public static RegistryObject<BlockEntityType<?>> EMITER_TILE = TILEENTITY_REGISTRY.register("emitter", () -> BlockEntityType.Builder.of(TileRedstoneEmitter::new, RS_EMITTER.get()).build(null));

private static RegistryObject<Block> internalRegisterBlock(final String name, final Supplier<Block> sup) {
final RegistryObject<Block> registerObject = BLOCK_REGISTRY.register(name, sup);
ITEM_REGISTRY.register(name, () -> new BlockItem(registerObject.get(), new Properties().tab(CreativeModeTab.TAB_REDSTONE)));
return registerObject;
}

public static void init() {
final IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus();
ITEM_REGISTRY.register(bus);
BLOCK_REGISTRY.register(bus);
TILEENTITY_REGISTRY.register(bus);
}


public static final DeferredRegister<Item> ITEM_REGISTRY = DeferredRegister
.create(ForgeRegistries.ITEMS, GIRCRedstoneMain.MODID);
public static final DeferredRegister<Block> BLOCK_REGISTRY = DeferredRegister
.create(ForgeRegistries.BLOCKS, GIRCRedstoneMain.MODID);
public static final DeferredRegister<BlockEntityType<?>> TILEENTITY_REGISTRY = DeferredRegister
.create(ForgeRegistries.BLOCK_ENTITY_TYPES, GIRCRedstoneMain.MODID);

public static final RegistryObject<Block> RS_ACCEPTOR = internalRegisterBlock("acceptor",
() -> new BlockRedstoneAcceptor(BlockBehaviour.Properties.of(Material.METAL)
.strength(1.5f, 6.0f).requiresCorrectToolForDrops()));
public static final RegistryObject<Block> RS_EMITTER = internalRegisterBlock("emitter",
() -> new BlockRedstoneEmitter(BlockBehaviour.Properties.of(Material.METAL)
.strength(1.5f, 6.0f).requiresCorrectToolForDrops()));

public static final RegistryObject<Item> RS_LINKER = ITEM_REGISTRY.register("linker",
() -> new Linkingtool(new Properties().tab(CreativeModeTab.TAB_REDSTONE)));
public static final RegistryObject<Item> REMOTE_ACTIVATOR = ITEM_REGISTRY.register("activator",
() -> new RemoteActivator(new Properties().tab(CreativeModeTab.TAB_REDSTONE)));

public static final RegistryObject<BlockEntityType<?>> EMITER_TILE = TILEENTITY_REGISTRY
.register("emitter", () -> BlockEntityType.Builder
.of(TileRedstoneEmitter::new, RS_EMITTER.get()).build(null));

private static final RegistryObject<Block> internalRegisterBlock(final String name,
final Supplier<Block> sup) {
final RegistryObject<Block> registerObject = BLOCK_REGISTRY.register(name, sup);
ITEM_REGISTRY.register(name, () -> new BlockItem(registerObject.get(),
new Properties().tab(CreativeModeTab.TAB_REDSTONE)));
return registerObject;
}

public static void init() {
final IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus();
ITEM_REGISTRY.register(bus);
BLOCK_REGISTRY.register(bus);
TILEENTITY_REGISTRY.register(bus);
}

}
Loading

0 comments on commit 08cb363

Please sign in to comment.