From 3a7d3f8562a676a331c37395c6b8d5394720a784 Mon Sep 17 00:00:00 2001 From: simibubi <31564874+simibubi@users.noreply.github.com> Date: Sat, 30 Nov 2019 00:27:03 +0100 Subject: [PATCH] Dangly Flaps - More progress on Crafter blocks - Belt tunnels now render dangling flaps reacting to bypassing items - Made Mechanical Press and Mixer full blocks --- .../java/com/simibubi/create/AllBlocks.java | 6 +- .../com/simibubi/create/AllTileEntities.java | 7 +- .../foundation/block/IWithTileEntity.java | 3 +- .../block/RenderUtilityDirectionalBlock.java | 11 + .../foundation/utility/SuperByteBuffer.java | 10 + .../receivers/MechanicalPressBlock.java | 2 +- .../crafter/MechanicalCrafterBlock.java | 33 ++- .../crafter/MechanicalCrafterTileEntity.java | 5 + .../relays/belt/BeltInventory.java | 29 +++ .../relays/belt/BeltTileEntity.java | 12 + .../relays/belt/BeltTileEntityRenderer.java | 16 +- .../relays/belt/BeltTunnelBlock.java | 26 +- .../relays/belt/BeltTunnelShapes.java | 54 ++++ .../relays/belt/BeltTunnelTileEntity.java | 117 ++++++++- .../belt/BeltTunnelTileEntityRenderer.java | 48 ++-- .../create/blockstates/belt_tunnel_flap.json | 5 + .../blockstates/mechanical_crafter.json | 12 +- .../blockstates/mechanical_crafter_arrow.json | 16 ++ .../blockstates/mechanical_crafter_belt.json | 16 ++ .../mechanical_crafter_belt_frame.json | 16 ++ .../resources/assets/create/lang/en_us.json | 1 + .../block/belt_tunnel/belttunnel_flap.json | 73 ------ .../models/block/belt_tunnel/cross.json | 240 ++++++++--------- .../create/models/block/belt_tunnel/flap.json | 31 +++ .../models/block/belt_tunnel/t_left.json | 69 +++-- .../models/block/belt_tunnel/t_right.json | 67 ++--- .../create/models/block/crafter/arrow.json | 43 ++++ .../create/models/block/crafter/belt.json | 2 +- .../models/block/crafter/belt_animated.json | 2 +- .../create/models/block/crafter/casing.json | 24 +- .../create/models/block/crafter/item.json | 243 ++++++++++++++++++ .../create/models/block/crafter/lid.json | 2 +- .../models/item/mechanical_crafter.json | 3 + .../textures/block/crafter_thingies.png | Bin 481 -> 464 bytes 34 files changed, 891 insertions(+), 353 deletions(-) create mode 100644 src/main/java/com/simibubi/create/foundation/block/RenderUtilityDirectionalBlock.java create mode 100644 src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltTunnelShapes.java create mode 100644 src/main/resources/assets/create/blockstates/belt_tunnel_flap.json create mode 100644 src/main/resources/assets/create/blockstates/mechanical_crafter_arrow.json create mode 100644 src/main/resources/assets/create/blockstates/mechanical_crafter_belt.json create mode 100644 src/main/resources/assets/create/blockstates/mechanical_crafter_belt_frame.json delete mode 100644 src/main/resources/assets/create/models/block/belt_tunnel/belttunnel_flap.json create mode 100644 src/main/resources/assets/create/models/block/belt_tunnel/flap.json create mode 100644 src/main/resources/assets/create/models/block/crafter/arrow.json create mode 100644 src/main/resources/assets/create/models/block/crafter/item.json create mode 100644 src/main/resources/assets/create/models/item/mechanical_crafter.json diff --git a/src/main/java/com/simibubi/create/AllBlocks.java b/src/main/java/com/simibubi/create/AllBlocks.java index 28d8db153..845ddd674 100644 --- a/src/main/java/com/simibubi/create/AllBlocks.java +++ b/src/main/java/com/simibubi/create/AllBlocks.java @@ -5,6 +5,7 @@ import com.simibubi.create.foundation.block.IWithoutBlockItem; import com.simibubi.create.foundation.block.ProperStairsBlock; import com.simibubi.create.foundation.block.RenderUtilityAxisBlock; import com.simibubi.create.foundation.block.RenderUtilityBlock; +import com.simibubi.create.foundation.block.RenderUtilityDirectionalBlock; import com.simibubi.create.foundation.utility.Lang; import com.simibubi.create.modules.IModule; import com.simibubi.create.modules.contraptions.generators.MotorBlock; @@ -125,7 +126,10 @@ public enum AllBlocks { MECHANICAL_MIXER_HEAD(new RenderUtilityBlock()), BASIN(new BasinBlock()), MECHANICAL_CRAFTER(new MechanicalCrafterBlock()), - MECHANICAL_CRAFTER_LID(new MechanicalCrafterBlock.Lid()), + MECHANICAL_CRAFTER_LID(new RenderUtilityDirectionalBlock()), + MECHANICAL_CRAFTER_ARROW(new RenderUtilityDirectionalBlock()), + MECHANICAL_CRAFTER_BELT_FRAME(new RenderUtilityDirectionalBlock()), + MECHANICAL_CRAFTER_BELT(new RenderUtilityDirectionalBlock()), MECHANICAL_PISTON(new MechanicalPistonBlock(false)), STICKY_MECHANICAL_PISTON(new MechanicalPistonBlock(true)), diff --git a/src/main/java/com/simibubi/create/AllTileEntities.java b/src/main/java/com/simibubi/create/AllTileEntities.java index 2c1466442..f245059f2 100644 --- a/src/main/java/com/simibubi/create/AllTileEntities.java +++ b/src/main/java/com/simibubi/create/AllTileEntities.java @@ -30,6 +30,7 @@ import com.simibubi.create.modules.contraptions.receivers.constructs.MechanicalB import com.simibubi.create.modules.contraptions.receivers.constructs.MechanicalPistonTileEntity; import com.simibubi.create.modules.contraptions.receivers.constructs.MechanicalPistonTileEntityRenderer; import com.simibubi.create.modules.contraptions.receivers.crafter.MechanicalCrafterTileEntity; +import com.simibubi.create.modules.contraptions.receivers.crafter.MechanicalCrafterTileEntityRenderer; import com.simibubi.create.modules.contraptions.relays.ClutchTileEntity; import com.simibubi.create.modules.contraptions.relays.EncasedShaftTileEntity; import com.simibubi.create.modules.contraptions.relays.EncasedShaftTileEntityRenderer; @@ -102,10 +103,7 @@ public enum AllTileEntities { BELT_TUNNEL(BeltTunnelTileEntity::new, AllBlocks.BELT_TUNNEL), MECHANICAL_PISTON(MechanicalPistonTileEntity::new, AllBlocks.MECHANICAL_PISTON, AllBlocks.STICKY_MECHANICAL_PISTON), MECHANICAL_BEARING(MechanicalBearingTileEntity::new, AllBlocks.MECHANICAL_BEARING), - CHASSIS( - ChassisTileEntity::new, - AllBlocks.ROTATION_CHASSIS, - AllBlocks.TRANSLATION_CHASSIS, + CHASSIS(ChassisTileEntity::new, AllBlocks.ROTATION_CHASSIS, AllBlocks.TRANSLATION_CHASSIS, AllBlocks.TRANSLATION_CHASSIS_SECONDARY), DRILL(DrillTileEntity::new, AllBlocks.DRILL), SAW(SawTileEntity::new, AllBlocks.SAW), @@ -198,6 +196,7 @@ public enum AllTileEntities { bind(LogisticiansTableTileEntity.class, new LogisticiansTableTileEntityRenderer()); bind(HarvesterTileEntity.class, new HarvesterTileEntityRenderer()); bind(MechanicalMixerTileEntity.class, new MechanicalMixerTileEntityRenderer()); + bind(MechanicalCrafterTileEntity.class, new MechanicalCrafterTileEntityRenderer()); bind(BasinTileEntity.class, new BasinTileEntityRenderer()); } diff --git a/src/main/java/com/simibubi/create/foundation/block/IWithTileEntity.java b/src/main/java/com/simibubi/create/foundation/block/IWithTileEntity.java index 8dcc922fe..3c6cda04c 100644 --- a/src/main/java/com/simibubi/create/foundation/block/IWithTileEntity.java +++ b/src/main/java/com/simibubi/create/foundation/block/IWithTileEntity.java @@ -5,11 +5,10 @@ import java.util.function.Consumer; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.math.BlockPos; import net.minecraft.world.IBlockReader; -import net.minecraft.world.IWorld; public interface IWithTileEntity { - default void withTileEntityDo(IWorld world, BlockPos pos, Consumer action) { + default void withTileEntityDo(IBlockReader world, BlockPos pos, Consumer action) { @SuppressWarnings("unchecked") T te = (T) world.getTileEntity(pos); if (te == null) diff --git a/src/main/java/com/simibubi/create/foundation/block/RenderUtilityDirectionalBlock.java b/src/main/java/com/simibubi/create/foundation/block/RenderUtilityDirectionalBlock.java new file mode 100644 index 000000000..1fa79aff6 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/block/RenderUtilityDirectionalBlock.java @@ -0,0 +1,11 @@ +package com.simibubi.create.foundation.block; + +import net.minecraft.block.material.Material; + +public class RenderUtilityDirectionalBlock extends ProperDirectionalBlock implements IRenderUtilityBlock { + + public RenderUtilityDirectionalBlock() { + super(Properties.create(Material.AIR)); + } + +} diff --git a/src/main/java/com/simibubi/create/foundation/utility/SuperByteBuffer.java b/src/main/java/com/simibubi/create/foundation/utility/SuperByteBuffer.java index 6ac337619..53f8a22b1 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/SuperByteBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/utility/SuperByteBuffer.java @@ -91,6 +91,9 @@ public class SuperByteBuffer { } t.setIdentity(); + shouldShiftUV = false; + shouldColor = false; + shouldLight = false; return mutable; } @@ -141,6 +144,13 @@ public class SuperByteBuffer { return this; } + public SuperByteBuffer dontShiftUV() { + shouldShiftUV = false; + uShift = 0; + vShift = 0; + return this; + } + public SuperByteBuffer light(int packedLightCoords) { shouldLight = true; this.packedLightCoords = packedLightCoords; diff --git a/src/main/java/com/simibubi/create/modules/contraptions/receivers/MechanicalPressBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/receivers/MechanicalPressBlock.java index 9f9dcebcb..c0ace0cc2 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/receivers/MechanicalPressBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/receivers/MechanicalPressBlock.java @@ -37,7 +37,7 @@ import net.minecraft.world.World; public class MechanicalPressBlock extends HorizontalKineticBlock implements IWithTileEntity, IBeltAttachment { - public static VoxelShape SHAPE = makeCuboidShape(0, 2, 0, 16, 16, 16); + public static VoxelShape SHAPE = makeCuboidShape(0, 0, 0, 16, 16, 16); public MechanicalPressBlock() { super(Properties.from(Blocks.PISTON)); diff --git a/src/main/java/com/simibubi/create/modules/contraptions/receivers/crafter/MechanicalCrafterBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/receivers/crafter/MechanicalCrafterBlock.java index 7b80382d6..8cb6ad7f3 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/receivers/crafter/MechanicalCrafterBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/receivers/crafter/MechanicalCrafterBlock.java @@ -1,16 +1,13 @@ package com.simibubi.create.modules.contraptions.receivers.crafter; import com.simibubi.create.foundation.block.IWithTileEntity; -import com.simibubi.create.foundation.block.RenderUtilityBlock; import com.simibubi.create.modules.contraptions.base.DirectionalKineticBlock; -import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; -import net.minecraft.state.DirectionProperty; -import net.minecraft.state.StateContainer.Builder; -import net.minecraft.state.properties.BlockStateProperties; +import net.minecraft.item.BlockItemUseContext; import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.BlockRenderLayer; import net.minecraft.util.Direction; import net.minecraft.util.Direction.Axis; import net.minecraft.util.math.BlockPos; @@ -20,17 +17,10 @@ import net.minecraft.world.World; public class MechanicalCrafterBlock extends DirectionalKineticBlock implements IWithTileEntity { - public static final DirectionProperty OUTPUT = BlockStateProperties.HORIZONTAL_FACING; - public MechanicalCrafterBlock() { super(Properties.from(Blocks.GOLD_BLOCK)); } - @Override - protected void fillStateContainer(Builder builder) { - super.fillStateContainer(builder.add(OUTPUT)); - } - @Override public TileEntity createTileEntity(BlockState state, IBlockReader world) { return new MechanicalCrafterTileEntity(); @@ -50,12 +40,19 @@ public class MechanicalCrafterBlock extends DirectionalKineticBlock public Axis getRotationAxis(BlockState state) { return state.get(FACING).getAxis(); } - - public static class Lid extends RenderUtilityBlock { - @Override - protected void fillStateContainer(Builder builder) { - super.fillStateContainer(builder.add(BlockStateProperties.FACING)); - } + + @Override + public BlockState getStateForPlacement(BlockItemUseContext context) { + BlockPos placedOnPos = context.getPos().offset(context.getFace().getOpposite()); + BlockState blockState = context.getWorld().getBlockState(placedOnPos); + if ((blockState.getBlock() == this) && !context.isPlacerSneaking()) + return getDefaultState().with(FACING, blockState.get(FACING)); + return super.getStateForPlacement(context); + } + + @Override + public BlockRenderLayer getRenderLayer() { + return BlockRenderLayer.CUTOUT_MIPPED; } } diff --git a/src/main/java/com/simibubi/create/modules/contraptions/receivers/crafter/MechanicalCrafterTileEntity.java b/src/main/java/com/simibubi/create/modules/contraptions/receivers/crafter/MechanicalCrafterTileEntity.java index 52551f624..98f5c2a62 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/receivers/crafter/MechanicalCrafterTileEntity.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/receivers/crafter/MechanicalCrafterTileEntity.java @@ -8,5 +8,10 @@ public class MechanicalCrafterTileEntity extends KineticTileEntity { public MechanicalCrafterTileEntity() { super(AllTileEntities.MECHANICAL_CRAFTER.type); } + + @Override + public boolean hasFastRenderer() { + return false; + } } diff --git a/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltInventory.java b/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltInventory.java index c0c09313e..a754c3808 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltInventory.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltInventory.java @@ -20,6 +20,7 @@ import net.minecraft.nbt.CompoundNBT; import net.minecraft.nbt.ListNBT; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.Direction; +import net.minecraft.util.Direction.Axis; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Vec3d; @@ -139,6 +140,16 @@ public class BeltInventory { } } + // Client: Belt tunnel flaps + if (onClient) { + int seg1 = (int) current.beltPosition; + int seg2 = (int) (current.beltPosition + limitedMovement); + if (seg1 != seg2) { + flapTunnel(seg1, belt.getMovementFacing(), false); + flapTunnel(seg2, belt.getMovementFacing().getOpposite(), true); + } + } + // Apply Movement current.beltPosition += limitedMovement; current.sideOffset += (current.getTargetSideOffset() - current.sideOffset) * Math.abs(limitedMovement) * 2f; @@ -168,6 +179,7 @@ public class BeltInventory { if (world.isRemote) continue; + int lastOffset = beltMovementPositive ? belt.beltLength - 1 : 0; BlockPos nextPosition = getPositionForOffset(beltMovementPositive ? belt.beltLength : -1); BlockState state = world.getBlockState(nextPosition); Direction movementFacing = belt.getMovementFacing(); @@ -189,6 +201,7 @@ public class BeltInventory { if (remainder.isEmpty()) { iterator.remove(); current = null; + flapTunnel(lastOffset, belt.getMovementFacing(), false); } belt.sendData(); @@ -203,6 +216,7 @@ public class BeltInventory { eject(current); iterator.remove(); current = null; + flapTunnel(lastOffset, belt.getMovementFacing(), false); belt.sendData(); } continue; @@ -223,6 +237,7 @@ public class BeltInventory { if (nextBelt.tryInsertingFromSide(movementFacing, current, false)) { iterator.remove(); current = null; + flapTunnel(lastOffset, belt.getMovementFacing(), false); belt.sendData(); } @@ -232,6 +247,20 @@ public class BeltInventory { } + private void flapTunnel(int offset, Direction side, boolean inward) { + if (belt.getBlockState().get(BeltBlock.SLOPE) != Slope.HORIZONTAL) + return; + BlockPos pos = getPositionForOffset(offset).up(); + if (!AllBlocks.BELT_TUNNEL.typeOf(belt.getWorld().getBlockState(pos))) + return; + TileEntity te = belt.getWorld().getTileEntity(pos); + if (te == null || !(te instanceof BeltTunnelTileEntity)) + return; + if (side.getAxis() == Axis.Z) + side = side.getOpposite(); + ((BeltTunnelTileEntity) te).flap(side, inward ^ side.getAxis() == Axis.Z); + } + public boolean canInsertAt(int segment) { return canInsertFrom(segment, Direction.UP); } diff --git a/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltTileEntity.java b/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltTileEntity.java index ee8052b49..b80e88485 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltTileEntity.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltTileEntity.java @@ -320,6 +320,18 @@ public class BeltTileEntity extends KineticTileEntity { nextInventory.insert(transportedStack); nextBeltController.markDirty(); nextBeltController.sendData(); + + if (side.getAxis().isHorizontal()) { + if (AllBlocks.BELT_TUNNEL.typeOf(world.getBlockState(pos.up()))) { + TileEntity tileEntity = world.getTileEntity(pos.up()); + if (tileEntity != null && tileEntity instanceof BeltTunnelTileEntity) { + if (side.getAxis() == Axis.X) + side = side.getOpposite(); + ((BeltTunnelTileEntity) tileEntity).flap(side, side.getAxis() == Axis.X); + } + } + } + return true; } diff --git a/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltTileEntityRenderer.java b/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltTileEntityRenderer.java index 969d5653f..d88a30227 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltTileEntityRenderer.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltTileEntityRenderer.java @@ -63,18 +63,22 @@ public class BeltTileEntityRenderer extends TileEntityRenderer { beltBuffer.color(te.color == -1 ? 0x808080 : te.color); // UV shift - if (te.getSpeed() != 0) { - if (animatedTexture == null) - animatedTexture = SpriteShifter.get("block/belt", "block/belt_animated"); - + float speed = te.getSpeed(); + if (animatedTexture == null) + animatedTexture = SpriteShifter.get("block/belt", "block/belt_animated"); + if (speed != 0) { float time = AnimationTickHolder.getRenderTick() * te.getBlockState().get(HORIZONTAL_FACING).getAxisDirection().getOffset(); - int textureIndex = (int) ((te.getSpeed() * time / 8) % 16); + if (renderedState.get(BeltBlock.HORIZONTAL_FACING).getAxis() == Axis.X) + speed = -speed; + int textureIndex = (int) ((speed * time / 8) % 16); if (textureIndex < 0) textureIndex += 16; beltBuffer.shiftUVtoSheet(animatedTexture.getOriginal(), animatedTexture.getTarget(), (textureIndex % 4) * 16, (textureIndex / 4) * 16); + } else { + beltBuffer.shiftUVtoSheet(animatedTexture.getOriginal(), animatedTexture.getTarget(), 0, 0); } int packedLightmapCoords = te.getBlockState().getPackedLightmapCoords(getWorld(), te.getPos()); @@ -148,7 +152,7 @@ public class BeltTileEntityRenderer extends TileEntityRenderer { } if (blockItem) { - GlStateManager.translated(r.nextFloat() * .25f, 0, r.nextFloat() * .25f); + GlStateManager.translated(r.nextFloat() * .0625f * i, 0, r.nextFloat() * .0625f * i); } GlStateManager.scaled(.5, .5, .5); diff --git a/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltTunnelBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltTunnelBlock.java index 6c4aff83f..bf21c7118 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltTunnelBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltTunnelBlock.java @@ -1,6 +1,7 @@ package com.simibubi.create.modules.contraptions.relays.belt; import com.simibubi.create.AllBlocks; +import com.simibubi.create.foundation.block.IWithTileEntity; import com.simibubi.create.foundation.utility.Lang; import com.simibubi.create.modules.contraptions.relays.belt.BeltBlock.Slope; @@ -19,12 +20,14 @@ import net.minecraft.util.Direction.Axis; import net.minecraft.util.Direction.AxisDirection; import net.minecraft.util.IStringSerializable; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.shapes.ISelectionContext; +import net.minecraft.util.math.shapes.VoxelShape; import net.minecraft.world.IBlockReader; import net.minecraft.world.IWorld; import net.minecraft.world.IWorldReader; import net.minecraft.world.World; -public class BeltTunnelBlock extends Block { +public class BeltTunnelBlock extends Block implements IWithTileEntity { public static final IProperty SHAPE = EnumProperty.create("shape", Shape.class); public static final IProperty HORIZONTAL_AXIS = BlockStateProperties.HORIZONTAL_AXIS; @@ -42,12 +45,28 @@ public class BeltTunnelBlock extends Block { return Lang.asId(name()); } } - + @Override public boolean hasTileEntity(BlockState state) { return true; } - + + @Override + public boolean isSolid(BlockState state) { + return false; + } + + @Override + public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { + return BeltTunnelShapes.getFilledShape(state); + } + + @Override + public VoxelShape getCollisionShape(BlockState state, IBlockReader worldIn, BlockPos pos, + ISelectionContext context) { + return BeltTunnelShapes.getFrameShape(state); + } + @Override public TileEntity createTileEntity(BlockState state, IBlockReader world) { return new BeltTunnelTileEntity(); @@ -80,6 +99,7 @@ public class BeltTunnelBlock extends Block { @Override public BlockState updatePostPlacement(BlockState state, Direction facing, BlockState facingState, IWorld worldIn, BlockPos currentPos, BlockPos facingPos) { + withTileEntityDo(worldIn, currentPos, BeltTunnelTileEntity::initFlaps); return getTunnelState(worldIn, currentPos); } diff --git a/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltTunnelShapes.java b/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltTunnelShapes.java new file mode 100644 index 000000000..60cc1b049 --- /dev/null +++ b/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltTunnelShapes.java @@ -0,0 +1,54 @@ +package com.simibubi.create.modules.contraptions.relays.belt; + +import static com.simibubi.create.foundation.utility.VoxelShaper.forHorizontalAxis; +import static net.minecraft.block.Block.makeCuboidShape; +import static net.minecraft.util.math.shapes.VoxelShapes.or; + +import com.simibubi.create.foundation.utility.VoxelShaper; + +import net.minecraft.block.BlockState; +import net.minecraft.util.Direction; +import net.minecraft.util.math.shapes.VoxelShape; +import net.minecraft.util.math.shapes.VoxelShapes; + +public class BeltTunnelShapes { + + private static final VoxelShape TOP = makeCuboidShape(0, 8, 0, 16, 16, 16), + INNER = makeCuboidShape(2, -5, 2, 14, 16, 14); + + private static final VoxelShaper WALL = VoxelShaper.forHorizontal(makeCuboidShape(0, -5, 14, 16, 16, 16)), + POLES = VoxelShaper + .forHorizontal(or(makeCuboidShape(0, -5, 14, 2, 16, 16), makeCuboidShape(14, -5, 14, 16, 16, 16))); + + private static final VoxelShaper STRAIGHT = forHorizontalAxis( + VoxelShapes.or(TOP, WALL.get(Direction.EAST), WALL.get(Direction.WEST))), + T_LEFT = forHorizontalAxis(VoxelShapes.or(TOP, WALL.get(Direction.EAST), POLES.get(Direction.WEST))), + T_RIGHT = forHorizontalAxis(VoxelShapes.or(TOP, POLES.get(Direction.EAST), WALL.get(Direction.WEST))), + CROSS = forHorizontalAxis(VoxelShapes.or(TOP, POLES.get(Direction.EAST), POLES.get(Direction.WEST))); + + public static VoxelShape getFrameShape(BlockState state) { + VoxelShaper shaper = null; + switch (state.get(BeltTunnelBlock.SHAPE)) { + case CROSS: + shaper = CROSS; + break; + case T_LEFT: + shaper = T_LEFT; + break; + case T_RIGHT: + shaper = T_RIGHT; + break; + case STRAIGHT: + case WINDOW: + default: + shaper = STRAIGHT; + break; + } + return shaper.get(state.get(BeltTunnelBlock.HORIZONTAL_AXIS)); + } + + public static VoxelShape getFilledShape(BlockState state) { + return or(getFrameShape(state), INNER); + } + +} diff --git a/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltTunnelTileEntity.java b/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltTunnelTileEntity.java index 6c3e91d3f..5975c14e2 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltTunnelTileEntity.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltTunnelTileEntity.java @@ -1,30 +1,133 @@ package com.simibubi.create.modules.contraptions.relays.belt; +import java.util.HashMap; + import com.simibubi.create.AllBlocks; import com.simibubi.create.AllTileEntities; import com.simibubi.create.foundation.block.SyncedTileEntity; +import com.simibubi.create.foundation.gui.widgets.InterpolatedChasingValue; +import com.simibubi.create.modules.contraptions.relays.belt.BeltTunnelBlock.Shape; +import net.minecraft.block.BlockState; +import net.minecraft.nbt.CompoundNBT; +import net.minecraft.state.properties.BlockStateProperties; +import net.minecraft.tileentity.ITickableTileEntity; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.Direction; +import net.minecraft.util.Direction.Axis; +import net.minecraft.util.Direction.AxisDirection; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.util.LazyOptional; +import net.minecraftforge.items.CapabilityItemHandler; +import net.minecraftforge.items.IItemHandler; -public class BeltTunnelTileEntity extends SyncedTileEntity { +public class BeltTunnelTileEntity extends SyncedTileEntity implements ITickableTileEntity { + + public HashMap flaps; + private LazyOptional cap = LazyOptional.empty(); + private boolean initialize; + + private Direction flapToSend; + private boolean flapInward; public BeltTunnelTileEntity() { super(AllTileEntities.BELT_TUNNEL.type); + flaps = new HashMap<>(); + initialize = true; } @Override - public LazyOptional getCapability(Capability cap, Direction side) { + public LazyOptional getCapability(Capability capabitily, Direction side) { - if (AllBlocks.BELT.typeOf(world.getBlockState(pos.down()))) { - TileEntity teBelow = world.getTileEntity(pos.down()); - if (teBelow != null) - return teBelow.getCapability(cap, Direction.UP); + if (capabitily == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) { + if (!this.cap.isPresent()) { + if (AllBlocks.BELT.typeOf(world.getBlockState(pos.down()))) { + TileEntity teBelow = world.getTileEntity(pos.down()); + if (teBelow != null) + cap = LazyOptional.of(() -> teBelow.getCapability(capabitily, Direction.UP).orElse(null)) + .cast(); + } + } + return this.cap.cast(); + } + return super.getCapability(capabitily, side); + } + + @Override + public void remove() { + super.remove(); + cap.invalidate(); + } + + @Override + public CompoundNBT writeToClient(CompoundNBT tag) { + CompoundNBT writeToClient = super.writeToClient(tag); + if (flapToSend != null) { + writeToClient.putInt("Flap", flapToSend.getIndex()); + writeToClient.putBoolean("FlapInward", flapInward); + flapToSend = null; + } + return writeToClient; + } + + @Override + public void readClientUpdate(CompoundNBT tag) { + super.readClientUpdate(tag); + if (tag.contains("Flap")) { + Direction side = Direction.byIndex(tag.getInt("Flap")); + flap(side, tag.getBoolean("FlapInward")); + } else + initFlaps(); + } + + public void initFlaps() { + if (!world.isRemote) { + sendData(); + return; } - return super.getCapability(cap, side); + initialize = false; + flaps.clear(); + BlockState tunnelState = getBlockState(); + for (Direction direction : Direction.values()) { + if (direction.getAxis().isVertical()) + continue; + if (AllBlocks.BELT_TUNNEL.typeOf(world.getBlockState(pos.offset(direction)))) + continue; + if (direction.getAxis() != tunnelState.get(BlockStateProperties.HORIZONTAL_AXIS)) { + boolean positive = direction.getAxisDirection() == AxisDirection.POSITIVE + ^ direction.getAxis() == Axis.Z; + Shape shape = tunnelState.get(BeltTunnelBlock.SHAPE); + if (shape == Shape.STRAIGHT || shape == Shape.WINDOW) + continue; + if (positive && shape == Shape.T_LEFT) + continue; + if (!positive && shape == Shape.T_RIGHT) + continue; + } + flaps.put(direction, new InterpolatedChasingValue().target(0).withSpeed(.05f)); + } + } + + public void flap(Direction side, boolean inward) { + if (world.isRemote) { + if (flaps.containsKey(side)) + flaps.get(side).set(inward ? -1 : 1); + return; + } + + flapToSend = side; + flapInward = inward; + sendData(); + } + + @Override + public void tick() { + if (!world.isRemote) + return; + if (initialize) + initFlaps(); + flaps.forEach((d, value) -> value.tick()); } } diff --git a/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltTunnelTileEntityRenderer.java b/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltTunnelTileEntityRenderer.java index 4ae9a3d86..40621208c 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltTunnelTileEntityRenderer.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltTunnelTileEntityRenderer.java @@ -3,15 +3,13 @@ package com.simibubi.create.modules.contraptions.relays.belt; import com.simibubi.create.AllBlocks; import com.simibubi.create.CreateClient; import com.simibubi.create.foundation.utility.SuperByteBuffer; -import com.simibubi.create.modules.contraptions.relays.belt.BeltTunnelBlock.Shape; import net.minecraft.block.BlockState; import net.minecraft.client.renderer.BufferBuilder; -import net.minecraft.state.properties.BlockStateProperties; import net.minecraft.util.Direction; import net.minecraft.util.Direction.Axis; -import net.minecraft.util.Direction.AxisDirection; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.MathHelper; import net.minecraft.world.World; import net.minecraftforge.client.model.animation.TileEntityRendererFast; @@ -21,33 +19,37 @@ public class BeltTunnelTileEntityRenderer extends TileEntityRendererFastYU6vn@MD>V+Lmd1*I zS{J8I3OYFyd;t*$M<<`a2k-?P^a%tf2k{+r5(+w55Fw@7Nv!oxq)nRKYtCs?Old`N z@&`9Lx!mu&=Q|OHd+Qn@fzoLE0hM@nTpS!-a{U#^>YK3#Fa6U5Z^6ct0)}GkiTYU6vn@MD>V+L7GuRf zO&y$ERM5#m=;|Qipo8G#6ZinWfP+4PAPybG&9#G*P*gf7h>+UaN!0o$(k4xA%sp+u z)K(NHe{ji3?)|=;?_9RKwdlde6&~u2D@(kY7IyYdss4S!LkLqqnw_nVb$b7G(aQ6hpSabU;(FlVY??>*cg!IBB zxE$EXpo*HGUw@Ju>LUX=Fiq1!OHva(B$h)gmTtk;=SS%lB!Roc^