Skip to content

Commit

Permalink
Merge pull request #149 from German-Immersive-Railroading-Community/1…
Browse files Browse the repository at this point in the history
….18-backport

feat: added remote activator
  • Loading branch information
MrTroble authored Oct 5, 2022
2 parents 0f3518d + 0d50c77 commit fe9c482
Show file tree
Hide file tree
Showing 16 changed files with 841 additions and 243 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

## [Internal]

* Internal forge update
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 state) {
return true;
}

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

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

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

}
98 changes: 51 additions & 47 deletions src/main/java/eu/gir/gircredstone/block/BlockRedstoneEmitter.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,51 +17,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);
final UUID uuid = player.getUUID();
if (entity instanceof TileRedstoneEmitter) {
final TileRedstoneEmitter emitter = (TileRedstoneEmitter) entity;
final BlockPos linkedpos = emitter.getLinkedPos();
if (linkedpos == null) {
player.sendMessage(new TranslatableComponent("em.notlinked"), uuid);
} else {
if (player.isCrouching()) {
emitter.unlink();
player.sendMessage(new TranslatableComponent("em.unlink", linkedpos.getX(), linkedpos.getY(), linkedpos.getZ()), uuid);
} else {
player.sendMessage(new TranslatableComponent("lt.linkedpos", linkedpos.getX(), linkedpos.getY(), linkedpos.getZ()), uuid);
}
}
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);
final UUID uuid = player.getUUID();
if (entity instanceof TileRedstoneEmitter) {
final TileRedstoneEmitter emitter = (TileRedstoneEmitter) entity;
final BlockPos linkedpos = emitter.getLinkedPos();
if (linkedpos == null) {
player.sendMessage(new TranslatableComponent("em.notlinked"), uuid);
} else {
if (player.isCrouching()) {
emitter.unlink();
player.sendMessage(new TranslatableComponent("em.unlink", linkedpos.getX(),
linkedpos.getY(), linkedpos.getZ()), uuid);
} else {
player.sendMessage(new TranslatableComponent("lt.linkedpos", linkedpos.getX(),
linkedpos.getY(), linkedpos.getZ()), uuid);
}
}
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_ENTITIES, 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_ENTITIES, 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 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 fe9c482

Please sign in to comment.