diff --git a/src/main/java/com/simibubi/create/AllBlocks.java b/src/main/java/com/simibubi/create/AllBlocks.java index be8a903dd..983e9d35f 100644 --- a/src/main/java/com/simibubi/create/AllBlocks.java +++ b/src/main/java/com/simibubi/create/AllBlocks.java @@ -12,10 +12,16 @@ import com.simibubi.create.AllTags.AllBlockTags; import com.simibubi.create.content.AllSections; import com.simibubi.create.content.contraptions.base.CasingBlock; import com.simibubi.create.content.contraptions.components.actors.DrillBlock; +import com.simibubi.create.content.contraptions.components.actors.DrillMovementBehaviour; import com.simibubi.create.content.contraptions.components.actors.HarvesterBlock; +import com.simibubi.create.content.contraptions.components.actors.HarvesterMovementBehaviour; import com.simibubi.create.content.contraptions.components.actors.PloughBlock; +import com.simibubi.create.content.contraptions.components.actors.PloughMovementBehaviour; import com.simibubi.create.content.contraptions.components.actors.PortableStorageInterfaceBlock; +import com.simibubi.create.content.contraptions.components.actors.SawMovementBehaviour; import com.simibubi.create.content.contraptions.components.actors.SeatBlock; +import com.simibubi.create.content.contraptions.components.actors.SeatMovementBehaviour; +import com.simibubi.create.content.contraptions.components.actors.StorageInterfaceMovement; import com.simibubi.create.content.contraptions.components.clock.CuckooClockBlock; import com.simibubi.create.content.contraptions.components.crafter.CrafterCTBehaviour; import com.simibubi.create.content.contraptions.components.crafter.MechanicalCrafterBlock; @@ -23,6 +29,7 @@ import com.simibubi.create.content.contraptions.components.crank.HandCrankBlock; import com.simibubi.create.content.contraptions.components.crusher.CrushingWheelBlock; import com.simibubi.create.content.contraptions.components.crusher.CrushingWheelControllerBlock; import com.simibubi.create.content.contraptions.components.deployer.DeployerBlock; +import com.simibubi.create.content.contraptions.components.deployer.DeployerMovementBehaviour; import com.simibubi.create.content.contraptions.components.fan.EncasedFanBlock; import com.simibubi.create.content.contraptions.components.fan.NozzleBlock; import com.simibubi.create.content.contraptions.components.flywheel.FlywheelBlock; @@ -98,6 +105,7 @@ import com.simibubi.create.content.logistics.block.diodes.PulseRepeaterGenerator import com.simibubi.create.content.logistics.block.diodes.ToggleLatchBlock; import com.simibubi.create.content.logistics.block.diodes.ToggleLatchGenerator; import com.simibubi.create.content.logistics.block.extractor.ExtractorBlock; +import com.simibubi.create.content.logistics.block.extractor.ExtractorMovementBehaviour; import com.simibubi.create.content.logistics.block.extractor.LinkedExtractorBlock; import com.simibubi.create.content.logistics.block.extractor.VerticalExtractorGenerator; import com.simibubi.create.content.logistics.block.funnel.AndesiteBeltFunnelBlock; @@ -114,6 +122,7 @@ import com.simibubi.create.content.logistics.block.mechanicalArm.ArmBlock; import com.simibubi.create.content.logistics.block.mechanicalArm.ArmItem; import com.simibubi.create.content.logistics.block.packager.PackagerBlock; import com.simibubi.create.content.logistics.block.redstone.AnalogLeverBlock; +import com.simibubi.create.content.logistics.block.redstone.ContactMovementBehaviour; import com.simibubi.create.content.logistics.block.redstone.NixieTubeBlock; import com.simibubi.create.content.logistics.block.redstone.NixieTubeGenerator; import com.simibubi.create.content.logistics.block.redstone.RedstoneContactBlock; @@ -605,6 +614,7 @@ public class AllBlocks { .initialProperties(SharedProperties::stone) .blockstate(BlockStateGen.directionalBlockProvider(true)) .transform(StressConfigDefaults.setImpact(4.0)) + .onRegister(AllMovementBehaviours.addMovementBehaviour(new DrillMovementBehaviour())) .item() .transform(customItemModel()) .register(); @@ -613,6 +623,7 @@ public class AllBlocks { .initialProperties(SharedProperties::stone) .blockstate(new SawGenerator()::generate) .transform(StressConfigDefaults.setImpact(4.0)) + .onRegister(AllMovementBehaviours.addMovementBehaviour(new SawMovementBehaviour())) .addLayer(() -> RenderType::getCutoutMipped) .item() .model((c, p) -> p.blockItem(() -> c.getEntry() @@ -624,6 +635,7 @@ public class AllBlocks { .initialProperties(SharedProperties::stone) .blockstate(BlockStateGen.directionalAxisBlockProvider()) .transform(StressConfigDefaults.setImpact(4.0)) + .onRegister(AllMovementBehaviours.addMovementBehaviour(new DeployerMovementBehaviour())) .item() .transform(customItemModel()) .register(); @@ -631,6 +643,7 @@ public class AllBlocks { public static final BlockEntry PORTABLE_STORAGE_INTERFACE = REGISTRATE.block("portable_storage_interface", PortableStorageInterfaceBlock::new) .initialProperties(SharedProperties::stone) + .onRegister(AllMovementBehaviours.addMovementBehaviour(new StorageInterfaceMovement())) .blockstate(BlockStateGen.directionalBlockProvider(false)) .simpleItem() .register(); @@ -638,6 +651,7 @@ public class AllBlocks { public static final BlockEntry MECHANICAL_HARVESTER = REGISTRATE.block("mechanical_harvester", HarvesterBlock::new) .initialProperties(SharedProperties::stone) + .onRegister(AllMovementBehaviours.addMovementBehaviour(new HarvesterMovementBehaviour())) .blockstate(BlockStateGen.horizontalBlockProvider(true)) .addLayer(() -> RenderType::getCutoutMipped) .item() @@ -647,6 +661,7 @@ public class AllBlocks { public static final BlockEntry MECHANICAL_PLOUGH = REGISTRATE.block("mechanical_plough", PloughBlock::new) .initialProperties(SharedProperties::stone) + .onRegister(AllMovementBehaviours.addMovementBehaviour(new PloughMovementBehaviour())) .blockstate(BlockStateGen.horizontalBlockProvider(false)) .simpleItem() .register(); @@ -656,6 +671,7 @@ public class AllBlocks { String colourName = colour.getName(); REGISTRATE.block(colourName + "_seat", p -> new SeatBlock(p, colour == DyeColor.RED)) .initialProperties(SharedProperties::wooden) + .onRegister(AllMovementBehaviours.addMovementBehaviour(new SeatMovementBehaviour())) .blockstate((c, p) -> { p.simpleBlock(c.get(), p.models() .withExistingParent(colourName + "_seat", p.modLoc("block/seat")) @@ -812,6 +828,7 @@ public class AllBlocks { public static final BlockEntry REDSTONE_CONTACT = REGISTRATE.block("redstone_contact", RedstoneContactBlock::new) .initialProperties(SharedProperties::stone) + .onRegister(AllMovementBehaviours.addMovementBehaviour(new ContactMovementBehaviour())) .blockstate((c, p) -> p.directionalBlock(c.get(), AssetLookup.forPowered(c, p))) .item() .transform(customItemModel("_", "block")) @@ -878,6 +895,7 @@ public class AllBlocks { public static final BlockEntry EXTRACTOR = REGISTRATE.block("extractor", ExtractorBlock::new) .initialProperties(SharedProperties::softMetal) .tag(AllBlockTags.BRITTLE.tag) + .onRegister(AllMovementBehaviours.addMovementBehaviour(new ExtractorMovementBehaviour())) .blockstate((c, p) -> p.horizontalBlock(c.get(), AssetLookup.forPowered(c, p, c.getName() + "/horizontal"))) .item() .transform(customItemModel("_", "horizontal")) diff --git a/src/main/java/com/simibubi/create/AllMovementBehaviours.java b/src/main/java/com/simibubi/create/AllMovementBehaviours.java new file mode 100644 index 000000000..924f1c5dd --- /dev/null +++ b/src/main/java/com/simibubi/create/AllMovementBehaviours.java @@ -0,0 +1,38 @@ +package com.simibubi.create; + +import com.simibubi.create.content.contraptions.components.structureMovement.MovementBehaviour; +import com.tterrag.registrate.util.nullness.NonNullConsumer; +import net.minecraft.block.Block; +import net.minecraft.util.ResourceLocation; + +import javax.annotation.Nullable; +import java.util.HashMap; + +public class AllMovementBehaviours { + private static final HashMap movementBehaviours = new HashMap<>(); + + public static void addMovementBehaviour(ResourceLocation resourceLocation, MovementBehaviour movementBehaviour) { + movementBehaviours.put(resourceLocation, movementBehaviour); + } + + @Nullable + public static MovementBehaviour getMovementBehaviour(ResourceLocation resourceLocation) { + return movementBehaviours.getOrDefault(resourceLocation, null); + } + + @Nullable + public static MovementBehaviour getMovementBehaviour(Block block) { + return getMovementBehaviour(block.getRegistryName()); + } + + public static boolean hasMovementBehaviour(Block block) { + return movementBehaviours.containsKey(block.getRegistryName()); + } + + public static NonNullConsumer addMovementBehaviour( + MovementBehaviour movementBehaviour) { + return b -> addMovementBehaviour(b.getRegistryName(), movementBehaviour); + } + + static void register() {} +} diff --git a/src/main/java/com/simibubi/create/Create.java b/src/main/java/com/simibubi/create/Create.java index 765c5bb55..addfa5821 100644 --- a/src/main/java/com/simibubi/create/Create.java +++ b/src/main/java/com/simibubi/create/Create.java @@ -63,6 +63,7 @@ public class Create { AllPaletteBlocks.register(); AllEntityTypes.register(); AllTileEntities.register(); + AllMovementBehaviours.register(); modEventBus.addListener(Create::init); modEventBus.addGenericListener(IRecipeSerializer.class, AllRecipeTypes::register); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/AttachedActorBlock.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/AttachedActorBlock.java index ccde0e5fa..161d1828f 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/AttachedActorBlock.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/AttachedActorBlock.java @@ -1,9 +1,9 @@ package com.simibubi.create.content.contraptions.components.actors; import com.simibubi.create.AllShapes; -import com.simibubi.create.content.contraptions.components.structureMovement.IPortableBlock; import com.simibubi.create.content.contraptions.wrench.IWrenchable; +import mcp.MethodsReturnNonnullByDefault; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.HorizontalBlock; @@ -18,7 +18,11 @@ import net.minecraft.util.math.shapes.VoxelShape; import net.minecraft.world.IBlockReader; import net.minecraft.world.IWorldReader; -public abstract class AttachedActorBlock extends HorizontalBlock implements IPortableBlock, IWrenchable { +import javax.annotation.ParametersAreNonnullByDefault; + +@ParametersAreNonnullByDefault +@MethodsReturnNonnullByDefault +public abstract class AttachedActorBlock extends HorizontalBlock implements IWrenchable { protected AttachedActorBlock(Properties p_i48377_1_) { super(p_i48377_1_); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillBlock.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillBlock.java index 219387d3f..74eb40d0d 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillBlock.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillBlock.java @@ -3,8 +3,6 @@ package com.simibubi.create.content.contraptions.components.actors; import com.simibubi.create.AllShapes; import com.simibubi.create.AllTileEntities; import com.simibubi.create.content.contraptions.base.DirectionalKineticBlock; -import com.simibubi.create.content.contraptions.components.structureMovement.IPortableBlock; -import com.simibubi.create.content.contraptions.components.structureMovement.MovementBehaviour; import com.simibubi.create.foundation.block.ITE; import net.minecraft.block.Block; @@ -25,9 +23,12 @@ import net.minecraft.world.IBlockReader; import net.minecraft.world.IWorldReader; import net.minecraft.world.World; -public class DrillBlock extends DirectionalKineticBlock implements IPortableBlock, ITE { +import javax.annotation.ParametersAreNonnullByDefault; +import mcp.MethodsReturnNonnullByDefault; - public static MovementBehaviour MOVEMENT = new DrillMovementBehaviour(); +@ParametersAreNonnullByDefault +@MethodsReturnNonnullByDefault +public class DrillBlock extends DirectionalKineticBlock implements ITE { public static DamageSource damageSourceDrill = new DamageSource("create.drill").setDamageBypassesArmor(); public DrillBlock(Properties properties) { @@ -83,11 +84,6 @@ public class DrillBlock extends DirectionalKineticBlock implements IPortableBloc return PushReaction.NORMAL; } - @Override - public MovementBehaviour getMovementBehaviour() { - return MOVEMENT; - } - @Override public Class getTileEntityClass() { return DrillTileEntity.class; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterBlock.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterBlock.java index 6c5bdee4d..68a6b5ad8 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterBlock.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterBlock.java @@ -1,16 +1,12 @@ package com.simibubi.create.content.contraptions.components.actors; import com.simibubi.create.AllTileEntities; -import com.simibubi.create.content.contraptions.components.structureMovement.IPortableBlock; -import com.simibubi.create.content.contraptions.components.structureMovement.MovementBehaviour; import net.minecraft.block.BlockState; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.IBlockReader; -public class HarvesterBlock extends AttachedActorBlock implements IPortableBlock { - - public static MovementBehaviour MOVEMENT = new HarvesterMovementBehaviour(); +public class HarvesterBlock extends AttachedActorBlock { public HarvesterBlock(Properties p_i48377_1_) { super(p_i48377_1_); @@ -25,10 +21,4 @@ public class HarvesterBlock extends AttachedActorBlock implements IPortableBlock public TileEntity createTileEntity(BlockState state, IBlockReader world) { return new HarvesterTileEntity(AllTileEntities.HARVESTER.get()); } - - @Override - public MovementBehaviour getMovementBehaviour() { - return MOVEMENT; - } - } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/PloughBlock.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/PloughBlock.java index ad3b53960..686fbc86f 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/PloughBlock.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/PloughBlock.java @@ -9,17 +9,10 @@ import net.minecraft.world.server.ServerWorld; import net.minecraftforge.common.util.FakePlayer; public class PloughBlock extends AttachedActorBlock { - - public static MovementBehaviour MOVEMENT = new PloughMovementBehaviour(); public PloughBlock(Properties p_i48377_1_) { super(p_i48377_1_); } - - @Override - public MovementBehaviour getMovementBehaviour() { - return MOVEMENT; - } /** * The OnHoeUse event takes a player, so we better not pass null diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/PortableStorageInterfaceBlock.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/PortableStorageInterfaceBlock.java index 5f10333fc..a992df339 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/PortableStorageInterfaceBlock.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/PortableStorageInterfaceBlock.java @@ -1,8 +1,6 @@ package com.simibubi.create.content.contraptions.components.actors; import com.simibubi.create.AllShapes; -import com.simibubi.create.content.contraptions.components.structureMovement.IPortableBlock; -import com.simibubi.create.content.contraptions.components.structureMovement.MovementBehaviour; import com.simibubi.create.foundation.block.ProperDirectionalBlock; import net.minecraft.block.BlockState; @@ -12,9 +10,13 @@ import net.minecraft.util.math.shapes.ISelectionContext; import net.minecraft.util.math.shapes.VoxelShape; import net.minecraft.world.IBlockReader; -public class PortableStorageInterfaceBlock extends ProperDirectionalBlock implements IPortableBlock { - public static MovementBehaviour MOVEMENT = new StorageInterfaceMovement(); +import javax.annotation.ParametersAreNonnullByDefault; +import mcp.MethodsReturnNonnullByDefault; + +@ParametersAreNonnullByDefault +@MethodsReturnNonnullByDefault +public class PortableStorageInterfaceBlock extends ProperDirectionalBlock { public PortableStorageInterfaceBlock(Properties p_i48415_1_) { super(p_i48415_1_); @@ -31,9 +33,4 @@ public class PortableStorageInterfaceBlock extends ProperDirectionalBlock implem return AllShapes.PORTABLE_STORAGE_INTERFACE.get(state.get(FACING)); } - @Override - public MovementBehaviour getMovementBehaviour() { - return MOVEMENT; - } - } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/SeatBlock.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/SeatBlock.java index fb4d5c96f..584df561a 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/SeatBlock.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/SeatBlock.java @@ -3,8 +3,6 @@ package com.simibubi.create.content.contraptions.components.actors; import java.util.List; import com.simibubi.create.AllShapes; -import com.simibubi.create.content.contraptions.components.structureMovement.IPortableBlock; -import com.simibubi.create.content.contraptions.components.structureMovement.MovementBehaviour; import net.minecraft.block.Block; import net.minecraft.block.BlockState; @@ -27,10 +25,16 @@ import net.minecraft.util.math.shapes.VoxelShape; import net.minecraft.world.IBlockReader; import net.minecraft.world.World; -public class SeatBlock extends Block implements IPortableBlock { - public static MovementBehaviour MOVEMENT = new SeatMovementBehaviour(); - private boolean inCreativeTab; +import javax.annotation.Nullable; +import javax.annotation.ParametersAreNonnullByDefault; +import mcp.MethodsReturnNonnullByDefault; + +@ParametersAreNonnullByDefault +@MethodsReturnNonnullByDefault +public class SeatBlock extends Block { + + private final boolean inCreativeTab; public SeatBlock(Properties p_i48440_1_, boolean inCreativeTab) { super(p_i48440_1_); @@ -63,7 +67,7 @@ public class SeatBlock extends Block implements IPortableBlock { } @Override - public PathNodeType getAiPathNodeType(BlockState state, IBlockReader world, BlockPos pos, MobEntity entity) { + public PathNodeType getAiPathNodeType(BlockState state, IBlockReader world, BlockPos pos, @Nullable MobEntity entity) { return PathNodeType.RAIL; } @@ -118,8 +122,4 @@ public class SeatBlock extends Block implements IPortableBlock { entity.startRiding(seat, true); } - @Override - public MovementBehaviour getMovementBehaviour() { - return MOVEMENT; - } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerBlock.java b/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerBlock.java index 04c958125..4e407038a 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerBlock.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerBlock.java @@ -4,8 +4,6 @@ import com.simibubi.create.AllItems; import com.simibubi.create.AllShapes; import com.simibubi.create.AllTileEntities; import com.simibubi.create.content.contraptions.base.DirectionalAxisKineticBlock; -import com.simibubi.create.content.contraptions.components.structureMovement.IPortableBlock; -import com.simibubi.create.content.contraptions.components.structureMovement.MovementBehaviour; import com.simibubi.create.foundation.block.ITE; import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour; import com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringBehaviour; @@ -25,9 +23,12 @@ import net.minecraft.util.math.shapes.VoxelShape; import net.minecraft.world.IBlockReader; import net.minecraft.world.World; -public class DeployerBlock extends DirectionalAxisKineticBlock implements ITE, IPortableBlock { +import javax.annotation.ParametersAreNonnullByDefault; +import mcp.MethodsReturnNonnullByDefault; - public static MovementBehaviour MOVEMENT = new DeployerMovementBehaviour(); +@ParametersAreNonnullByDefault +@MethodsReturnNonnullByDefault +public class DeployerBlock extends DirectionalAxisKineticBlock implements ITE { public DeployerBlock(Properties properties) { super(properties); @@ -102,11 +103,6 @@ public class DeployerBlock extends DirectionalAxisKineticBlock implements ITE getTileEntityClass() { return DeployerTileEntity.class; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawBlock.java b/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawBlock.java index 95f247870..8ec99f1b9 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawBlock.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawBlock.java @@ -3,9 +3,6 @@ package com.simibubi.create.content.contraptions.components.saw; import com.simibubi.create.AllShapes; import com.simibubi.create.AllTileEntities; import com.simibubi.create.content.contraptions.base.DirectionalAxisKineticBlock; -import com.simibubi.create.content.contraptions.components.actors.SawMovementBehaviour; -import com.simibubi.create.content.contraptions.components.structureMovement.IPortableBlock; -import com.simibubi.create.content.contraptions.components.structureMovement.MovementBehaviour; import com.simibubi.create.foundation.block.ITE; import com.simibubi.create.foundation.item.ItemHelper; import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour; @@ -32,11 +29,15 @@ import net.minecraft.world.IBlockReader; import net.minecraft.world.IWorldReader; import net.minecraft.world.World; -public class SawBlock extends DirectionalAxisKineticBlock implements ITE, IPortableBlock { +import javax.annotation.ParametersAreNonnullByDefault; +import mcp.MethodsReturnNonnullByDefault; + +@ParametersAreNonnullByDefault +@MethodsReturnNonnullByDefault +public class SawBlock extends DirectionalAxisKineticBlock implements ITE { public static final BooleanProperty RUNNING = BooleanProperty.create("running"); public static DamageSource damageSourceSaw = new DamageSource("create.saw").setDamageBypassesArmor(); - public static MovementBehaviour MOVEMENT = new SawMovementBehaviour(); public SawBlock(Properties properties) { super(properties); @@ -127,11 +128,6 @@ public class SawBlock extends DirectionalAxisKineticBlock implements ITE getTileEntityClass() { return SawTileEntity.class; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/Contraption.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/Contraption.java index e93612c77..42caef70d 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/Contraption.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/Contraption.java @@ -17,6 +17,7 @@ import java.util.stream.Collectors; import javax.annotation.Nullable; +import com.simibubi.create.AllMovementBehaviours; import org.apache.commons.lang3.tuple.MutablePair; import org.apache.commons.lang3.tuple.Pair; @@ -146,9 +147,9 @@ public abstract class Contraption { protected static MovementBehaviour getMovement(BlockState state) { Block block = state.getBlock(); - if (!(block instanceof IPortableBlock)) + if (!AllMovementBehaviours.hasMovementBehaviour(block)) return null; - return ((IPortableBlock) block).getMovementBehaviour(); + return AllMovementBehaviours.getMovementBehaviour(block); } public Set getColliders(World world, Direction movementDirection) { @@ -439,7 +440,7 @@ public abstract class Contraption { TileEntity te = pair.getValue(); if (te != null && MountedStorage.canUseAsStorage(te)) storage.put(localPos, new MountedStorage(te)); - if (captured.state.getBlock() instanceof IPortableBlock) + if (AllMovementBehaviours.hasMovementBehaviour(captured.state.getBlock())) actors.add(MutablePair.of(blockInfo, null)); } @@ -463,7 +464,7 @@ public abstract class Contraption { else renderOrder.add(0, info.pos); CompoundNBT tag = info.nbt; - if (tag == null || block instanceof IPortableBlock) + if (tag == null || AllMovementBehaviours.hasMovementBehaviour(block)) return; tag.putInt("x", info.pos.getX()); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionCollider.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionCollider.java index dee4afe93..9cc0d311c 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionCollider.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionCollider.java @@ -9,6 +9,7 @@ import java.util.Iterator; import java.util.List; import java.util.stream.Stream; +import com.simibubi.create.AllMovementBehaviours; import org.apache.commons.lang3.mutable.MutableBoolean; import org.apache.commons.lang3.mutable.MutableObject; @@ -393,11 +394,11 @@ public class ContraptionCollider { BlockState collidedState = world.getBlockState(colliderPos); BlockInfo blockInfo = contraption.blocks.get(pos); - if (blockInfo.state.getBlock() instanceof IPortableBlock) { - IPortableBlock block = (IPortableBlock) blockInfo.state.getBlock(); - if (block.getMovementBehaviour() instanceof BlockBreakingMovementBehaviour) { + if (AllMovementBehaviours.hasMovementBehaviour(blockInfo.state.getBlock())) { + MovementBehaviour movementBehaviour = AllMovementBehaviours.getMovementBehaviour(blockInfo.state.getBlock()); + if (movementBehaviour instanceof BlockBreakingMovementBehaviour) { BlockBreakingMovementBehaviour behaviour = - (BlockBreakingMovementBehaviour) block.getMovementBehaviour(); + (BlockBreakingMovementBehaviour) movementBehaviour; if (!behaviour.canBreak(world, colliderPos, collidedState) && !collidedState.getCollisionShape(world, pos) .isEmpty()) { diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/IPortableBlock.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/IPortableBlock.java deleted file mode 100644 index 8c889fb12..000000000 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/IPortableBlock.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.simibubi.create.content.contraptions.components.structureMovement; - -public interface IPortableBlock { - - public MovementBehaviour getMovementBehaviour(); - -} diff --git a/src/main/java/com/simibubi/create/content/logistics/block/extractor/ExtractorBlock.java b/src/main/java/com/simibubi/create/content/logistics/block/extractor/ExtractorBlock.java index 11c53eec1..1cd5657b6 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/extractor/ExtractorBlock.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/extractor/ExtractorBlock.java @@ -3,8 +3,6 @@ package com.simibubi.create.content.logistics.block.extractor; import com.simibubi.create.AllBlocks; import com.simibubi.create.AllShapes; import com.simibubi.create.AllTileEntities; -import com.simibubi.create.content.contraptions.components.structureMovement.IPortableBlock; -import com.simibubi.create.content.contraptions.components.structureMovement.MovementBehaviour; import com.simibubi.create.content.logistics.block.AttachedLogisticalBlock; import com.simibubi.create.content.logistics.block.belts.BeltAttachableLogisticalBlock; import com.simibubi.create.foundation.utility.AngleHelper; @@ -25,10 +23,9 @@ import net.minecraft.util.math.shapes.VoxelShape; import net.minecraft.world.IBlockReader; import net.minecraft.world.World; -public class ExtractorBlock extends BeltAttachableLogisticalBlock implements IPortableBlock { +public class ExtractorBlock extends BeltAttachableLogisticalBlock { public static BooleanProperty POWERED = BlockStateProperties.POWERED; - private static final MovementBehaviour MOVEMENT = new ExtractorMovementBehaviour(); public ExtractorBlock(Properties properties) { super(properties); @@ -127,9 +124,4 @@ public class ExtractorBlock extends BeltAttachableLogisticalBlock implements IPo } } - @Override - public MovementBehaviour getMovementBehaviour() { - return MOVEMENT; - } - } \ No newline at end of file diff --git a/src/main/java/com/simibubi/create/content/logistics/block/redstone/RedstoneContactBlock.java b/src/main/java/com/simibubi/create/content/logistics/block/redstone/RedstoneContactBlock.java index 72ea19d51..6f4286162 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/redstone/RedstoneContactBlock.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/redstone/RedstoneContactBlock.java @@ -3,8 +3,6 @@ package com.simibubi.create.content.logistics.block.redstone; import java.util.Random; import com.simibubi.create.AllBlocks; -import com.simibubi.create.content.contraptions.components.structureMovement.IPortableBlock; -import com.simibubi.create.content.contraptions.components.structureMovement.MovementBehaviour; import com.simibubi.create.content.contraptions.wrench.IWrenchable; import com.simibubi.create.foundation.block.ProperDirectionalBlock; @@ -21,10 +19,15 @@ import net.minecraft.world.IWorld; import net.minecraft.world.World; import net.minecraft.world.server.ServerWorld; -public class RedstoneContactBlock extends ProperDirectionalBlock implements IPortableBlock, IWrenchable { +import javax.annotation.Nullable; +import javax.annotation.ParametersAreNonnullByDefault; +import mcp.MethodsReturnNonnullByDefault; + +@ParametersAreNonnullByDefault +@MethodsReturnNonnullByDefault +public class RedstoneContactBlock extends ProperDirectionalBlock implements IWrenchable { public static final BooleanProperty POWERED = BlockStateProperties.POWERED; - public static MovementBehaviour MOVEMENT = new ContactMovementBehaviour(); public RedstoneContactBlock(Properties properties) { super(properties); @@ -94,7 +97,7 @@ public class RedstoneContactBlock extends ProperDirectionalBlock implements IPor } @Override - public boolean canConnectRedstone(BlockState state, IBlockReader world, BlockPos pos, Direction side) { + public boolean canConnectRedstone(BlockState state, IBlockReader world, BlockPos pos, @Nullable Direction side) { if (side == null) return true; return state.get(FACING) != side.getOpposite(); @@ -105,9 +108,4 @@ public class RedstoneContactBlock extends ProperDirectionalBlock implements IPor return state.get(POWERED) ? 15 : 0; } - @Override - public MovementBehaviour getMovementBehaviour() { - return MOVEMENT; - } - }