From 0bd3a8d880c9915140efd04437b4bc7498dfcb3c Mon Sep 17 00:00:00 2001 From: simibubi <31564874+simibubi@users.noreply.github.com> Date: Sat, 9 May 2020 12:14:26 +0200 Subject: [PATCH] More portable blocks - Fixed latch hotfix still not making it work properly - Cocoa pods can now be harvested by harvesters - Fans, RSCs, basins, stockpile switches, gauges, engines, cranks and other blocks can now be moved in a contraption - Most of creates technical blocks can now be picked up using a wrench - Fixed Stockpile switch not reacting to movement. - Fixed Stockpile switch not reacting to changes to a double container - Chassis range display no longer shows the overlay for non-sticky directions --- .../modules/contraptions/CasingBlock.java | 9 +++++- .../modules/contraptions/IWrenchable.java | 2 ++ .../contraptions/base/KineticBlock.java | 6 ---- .../contraptions/base/KineticTileEntity.java | 6 +++- .../components/actors/AttachedActorBlock.java | 10 ++++++- .../actors/HarvesterMovementBehaviour.java | 9 +++--- .../contraptions/BlockMovementTraits.java | 15 ++++++++++ .../contraptions/ContraptionCollider.java | 4 ++- .../contraptions/bearing/BearingBlock.java | 2 +- .../chassis/AbstractChassisBlock.java | 3 +- .../chassis/ChassisTileEntity.java | 7 +++-- .../mounted/CartAssemblerBlock.java | 3 +- .../contraptions/piston/PistonPoleBlock.java | 3 +- .../components/fan/NozzleBlock.java | 10 ++++++- .../flywheel/engine/EngineBlock.java | 12 ++++---- .../contraptions/processing/BasinBlock.java | 12 ++++---- .../contraptions/redstone/ContactBlock.java | 3 +- .../contraptions/relays/gauge/GaugeBlock.java | 28 ++++++++++++------- .../block/AttachedLogisticalBlock.java | 10 ++++++- .../logistics/block/StockswitchBlock.java | 12 ++++---- .../block/StockswitchTileEntity.java | 27 +++++++++++++++--- .../block/diodes/AbstractDiodeBlock.java | 13 +++++++++ .../block/diodes/FlexpeaterBlock.java | 3 +- .../logistics/block/diodes/LatchBlock.java | 3 +- .../block/diodes/PulseRepeaterBlock.java | 3 +- .../block/diodes/ToggleLatchBlock.java | 15 ++++++---- .../block/inventories/CrateBlock.java | 3 +- .../block/transposer/TransposerBlock.java | 3 +- 28 files changed, 167 insertions(+), 69 deletions(-) create mode 100644 src/main/java/com/simibubi/create/modules/logistics/block/diodes/AbstractDiodeBlock.java diff --git a/src/main/java/com/simibubi/create/modules/contraptions/CasingBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/CasingBlock.java index a67ba3f12..938b56b2c 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/CasingBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/CasingBlock.java @@ -10,11 +10,13 @@ import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.ItemUseContext; +import net.minecraft.util.ActionResultType; import net.minecraft.util.math.BlockPos; import net.minecraft.world.IBlockReader; import net.minecraftforge.common.ToolType; -public class CasingBlock extends Block implements IHaveConnectedTextures { +public class CasingBlock extends Block implements IHaveConnectedTextures, IWrenchable { String textureFrom; @@ -22,6 +24,11 @@ public class CasingBlock extends Block implements IHaveConnectedTextures { super(Properties.from(Blocks.ANDESITE)); this.textureFrom = textureFrom; } + + @Override + public ActionResultType onWrenched(BlockState state, ItemUseContext context) { + return ActionResultType.FAIL; + } @Override public ToolType getHarvestTool(BlockState state) { diff --git a/src/main/java/com/simibubi/create/modules/contraptions/IWrenchable.java b/src/main/java/com/simibubi/create/modules/contraptions/IWrenchable.java index 667c32468..ff4068f0a 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/IWrenchable.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/IWrenchable.java @@ -27,6 +27,8 @@ public interface IWrenchable { KineticTileEntity.switchToBlockState(world, context.getPos(), updateAfterWrenched(rotated, context)); TileEntity te = context.getWorld().getTileEntity(context.getPos()); + if (te != null) + te.updateContainingBlockInfo(); if (te instanceof GeneratingKineticTileEntity) { ((GeneratingKineticTileEntity) te).updateGeneratedRotation(); } diff --git a/src/main/java/com/simibubi/create/modules/contraptions/base/KineticBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/base/KineticBlock.java index d70185a9a..cafd39009 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/base/KineticBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/base/KineticBlock.java @@ -4,7 +4,6 @@ import com.simibubi.create.foundation.item.ItemDescription.Palette; import net.minecraft.block.Block; import net.minecraft.block.BlockState; -import net.minecraft.block.material.PushReaction; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; @@ -71,11 +70,6 @@ public abstract class KineticBlock extends Block implements IRotate { return true; } - @Override - public PushReaction getPushReaction(BlockState state) { - return PushReaction.BLOCK; - } - @Override public abstract TileEntity createTileEntity(BlockState state, IBlockReader world); diff --git a/src/main/java/com/simibubi/create/modules/contraptions/base/KineticTileEntity.java b/src/main/java/com/simibubi/create/modules/contraptions/base/KineticTileEntity.java index f0804b5e4..ebcb384df 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/base/KineticTileEntity.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/base/KineticTileEntity.java @@ -359,8 +359,12 @@ public abstract class KineticTileEntity extends SmartTileEntity return; TileEntity tileEntityIn = world.getTileEntity(pos); - if (!(tileEntityIn instanceof KineticTileEntity)) + boolean isKinetic = tileEntityIn instanceof KineticTileEntity; + + if (!isKinetic) { + world.setBlockState(pos, state, 3); return; + } KineticTileEntity tileEntity = (KineticTileEntity) tileEntityIn; if (tileEntity.hasNetwork()) diff --git a/src/main/java/com/simibubi/create/modules/contraptions/components/actors/AttachedActorBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/components/actors/AttachedActorBlock.java index c738f69b1..d1b882be7 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/components/actors/AttachedActorBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/components/actors/AttachedActorBlock.java @@ -1,6 +1,7 @@ package com.simibubi.create.modules.contraptions.components.actors; import com.simibubi.create.foundation.utility.AllShapes; +import com.simibubi.create.modules.contraptions.IWrenchable; import com.simibubi.create.modules.contraptions.components.contraptions.IPortableBlock; import net.minecraft.block.Block; @@ -8,7 +9,9 @@ import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; import net.minecraft.block.HorizontalBlock; import net.minecraft.item.BlockItemUseContext; +import net.minecraft.item.ItemUseContext; import net.minecraft.state.StateContainer.Builder; +import net.minecraft.util.ActionResultType; import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.shapes.ISelectionContext; @@ -16,11 +19,16 @@ 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 { +public abstract class AttachedActorBlock extends HorizontalBlock implements IPortableBlock, IWrenchable { public AttachedActorBlock() { super(Properties.from(Blocks.IRON_BLOCK)); } + + @Override + public ActionResultType onWrenched(BlockState state, ItemUseContext context) { + return ActionResultType.FAIL; + } @Override public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { diff --git a/src/main/java/com/simibubi/create/modules/contraptions/components/actors/HarvesterMovementBehaviour.java b/src/main/java/com/simibubi/create/modules/contraptions/components/actors/HarvesterMovementBehaviour.java index 83a8548b4..c18a8e0a5 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/components/actors/HarvesterMovementBehaviour.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/components/actors/HarvesterMovementBehaviour.java @@ -12,6 +12,7 @@ import com.simibubi.create.modules.contraptions.components.contraptions.Movement import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; +import net.minecraft.block.CocoaBlock; import net.minecraft.block.CropsBlock; import net.minecraft.block.KelpBlock; import net.minecraft.block.SugarCaneBlock; @@ -81,7 +82,7 @@ public class HarvesterMovementBehaviour extends MovementBehaviour { return false; return true; } - if (state.getCollisionShape(world, pos).isEmpty()) { + if (state.getCollisionShape(world, pos).isEmpty() || state.getBlock() instanceof CocoaBlock) { for (IProperty property : state.getProperties()) { if (!(property instanceof IntegerProperty)) continue; @@ -96,14 +97,14 @@ public class HarvesterMovementBehaviour extends MovementBehaviour { return false; } - + private boolean isValidOther(World world, BlockPos pos, BlockState state) { if (state.getBlock() instanceof CropsBlock) return false; if (state.getBlock() instanceof SugarCaneBlock) return true; - if (state.getCollisionShape(world, pos).isEmpty()) { + if (state.getCollisionShape(world, pos).isEmpty() || state.getBlock() instanceof CocoaBlock) { for (IProperty property : state.getProperties()) { if (!(property instanceof IntegerProperty)) continue; @@ -131,7 +132,7 @@ public class HarvesterMovementBehaviour extends MovementBehaviour { return Blocks.AIR.getDefaultState(); return state.getFluidState().getBlockState(); } - if (state.getCollisionShape(world, pos).isEmpty()) { + if (state.getCollisionShape(world, pos).isEmpty() || state.getBlock() instanceof CocoaBlock) { for (IProperty property : state.getProperties()) { if (!(property instanceof IntegerProperty)) continue; diff --git a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/BlockMovementTraits.java b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/BlockMovementTraits.java index 96e7419cb..af70da30a 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/BlockMovementTraits.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/BlockMovementTraits.java @@ -13,6 +13,9 @@ import com.simibubi.create.modules.contraptions.components.contraptions.piston.M import com.simibubi.create.modules.contraptions.components.contraptions.piston.MechanicalPistonBlock.PistonState; import com.simibubi.create.modules.contraptions.components.contraptions.pulley.PulleyBlock; import com.simibubi.create.modules.contraptions.components.contraptions.pulley.PulleyTileEntity; +import com.simibubi.create.modules.contraptions.components.crank.HandCrankBlock; +import com.simibubi.create.modules.contraptions.components.fan.NozzleBlock; +import com.simibubi.create.modules.contraptions.components.flywheel.engine.EngineBlock; import com.simibubi.create.modules.contraptions.components.contraptions.pulley.PulleyBlock.MagnetBlock; import com.simibubi.create.modules.contraptions.components.contraptions.pulley.PulleyBlock.RopeBlock; import com.simibubi.create.modules.logistics.block.AttachedLogisticalBlock; @@ -105,6 +108,8 @@ public class BlockMovementTraits { Block block = state.getBlock(); if (state.has(BlockStateProperties.HANGING)) return true; + if (block instanceof HandCrankBlock) + return true; if (block instanceof LadderBlock) return true; if (block instanceof ExtractorBlock) @@ -131,8 +136,12 @@ public class BlockMovementTraits { return true; if (block instanceof RopeBlock) return true; + if (block instanceof NozzleBlock) + return true; if (block instanceof MagnetBlock) return true; + if (block instanceof EngineBlock) + return true; return false; } @@ -178,6 +187,12 @@ public class BlockMovementTraits { return direction == Direction.DOWN; if (block instanceof AttachedActorBlock) return direction == state.get(HarvesterBlock.HORIZONTAL_FACING).getOpposite(); + if (block instanceof HandCrankBlock) + return direction == state.get(HandCrankBlock.FACING).getOpposite(); + if (block instanceof NozzleBlock) + return direction == state.get(NozzleBlock.FACING).getOpposite(); + if (block instanceof EngineBlock) + return direction == state.get(EngineBlock.HORIZONTAL_FACING).getOpposite(); return false; } diff --git a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/ContraptionCollider.java b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/ContraptionCollider.java index 42d73959d..f3a900949 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/ContraptionCollider.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/ContraptionCollider.java @@ -7,6 +7,7 @@ import com.simibubi.create.AllBlocks; import com.simibubi.create.modules.contraptions.components.actors.BlockBreakingMovementBehaviour; import net.minecraft.block.BlockState; +import net.minecraft.block.CocoaBlock; import net.minecraft.block.material.PushReaction; import net.minecraft.client.Minecraft; import net.minecraft.entity.Entity; @@ -272,7 +273,8 @@ public class ContraptionCollider { if (AllBlocks.PULLEY_MAGNET.typeOf(collidedState) && pos.equals(BlockPos.ZERO) && movementDirection == Direction.UP) continue; - + if (collidedState.getBlock() instanceof CocoaBlock) + continue; if (!collidedState.getMaterial().isReplaceable() && !collidedState.getCollisionShape(world, colliderPos).isEmpty()) { return true; diff --git a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/bearing/BearingBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/bearing/BearingBlock.java index d0b630bd4..3d2490654 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/bearing/BearingBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/bearing/BearingBlock.java @@ -24,7 +24,7 @@ public abstract class BearingBlock extends DirectionalKineticBlock { protected boolean hasStaticPart() { return true; } - + @Override public Axis getRotationAxis(BlockState state) { return state.get(FACING).getAxis(); diff --git a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/chassis/AbstractChassisBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/chassis/AbstractChassisBlock.java index e11ca9928..a4f269a9b 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/chassis/AbstractChassisBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/chassis/AbstractChassisBlock.java @@ -1,6 +1,7 @@ package com.simibubi.create.modules.contraptions.components.contraptions.chassis; import com.simibubi.create.AllSoundEvents; +import com.simibubi.create.modules.contraptions.IWrenchable; import net.minecraft.block.BlockState; import net.minecraft.block.RotatedPillarBlock; @@ -21,7 +22,7 @@ import net.minecraft.world.IBlockReader; import net.minecraft.world.World; import net.minecraftforge.common.Tags; -public abstract class AbstractChassisBlock extends RotatedPillarBlock { +public abstract class AbstractChassisBlock extends RotatedPillarBlock implements IWrenchable { public AbstractChassisBlock(Properties properties) { super(properties); diff --git a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/chassis/ChassisTileEntity.java b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/chassis/ChassisTileEntity.java index 2cf714806..3a2e58f89 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/chassis/ChassisTileEntity.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/chassis/ChassisTileEntity.java @@ -46,8 +46,9 @@ public class ChassisTileEntity extends SmartTileEntity { te -> ((ChassisTileEntity) te).collectChassisGroup()); range.requiresWrench(); range.between(1, max); - range.withClientCallback( - i -> DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> ChassisRangeDisplay.display(this))); + range + .withClientCallback( + i -> DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> ChassisRangeDisplay.display(this))); range.value = max / 2; behaviours.add(range); } @@ -161,7 +162,7 @@ public class ChassisTileEntity extends SmartTileEntity { BlockPos current = pos.offset(facing, i); BlockState currentState = world.getBlockState(current); - if (forcedMovement != facing && !visualize && !sticky) + if (forcedMovement != facing && !sticky) break; // Ignore replaceable Blocks and Air-like diff --git a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/mounted/CartAssemblerBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/mounted/CartAssemblerBlock.java index 3475d35d4..8efab9d2d 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/mounted/CartAssemblerBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/mounted/CartAssemblerBlock.java @@ -4,6 +4,7 @@ import com.simibubi.create.AllBlocks; import com.simibubi.create.foundation.block.ITE; import com.simibubi.create.foundation.block.RenderUtilityBlock; import com.simibubi.create.foundation.utility.AllShapes; +import com.simibubi.create.modules.contraptions.IWrenchable; import com.simibubi.create.modules.contraptions.components.contraptions.ContraptionEntity; import com.simibubi.create.modules.contraptions.components.contraptions.mounted.CartAssemblerTileEntity.CartMovementMode; @@ -32,7 +33,7 @@ import net.minecraft.util.math.shapes.VoxelShapes; import net.minecraft.world.IBlockReader; import net.minecraft.world.World; -public class CartAssemblerBlock extends AbstractRailBlock implements ITE { +public class CartAssemblerBlock extends AbstractRailBlock implements ITE, IWrenchable { public static IProperty RAIL_SHAPE = EnumProperty.create("shape", RailShape.class, RailShape.EAST_WEST, RailShape.NORTH_SOUTH); diff --git a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/piston/PistonPoleBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/piston/PistonPoleBlock.java index efa1100db..2b7e2256a 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/piston/PistonPoleBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/components/contraptions/piston/PistonPoleBlock.java @@ -3,6 +3,7 @@ package com.simibubi.create.modules.contraptions.components.contraptions.piston; import com.simibubi.create.AllBlocks; import com.simibubi.create.foundation.block.ProperDirectionalBlock; import com.simibubi.create.foundation.utility.AllShapes; +import com.simibubi.create.modules.contraptions.IWrenchable; import com.simibubi.create.modules.contraptions.components.contraptions.piston.MechanicalPistonBlock.PistonState; import net.minecraft.block.BlockState; @@ -20,7 +21,7 @@ import net.minecraft.util.math.shapes.VoxelShape; import net.minecraft.world.IBlockReader; import net.minecraft.world.World; -public class PistonPoleBlock extends ProperDirectionalBlock { +public class PistonPoleBlock extends ProperDirectionalBlock implements IWrenchable { public PistonPoleBlock() { super(Properties.from(Blocks.PISTON_HEAD)); diff --git a/src/main/java/com/simibubi/create/modules/contraptions/components/fan/NozzleBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/components/fan/NozzleBlock.java index 2e5e91fa3..d5694aaeb 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/components/fan/NozzleBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/components/fan/NozzleBlock.java @@ -3,11 +3,14 @@ package com.simibubi.create.modules.contraptions.components.fan; import com.simibubi.create.AllBlocks; import com.simibubi.create.foundation.block.ProperDirectionalBlock; import com.simibubi.create.foundation.utility.AllShapes; +import com.simibubi.create.modules.contraptions.IWrenchable; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.item.BlockItemUseContext; +import net.minecraft.item.ItemUseContext; import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.ActionResultType; import net.minecraft.util.BlockRenderLayer; import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; @@ -17,7 +20,7 @@ import net.minecraft.world.IBlockReader; import net.minecraft.world.IWorldReader; import net.minecraft.world.World; -public class NozzleBlock extends ProperDirectionalBlock { +public class NozzleBlock extends ProperDirectionalBlock implements IWrenchable { public NozzleBlock() { super(Properties.from(AllBlocks.ENCASED_FAN.get())); @@ -28,6 +31,11 @@ public class NozzleBlock extends ProperDirectionalBlock { return true; } + @Override + public ActionResultType onWrenched(BlockState state, ItemUseContext context) { + return ActionResultType.FAIL; + } + @Override public TileEntity createTileEntity(BlockState state, IBlockReader world) { return new NozzleTileEntity(); diff --git a/src/main/java/com/simibubi/create/modules/contraptions/components/flywheel/engine/EngineBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/components/flywheel/engine/EngineBlock.java index e73876769..688705df4 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/components/flywheel/engine/EngineBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/components/flywheel/engine/EngineBlock.java @@ -3,14 +3,16 @@ package com.simibubi.create.modules.contraptions.components.flywheel.engine; import javax.annotation.Nullable; import com.simibubi.create.AllBlockPartials; +import com.simibubi.create.modules.contraptions.IWrenchable; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.HorizontalBlock; -import net.minecraft.block.material.PushReaction; import net.minecraft.item.BlockItemUseContext; +import net.minecraft.item.ItemUseContext; import net.minecraft.state.StateContainer.Builder; import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.ActionResultType; import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; import net.minecraft.world.IBlockReader; @@ -19,7 +21,7 @@ import net.minecraft.world.World; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; -public abstract class EngineBlock extends HorizontalBlock { +public abstract class EngineBlock extends HorizontalBlock implements IWrenchable { protected EngineBlock(Properties builder) { super(builder); @@ -36,10 +38,10 @@ public abstract class EngineBlock extends HorizontalBlock { } @Override - public PushReaction getPushReaction(BlockState state) { - return PushReaction.BLOCK; + public ActionResultType onWrenched(BlockState state, ItemUseContext context) { + return ActionResultType.FAIL; } - + @Override public abstract TileEntity createTileEntity(BlockState state, IBlockReader world); diff --git a/src/main/java/com/simibubi/create/modules/contraptions/processing/BasinBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/processing/BasinBlock.java index 1a8ab2aa4..2e9451342 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/processing/BasinBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/processing/BasinBlock.java @@ -5,16 +5,18 @@ import com.simibubi.create.foundation.advancement.AllTriggers; import com.simibubi.create.foundation.block.ITE; import com.simibubi.create.foundation.item.ItemHelper; import com.simibubi.create.foundation.utility.AllShapes; +import com.simibubi.create.modules.contraptions.IWrenchable; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; -import net.minecraft.block.material.PushReaction; import net.minecraft.entity.Entity; import net.minecraft.entity.item.ItemEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; +import net.minecraft.item.ItemUseContext; import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.ActionResultType; import net.minecraft.util.Hand; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockRayTraceResult; @@ -26,7 +28,7 @@ import net.minecraftforge.items.IItemHandlerModifiable; import net.minecraftforge.items.ItemHandlerHelper; import net.minecraftforge.items.ItemStackHandler; -public class BasinBlock extends Block implements ITE { +public class BasinBlock extends Block implements ITE, IWrenchable { public BasinBlock() { super(Properties.from(Blocks.ANDESITE)); @@ -41,10 +43,10 @@ public class BasinBlock extends Block implements ITE { public TileEntity createTileEntity(BlockState state, IBlockReader world) { return new BasinTileEntity(); } - + @Override - public PushReaction getPushReaction(BlockState state) { - return PushReaction.BLOCK; + public ActionResultType onWrenched(BlockState state, ItemUseContext context) { + return ActionResultType.FAIL; } @Override diff --git a/src/main/java/com/simibubi/create/modules/contraptions/redstone/ContactBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/redstone/ContactBlock.java index 48eba0ce9..53d554a40 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/redstone/ContactBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/redstone/ContactBlock.java @@ -4,6 +4,7 @@ import java.util.Random; import com.simibubi.create.AllBlocks; import com.simibubi.create.foundation.block.ProperDirectionalBlock; +import com.simibubi.create.modules.contraptions.IWrenchable; import com.simibubi.create.modules.contraptions.components.contraptions.IPortableBlock; import com.simibubi.create.modules.contraptions.components.contraptions.MovementBehaviour; @@ -20,7 +21,7 @@ import net.minecraft.world.IBlockReader; import net.minecraft.world.IWorld; import net.minecraft.world.World; -public class ContactBlock extends ProperDirectionalBlock implements IPortableBlock { +public class ContactBlock extends ProperDirectionalBlock implements IPortableBlock, IWrenchable { public static final BooleanProperty POWERED = BlockStateProperties.POWERED; public static MovementBehaviour MOVEMENT = new ContactMovementBehaviour(); diff --git a/src/main/java/com/simibubi/create/modules/contraptions/relays/gauge/GaugeBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/relays/gauge/GaugeBlock.java index bcd1f077b..1f2897f4b 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/relays/gauge/GaugeBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/relays/gauge/GaugeBlock.java @@ -5,6 +5,7 @@ import java.util.Random; import com.simibubi.create.foundation.utility.ColorHelper; import com.simibubi.create.foundation.utility.Lang; import com.simibubi.create.foundation.utility.VecHelper; +import com.simibubi.create.foundation.utility.WrappedWorld; import com.simibubi.create.modules.contraptions.base.DirectionalAxisKineticBlock; import com.simibubi.create.modules.contraptions.base.IRotate; @@ -79,13 +80,16 @@ public class GaugeBlock extends DirectionalAxisKineticBlock { Direction nearestLookingDirection = context.getNearestLookingDirection(); boolean lookPositive = nearestLookingDirection.getAxisDirection() == AxisDirection.POSITIVE; if (face.getAxis() == Axis.X) { - toPlace = toPlace.with(FACING, lookPositive ? Direction.NORTH : Direction.SOUTH) + toPlace = toPlace + .with(FACING, lookPositive ? Direction.NORTH : Direction.SOUTH) .with(AXIS_ALONG_FIRST_COORDINATE, true); } else if (face.getAxis() == Axis.Y) { - toPlace = toPlace.with(FACING, horizontalFacing.getOpposite()).with(AXIS_ALONG_FIRST_COORDINATE, - horizontalFacing.getAxis() == Axis.X); + toPlace = toPlace + .with(FACING, horizontalFacing.getOpposite()) + .with(AXIS_ALONG_FIRST_COORDINATE, horizontalFacing.getAxis() == Axis.X); } else { - toPlace = toPlace.with(FACING, lookPositive ? Direction.WEST : Direction.EAST) + toPlace = toPlace + .with(FACING, lookPositive ? Direction.WEST : Direction.EAST) .with(AXIS_ALONG_FIRST_COORDINATE, false); } @@ -119,8 +123,8 @@ public class GaugeBlock extends DirectionalAxisKineticBlock { if (getRotationAxis(state) == Axis.Y && face != state.get(FACING)) return false; BlockState blockState = world.getBlockState(pos.offset(face)); - if (Block.hasSolidSide(blockState, world, pos, face.getOpposite()) - && blockState.getMaterial() != Material.GLASS) + if (Block.hasSolidSide(blockState, world, pos, face.getOpposite()) && blockState.getMaterial() != Material.GLASS + && !(world instanceof WrappedWorld)) return false; return true; } @@ -149,11 +153,15 @@ public class GaugeBlock extends DirectionalAxisKineticBlock { continue; for (int i = 0; i < particleCount; i++) { - Vec3d mul = VecHelper.offsetRandomly(Vec3d.ZERO, rand, .25f) - .mul(new Vec3d(1, 1, 1).subtract(positiveFaceVec)).normalize().scale(.3f); + Vec3d mul = VecHelper + .offsetRandomly(Vec3d.ZERO, rand, .25f) + .mul(new Vec3d(1, 1, 1).subtract(positiveFaceVec)) + .normalize() + .scale(.3f); Vec3d offset = VecHelper.getCenterOf(pos).add(faceVec.scale(.55)).add(mul); - worldIn.addParticle(new RedstoneParticleData((float) rgb.x, (float) rgb.y, (float) rgb.z, 1), offset.x, - offset.y, offset.z, mul.x, mul.y, mul.z); + worldIn + .addParticle(new RedstoneParticleData((float) rgb.x, (float) rgb.y, (float) rgb.z, 1), offset.x, + offset.y, offset.z, mul.x, mul.y, mul.z); } } diff --git a/src/main/java/com/simibubi/create/modules/logistics/block/AttachedLogisticalBlock.java b/src/main/java/com/simibubi/create/modules/logistics/block/AttachedLogisticalBlock.java index a15cacd5d..353e8644a 100644 --- a/src/main/java/com/simibubi/create/modules/logistics/block/AttachedLogisticalBlock.java +++ b/src/main/java/com/simibubi/create/modules/logistics/block/AttachedLogisticalBlock.java @@ -2,6 +2,7 @@ package com.simibubi.create.modules.logistics.block; import com.simibubi.create.AllBlocks; import com.simibubi.create.foundation.block.IHaveNoBlockItem; +import com.simibubi.create.modules.contraptions.IWrenchable; import com.simibubi.create.modules.contraptions.relays.belt.BeltBlock; import com.simibubi.create.modules.logistics.block.transposer.TransposerBlock; @@ -13,8 +14,10 @@ import net.minecraft.block.material.PushReaction; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.BlockItemUseContext; import net.minecraft.item.ItemStack; +import net.minecraft.item.ItemUseContext; import net.minecraft.state.BooleanProperty; import net.minecraft.state.StateContainer.Builder; +import net.minecraft.util.ActionResultType; import net.minecraft.util.Direction; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.BlockPos; @@ -23,7 +26,7 @@ import net.minecraft.world.IBlockReader; import net.minecraft.world.IWorldReader; import net.minecraft.world.World; -public abstract class AttachedLogisticalBlock extends HorizontalBlock implements IHaveNoBlockItem { +public abstract class AttachedLogisticalBlock extends HorizontalBlock implements IHaveNoBlockItem, IWrenchable { public static final BooleanProperty UPWARD = BooleanProperty.create("upward"); @@ -36,6 +39,11 @@ public abstract class AttachedLogisticalBlock extends HorizontalBlock implements return !isVertical(); } + @Override + public ActionResultType onWrenched(BlockState state, ItemUseContext context) { + return ActionResultType.FAIL; + } + protected abstract boolean isVertical(); protected abstract BlockState getVerticalDefaultState(); diff --git a/src/main/java/com/simibubi/create/modules/logistics/block/StockswitchBlock.java b/src/main/java/com/simibubi/create/modules/logistics/block/StockswitchBlock.java index 97f3172a1..348d04738 100644 --- a/src/main/java/com/simibubi/create/modules/logistics/block/StockswitchBlock.java +++ b/src/main/java/com/simibubi/create/modules/logistics/block/StockswitchBlock.java @@ -1,13 +1,14 @@ package com.simibubi.create.modules.logistics.block; +import com.simibubi.create.AllItems; import com.simibubi.create.foundation.block.ITE; import com.simibubi.create.foundation.gui.ScreenOpener; +import com.simibubi.create.modules.contraptions.IWrenchable; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; import net.minecraft.block.HorizontalBlock; -import net.minecraft.block.material.PushReaction; import net.minecraft.client.entity.player.ClientPlayerEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.BlockItemUseContext; @@ -26,7 +27,7 @@ import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.fml.DistExecutor; import net.minecraftforge.items.CapabilityItemHandler; -public class StockswitchBlock extends HorizontalBlock implements ITE { +public class StockswitchBlock extends HorizontalBlock implements ITE, IWrenchable { public static final IntegerProperty INDICATOR = IntegerProperty.create("indicator", 0, 6); @@ -88,6 +89,8 @@ public class StockswitchBlock extends HorizontalBlock implements ITE () -> withTileEntityDo(worldIn, pos, te -> this.displayScreen(te, player))); return true; @@ -139,11 +142,6 @@ public class StockswitchBlock extends HorizontalBlock implements ITE getTileEntityClass() { return StockswitchTileEntity.class; diff --git a/src/main/java/com/simibubi/create/modules/logistics/block/StockswitchTileEntity.java b/src/main/java/com/simibubi/create/modules/logistics/block/StockswitchTileEntity.java index c4b51bdb6..90c69cd51 100644 --- a/src/main/java/com/simibubi/create/modules/logistics/block/StockswitchTileEntity.java +++ b/src/main/java/com/simibubi/create/modules/logistics/block/StockswitchTileEntity.java @@ -1,7 +1,10 @@ package com.simibubi.create.modules.logistics.block; +import java.util.List; + import com.simibubi.create.AllTileEntities; -import com.simibubi.create.foundation.block.SyncedTileEntity; +import com.simibubi.create.foundation.behaviour.base.SmartTileEntity; +import com.simibubi.create.foundation.behaviour.base.TileEntityBehaviour; import net.minecraft.block.BlockState; import net.minecraft.item.ItemStack; @@ -15,7 +18,7 @@ import net.minecraftforge.common.util.LazyOptional; import net.minecraftforge.items.CapabilityItemHandler; import net.minecraftforge.items.IItemHandler; -public class StockswitchTileEntity extends SyncedTileEntity { +public class StockswitchTileEntity extends SmartTileEntity { public float onWhenAbove; public float offWhenBelow; @@ -34,6 +37,7 @@ public class StockswitchTileEntity extends SyncedTileEntity { currentLevel = -1; powered = false; observedInventory = LazyOptional.empty(); + setLazyTickRate(10); } @Override @@ -107,7 +111,17 @@ public class StockswitchTileEntity extends SyncedTileEntity { world.notifyNeighbors(pos, getBlockState().getBlock()); } + @Override + public void lazyTick() { + super.lazyTick(); + if (world.isRemote) + return; + findNewInventory(); + updateCurrentLevel(); + } + private boolean findNewInventory() { + observedInventory = LazyOptional.empty(); BlockPos invPos = getPos().offset(getBlockState().get(BlockStateProperties.HORIZONTAL_FACING)); if (!world.isBlockPresent(invPos)) @@ -119,14 +133,19 @@ public class StockswitchTileEntity extends SyncedTileEntity { TileEntity invTE = world.getTileEntity(invPos); if (invTE == null) return false; - + observedInventory = invTE.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY); if (observedInventory.isPresent()) { updateCurrentLevel(); return true; } - + return false; } + @Override + public void addBehaviours(List behaviours) { + + } + } diff --git a/src/main/java/com/simibubi/create/modules/logistics/block/diodes/AbstractDiodeBlock.java b/src/main/java/com/simibubi/create/modules/logistics/block/diodes/AbstractDiodeBlock.java new file mode 100644 index 000000000..04ad51126 --- /dev/null +++ b/src/main/java/com/simibubi/create/modules/logistics/block/diodes/AbstractDiodeBlock.java @@ -0,0 +1,13 @@ +package com.simibubi.create.modules.logistics.block.diodes; + +import com.simibubi.create.modules.contraptions.IWrenchable; + +import net.minecraft.block.RedstoneDiodeBlock; + +public abstract class AbstractDiodeBlock extends RedstoneDiodeBlock implements IWrenchable { + + public AbstractDiodeBlock(Properties builder) { + super(builder); + } + +} diff --git a/src/main/java/com/simibubi/create/modules/logistics/block/diodes/FlexpeaterBlock.java b/src/main/java/com/simibubi/create/modules/logistics/block/diodes/FlexpeaterBlock.java index dc2d0ca72..5865771eb 100644 --- a/src/main/java/com/simibubi/create/modules/logistics/block/diodes/FlexpeaterBlock.java +++ b/src/main/java/com/simibubi/create/modules/logistics/block/diodes/FlexpeaterBlock.java @@ -5,7 +5,6 @@ import com.simibubi.create.AllBlocks; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; -import net.minecraft.block.RedstoneDiodeBlock; import net.minecraft.state.BooleanProperty; import net.minecraft.state.StateContainer.Builder; import net.minecraft.tileentity.TileEntity; @@ -13,7 +12,7 @@ import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; import net.minecraft.world.IBlockReader; -public class FlexpeaterBlock extends RedstoneDiodeBlock { +public class FlexpeaterBlock extends AbstractDiodeBlock { public static BooleanProperty POWERING = BooleanProperty.create("powering"); diff --git a/src/main/java/com/simibubi/create/modules/logistics/block/diodes/LatchBlock.java b/src/main/java/com/simibubi/create/modules/logistics/block/diodes/LatchBlock.java index 67caa78ea..c559a35f2 100644 --- a/src/main/java/com/simibubi/create/modules/logistics/block/diodes/LatchBlock.java +++ b/src/main/java/com/simibubi/create/modules/logistics/block/diodes/LatchBlock.java @@ -57,7 +57,8 @@ public class LatchBlock extends ToggleLatchBlock { if (i > 0) return true; BlockState blockstate = worldIn.getBlockState(blockpos); - return blockstate.getBlock() == Blocks.REDSTONE_WIRE ? blockstate.get(RedstoneWireBlock.POWER) > 0 : false; + if (blockstate.getBlock() == Blocks.REDSTONE_WIRE && blockstate.get(RedstoneWireBlock.POWER) > 0) + return true; } return false; } diff --git a/src/main/java/com/simibubi/create/modules/logistics/block/diodes/PulseRepeaterBlock.java b/src/main/java/com/simibubi/create/modules/logistics/block/diodes/PulseRepeaterBlock.java index bb7531914..58fbf4d7e 100644 --- a/src/main/java/com/simibubi/create/modules/logistics/block/diodes/PulseRepeaterBlock.java +++ b/src/main/java/com/simibubi/create/modules/logistics/block/diodes/PulseRepeaterBlock.java @@ -5,7 +5,6 @@ import java.util.Random; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; -import net.minecraft.block.RedstoneDiodeBlock; import net.minecraft.state.BooleanProperty; import net.minecraft.state.StateContainer.Builder; import net.minecraft.util.Direction; @@ -14,7 +13,7 @@ import net.minecraft.world.IBlockReader; import net.minecraft.world.TickPriority; import net.minecraft.world.World; -public class PulseRepeaterBlock extends RedstoneDiodeBlock { +public class PulseRepeaterBlock extends AbstractDiodeBlock { public static BooleanProperty PULSING = BooleanProperty.create("pulsing"); diff --git a/src/main/java/com/simibubi/create/modules/logistics/block/diodes/ToggleLatchBlock.java b/src/main/java/com/simibubi/create/modules/logistics/block/diodes/ToggleLatchBlock.java index 20b238593..f4098e4b1 100644 --- a/src/main/java/com/simibubi/create/modules/logistics/block/diodes/ToggleLatchBlock.java +++ b/src/main/java/com/simibubi/create/modules/logistics/block/diodes/ToggleLatchBlock.java @@ -2,10 +2,11 @@ package com.simibubi.create.modules.logistics.block.diodes; import java.util.Random; +import com.simibubi.create.AllItems; + import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; -import net.minecraft.block.RedstoneDiodeBlock; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.state.BooleanProperty; import net.minecraft.state.StateContainer.Builder; @@ -16,10 +17,10 @@ import net.minecraft.util.math.BlockRayTraceResult; import net.minecraft.world.IBlockReader; import net.minecraft.world.World; -public class ToggleLatchBlock extends RedstoneDiodeBlock { +public class ToggleLatchBlock extends AbstractDiodeBlock { public static BooleanProperty POWERING = BooleanProperty.create("powering"); - + public ToggleLatchBlock() { super(Properties.from(Blocks.REPEATER)); setDefaultState(getDefaultState().with(POWERING, false).with(POWERED, false)); @@ -29,17 +30,17 @@ public class ToggleLatchBlock extends RedstoneDiodeBlock { protected void fillStateContainer(Builder builder) { builder.add(POWERED, POWERING, HORIZONTAL_FACING); } - + @Override public int getWeakPower(BlockState blockState, IBlockReader blockAccess, BlockPos pos, Direction side) { return blockState.get(HORIZONTAL_FACING) == side ? this.getActiveSignal(blockAccess, pos, blockState) : 0; } - + @Override protected int getDelay(BlockState state) { return 1; } - + @Override public boolean onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult hit) { @@ -47,6 +48,8 @@ public class ToggleLatchBlock extends RedstoneDiodeBlock { return false; if (player.isSneaking()) return false; + if (AllItems.WRENCH.typeOf(player.getHeldItem(handIn))) + return false; return activated(worldIn, pos, state); } diff --git a/src/main/java/com/simibubi/create/modules/logistics/block/inventories/CrateBlock.java b/src/main/java/com/simibubi/create/modules/logistics/block/inventories/CrateBlock.java index bb355a6c4..b72733e50 100644 --- a/src/main/java/com/simibubi/create/modules/logistics/block/inventories/CrateBlock.java +++ b/src/main/java/com/simibubi/create/modules/logistics/block/inventories/CrateBlock.java @@ -2,6 +2,7 @@ package com.simibubi.create.modules.logistics.block.inventories; import com.simibubi.create.foundation.block.ProperDirectionalBlock; import com.simibubi.create.foundation.utility.AllShapes; +import com.simibubi.create.modules.contraptions.IWrenchable; import net.minecraft.block.Block; import net.minecraft.block.BlockState; @@ -16,7 +17,7 @@ import net.minecraft.world.IBlockReader; import net.minecraft.world.IWorld; import net.minecraft.world.World; -public class CrateBlock extends ProperDirectionalBlock { +public class CrateBlock extends ProperDirectionalBlock implements IWrenchable { public static final BooleanProperty DOUBLE = BooleanProperty.create("double"); diff --git a/src/main/java/com/simibubi/create/modules/logistics/block/transposer/TransposerBlock.java b/src/main/java/com/simibubi/create/modules/logistics/block/transposer/TransposerBlock.java index 172541992..d4e9069dc 100644 --- a/src/main/java/com/simibubi/create/modules/logistics/block/transposer/TransposerBlock.java +++ b/src/main/java/com/simibubi/create/modules/logistics/block/transposer/TransposerBlock.java @@ -2,7 +2,6 @@ package com.simibubi.create.modules.logistics.block.transposer; import com.simibubi.create.AllBlocks; import com.simibubi.create.foundation.utility.AllShapes; -import com.simibubi.create.modules.contraptions.IWrenchable; import com.simibubi.create.modules.logistics.block.belts.BeltAttachableLogisticalBlock; import net.minecraft.block.Block; @@ -23,7 +22,7 @@ import net.minecraft.world.IBlockReader; import net.minecraft.world.IWorldReader; import net.minecraft.world.World; -public class TransposerBlock extends BeltAttachableLogisticalBlock implements IWrenchable { +public class TransposerBlock extends BeltAttachableLogisticalBlock { public static BooleanProperty POWERED = BlockStateProperties.POWERED;