From e1a1ce46db35319b507b043ba250dc351ea14839 Mon Sep 17 00:00:00 2001 From: simibubi <31564874+simibubi@users.noreply.github.com> Date: Fri, 10 Jan 2020 22:55:43 +0100 Subject: [PATCH] Synchronized Flaps - Belt tunnels can now act as backup-friendly belt mergers - Funnels can now pick up items touching them when not in belt mode - Fixed taking items from belts with right-click - Fixed crash when placing redstone links --- .../java/com/simibubi/create/AllBlocks.java | 1 + .../java/com/simibubi/create/AllItems.java | 2 +- .../components/fan/AirCurrent.java | 2 +- .../contraptions/relays/belt/BeltBlock.java | 2 +- .../relays/belt/BeltInventory.java | 56 +++++++++++-- .../relays/belt/BeltTileEntity.java | 2 +- .../relays/belt/BeltTunnelBlock.java | 53 ++++++++++++- .../relays/belt/BeltTunnelTileEntity.java | 43 +++++++++- .../belt/BeltTunnelTileEntityRenderer.java | 14 +++- .../block/IInventoryManipulator.java | 57 ------------- .../block/RedstoneLinkTileEntity.java | 4 +- .../block/belts/ExtractorForBeltsBlock.java | 75 ++++++++++++++++++ .../logistics/block/belts/FunnelBlock.java | 35 ++++---- .../block/belts/FunnelTileEntity.java | 74 +++-------------- .../blockstates/belt_tunnel_indicator.json | 5 ++ .../models/block/belt_tunnel/indicator.json | 22 +++++ .../create/textures/block/belt_tunnel.png | Bin 1952 -> 2672 bytes 17 files changed, 287 insertions(+), 160 deletions(-) delete mode 100644 src/main/java/com/simibubi/create/modules/logistics/block/IInventoryManipulator.java create mode 100644 src/main/java/com/simibubi/create/modules/logistics/block/belts/ExtractorForBeltsBlock.java create mode 100644 src/main/resources/assets/create/blockstates/belt_tunnel_indicator.json create mode 100644 src/main/resources/assets/create/models/block/belt_tunnel/indicator.json diff --git a/src/main/java/com/simibubi/create/AllBlocks.java b/src/main/java/com/simibubi/create/AllBlocks.java index e02eddf6d..6acf27fc6 100644 --- a/src/main/java/com/simibubi/create/AllBlocks.java +++ b/src/main/java/com/simibubi/create/AllBlocks.java @@ -175,6 +175,7 @@ public enum AllBlocks { VERTICAL_FUNNEL(new FunnelBlock.Vertical()), BELT_TUNNEL(new BeltTunnelBlock()), BELT_TUNNEL_FLAP(new RenderUtilityBlock()), + BELT_TUNNEL_INDICATOR(new RenderUtilityBlock()), ENTITY_DETECTOR(new BeltObserverBlock()), PULSE_REPEATER(new PulseRepeaterBlock()), FLEXPEATER(new FlexpeaterBlock()), diff --git a/src/main/java/com/simibubi/create/AllItems.java b/src/main/java/com/simibubi/create/AllItems.java index d454cd82e..d4d1c93ab 100644 --- a/src/main/java/com/simibubi/create/AllItems.java +++ b/src/main/java/com/simibubi/create/AllItems.java @@ -42,9 +42,9 @@ import net.minecraftforge.registries.IForgeRegistry; public enum AllItems { __MATERIALS__(), + ANDESITE_ALLOY_CUBE(ingredient()), COPPER_INGOT(ingredient()), ZINC_CUBE(ingredient()), - ANDESITE_ALLOY_CUBE(ingredient()), BRASS_CUBE(ingredient()), COPPER_NUGGET(ingredient()), ZINC_NUGGET(ingredient()), diff --git a/src/main/java/com/simibubi/create/modules/contraptions/components/fan/AirCurrent.java b/src/main/java/com/simibubi/create/modules/contraptions/components/fan/AirCurrent.java index 917704cb4..716a0c516 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/components/fan/AirCurrent.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/components/fan/AirCurrent.java @@ -255,7 +255,7 @@ public class AirCurrent { continue; World world = belt.getWorld(); - controller.getInventory().forEachWithin(belt.index + .5f, .5f, (transported) -> { + controller.getInventory().forEachWithin(belt.index + .5f, .51f, (transported) -> { InWorldProcessing.spawnParticlesForProcessing(world, controller.getInventory().getVectorForOffset(transported.beltPosition), processingType); if (world.isRemote) diff --git a/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltBlock.java index 2f0b5f82d..0a3cf7144 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltBlock.java @@ -192,7 +192,7 @@ public class BeltBlock extends HorizontalKineticBlock implements IHaveNoBlockIte return false; if (worldIn.isRemote) return true; - controllerBelt.getInventory().forEachWithin(belt.index, .75f, (transportedItemStack) -> { + controllerBelt.getInventory().forEachWithin(belt.index + .5f, .55f, (transportedItemStack) -> { player.inventory.placeItemBackInInventory(worldIn, transportedItemStack.stack); return Collections.emptyList(); }); 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 a754c3808..2860414d2 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 @@ -103,6 +103,7 @@ public class BeltInventory { float limitedMovement = beltMovementPositive ? Math.min(movement, diffToEnd) : Math.max(movement, diffToEnd); + float nextOffset = current.beltPosition + limitedMovement; if (!onClient) { // Don't move if belt attachments want to continue processing if (segmentBefore != -1 && current.locked) { @@ -122,10 +123,8 @@ public class BeltInventory { // See if any new belt processing catches the item int upcomingSegment = (int) (current.beltPosition + (beltMovementPositive ? .5f : -.5f)); - for (int segment = upcomingSegment; beltMovementPositive - ? segment + .5f <= current.beltPosition + limitedMovement - : segment + .5f >= current.beltPosition + limitedMovement; segment += beltMovementPositive ? 1 - : -1) { + for (int segment = upcomingSegment; beltMovementPositive ? segment + .5f <= nextOffset + : segment + .5f >= nextOffset; segment += beltMovementPositive ? 1 : -1) { BeltTileEntity beltSegment = getBeltSegment(segmentBefore); if (beltSegment == null) break; @@ -140,11 +139,16 @@ public class BeltInventory { } } - // Client: Belt tunnel flaps - if (onClient) { + // Belt tunnels + { int seg1 = (int) current.beltPosition; - int seg2 = (int) (current.beltPosition + limitedMovement); + int seg2 = (int) nextOffset; + if (!beltMovementPositive && nextOffset == 0) + seg2 = -1; if (seg1 != seg2) { + if (stuckAtTunnel(seg2, current.stack, belt.getMovementFacing())) { + continue; + } flapTunnel(seg1, belt.getMovementFacing(), false); flapTunnel(seg2, belt.getMovementFacing().getOpposite(), true); } @@ -247,6 +251,44 @@ public class BeltInventory { } + private boolean stuckAtTunnel(int offset, ItemStack stack, Direction movementDirection) { + BlockPos pos = getPositionForOffset(offset).up(); + if (!AllBlocks.BELT_TUNNEL.typeOf(belt.getWorld().getBlockState(pos))) + return false; + TileEntity te = belt.getWorld().getTileEntity(pos); + if (te == null || !(te instanceof BeltTunnelTileEntity)) + return false; + + Direction flapFacing = movementDirection; + if (flapFacing.getAxis() == Axis.X) + flapFacing = flapFacing.getOpposite(); + + BeltTunnelTileEntity tunnel = (BeltTunnelTileEntity) te; + if (!tunnel.flaps.containsKey(flapFacing)) + return false; + if (!tunnel.syncedFlaps.containsKey(flapFacing)) + return false; + ItemStack heldItem = tunnel.syncedFlaps.get(flapFacing); + if (heldItem == null) { + tunnel.syncedFlaps.put(flapFacing, ItemStack.EMPTY); + belt.sendData(); + return false; + } + if (heldItem == ItemStack.EMPTY) { + tunnel.syncedFlaps.put(flapFacing, stack); + return true; + } + + List group = BeltTunnelBlock.getSynchronizedGroup(belt.getWorld(), pos, flapFacing); + for (BeltTunnelTileEntity otherTunnel : group) + if (otherTunnel.syncedFlaps.get(flapFacing) == ItemStack.EMPTY) + return true; + for (BeltTunnelTileEntity otherTunnel : group) + otherTunnel.syncedFlaps.put(flapFacing, null); + + return true; + } + private void flapTunnel(int offset, Direction side, boolean inward) { if (belt.getBlockState().get(BeltBlock.SLOPE) != Slope.HORIZONTAL) return; 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 b80e88485..6df2fc7fa 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 @@ -159,6 +159,7 @@ public class BeltTileEntity extends KineticTileEntity { @Override public void read(CompoundNBT compound) { + super.read(compound); trackerUpdateTag = compound; controller = NBTUtil.readBlockPos(compound.getCompound("Controller")); color = compound.getInt("Color"); @@ -167,7 +168,6 @@ public class BeltTileEntity extends KineticTileEntity { if (isController()) getInventory().read(compound.getCompound("Inventory")); - super.read(compound); } public void applyColor(DyeColor colorIn) { 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 4ffca89aa..db4d4b334 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,5 +1,9 @@ package com.simibubi.create.modules.contraptions.relays.belt; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + import com.simibubi.create.AllBlocks; import com.simibubi.create.foundation.block.IWithTileEntity; import com.simibubi.create.foundation.utility.Lang; @@ -107,20 +111,47 @@ public class BeltTunnelBlock extends Block implements IWithTileEntity getSynchronizedGroup(World world, BlockPos pos, Direction flapFacing) { + List group = new ArrayList<>(); + Direction searchDirection = flapFacing.rotateY(); + + for (Direction d : Arrays.asList(searchDirection, searchDirection.getOpposite())) { + BlockPos currentPos = pos; + while (true) { + if (!world.isBlockPresent(currentPos)) + break; + TileEntity te = world.getTileEntity(currentPos); + if (te == null || !(te instanceof BeltTunnelTileEntity)) + break; + BeltTunnelTileEntity tunnel = (BeltTunnelTileEntity) te; + if (!tunnel.syncedFlaps.containsKey(flapFacing)) + break; + group.add(tunnel); + currentPos = currentPos.offset(d); + } + } + + return group; } private static BlockState getTunnelState(IBlockReader reader, BlockPos pos) { @@ -159,6 +190,12 @@ public class BeltTunnelBlock extends Block implements IWithTileEntity flaps; + public HashMap syncedFlaps; private LazyOptional cap = LazyOptional.empty(); private boolean initialize; @@ -33,6 +35,7 @@ public class BeltTunnelTileEntity extends SyncedTileEntity implements ITickableT public BeltTunnelTileEntity() { super(AllTileEntities.BELT_TUNNEL.type); flaps = new HashMap<>(); + syncedFlaps = new HashMap<>(); initialize = true; } @@ -62,6 +65,41 @@ public class BeltTunnelTileEntity extends SyncedTileEntity implements ITickableT cap.invalidate(); } + @Override + public CompoundNBT write(CompoundNBT compound) { + CompoundNBT dyedFlapsNBT = new CompoundNBT(); + syncedFlaps.forEach((direction, pair) -> { + dyedFlapsNBT.putBoolean(direction.name(), true); + }); + compound.put("syncedFlaps", dyedFlapsNBT); + return super.write(compound); + } + + @Override + public void read(CompoundNBT compound) { + if (compound.contains("syncedFlaps")) { + syncedFlaps.clear(); + CompoundNBT dyedFlapsNBT = compound.getCompound("syncedFlaps"); + for (Direction direction : Direction.values()) { + if (dyedFlapsNBT.contains(direction.name())) + syncedFlaps.put(direction, ItemStack.EMPTY); + } + } + super.read(compound); + } + + public boolean toggleSyncForFlap(Direction face) { + if (!flaps.containsKey(face)) + return false; + if (syncedFlaps.containsKey(face)) + syncedFlaps.remove(face); + else + syncedFlaps.put(face, ItemStack.EMPTY); + markDirty(); + sendData(); + return true; + } + @Override public CompoundNBT writeToClient(CompoundNBT tag) { CompoundNBT writeToClient = super.writeToClient(tag); @@ -86,7 +124,6 @@ public class BeltTunnelTileEntity extends SyncedTileEntity implements ITickableT public void initFlaps() { if (!world.isRemote) { sendData(); - return; } initialize = false; @@ -126,10 +163,10 @@ public class BeltTunnelTileEntity extends SyncedTileEntity implements ITickableT @Override public void tick() { - if (!world.isRemote) - return; if (initialize) initFlaps(); + if (!world.isRemote) + return; 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 40621208c..3e070144f 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 @@ -2,6 +2,7 @@ package com.simibubi.create.modules.contraptions.relays.belt; import com.simibubi.create.AllBlocks; import com.simibubi.create.CreateClient; +import com.simibubi.create.foundation.utility.ColorHelper; import com.simibubi.create.foundation.utility.SuperByteBuffer; import net.minecraft.block.BlockState; @@ -19,7 +20,9 @@ public class BeltTunnelTileEntityRenderer extends TileEntityRendererFast getInventory(); - - public void setInventory(LazyOptional inventory); - - default boolean findNewInventory() { - BlockPos invPos = getInventoryPos(); - World world = getWorld(); - - if (!world.isBlockPresent(invPos)) - return false; - BlockState invState = world.getBlockState(invPos); - - if (!invState.hasTileEntity()) - return false; - TileEntity invTE = world.getTileEntity(invPos); - if (invTE == null) - return false; - - LazyOptional inventory = invTE.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY); - setInventory(inventory); - if (inventory.isPresent()) { - return true; - } - - return false; - } - - public default void neighborChanged() { - boolean hasInventory = getInventory().isPresent(); - if (!hasInventory) { - findNewInventory(); - } - } - -} diff --git a/src/main/java/com/simibubi/create/modules/logistics/block/RedstoneLinkTileEntity.java b/src/main/java/com/simibubi/create/modules/logistics/block/RedstoneLinkTileEntity.java index b7ccda318..2db7812e6 100644 --- a/src/main/java/com/simibubi/create/modules/logistics/block/RedstoneLinkTileEntity.java +++ b/src/main/java/com/simibubi/create/modules/logistics/block/RedstoneLinkTileEntity.java @@ -44,13 +44,13 @@ public class RedstoneLinkTileEntity extends SmartTileEntity { @Override public void addBehavioursDeferred(List behaviours) { - if (slots == null) - createSlotPositioning(); createLink(); behaviours.add(link); } protected void createLink() { + if (slots == null) + createSlotPositioning(); if (transmitter) link = LinkBehaviour.transmitter(this, this::getSignal); else diff --git a/src/main/java/com/simibubi/create/modules/logistics/block/belts/ExtractorForBeltsBlock.java b/src/main/java/com/simibubi/create/modules/logistics/block/belts/ExtractorForBeltsBlock.java new file mode 100644 index 000000000..5b1f9f3bf --- /dev/null +++ b/src/main/java/com/simibubi/create/modules/logistics/block/belts/ExtractorForBeltsBlock.java @@ -0,0 +1,75 @@ +package com.simibubi.create.modules.logistics.block.belts; + +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +import com.simibubi.create.foundation.behaviour.base.TileEntityBehaviour; +import com.simibubi.create.foundation.behaviour.filtering.FilteringBehaviour; +import com.simibubi.create.foundation.behaviour.inventory.ExtractingBehaviour; +import com.simibubi.create.modules.contraptions.relays.belt.BeltTileEntity; +import com.simibubi.create.modules.contraptions.relays.belt.TransportedItemStack; +import com.simibubi.create.modules.contraptions.relays.belt.AllBeltAttachments.BeltAttachmentState; +import com.simibubi.create.modules.contraptions.relays.belt.AllBeltAttachments.IBeltAttachment; + +import net.minecraft.block.BlockState; +import net.minecraft.item.ItemStack; +import net.minecraft.util.Direction; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.IWorld; +import net.minecraft.world.World; + +public abstract class ExtractorForBeltsBlock extends AttachedLogisticalBlock implements IBeltAttachment { + + @Override + public void onBlockAdded(BlockState state, World worldIn, BlockPos pos, BlockState oldState, boolean isMoving) { + onAttachmentPlaced(worldIn, pos, state); + } + + @Override + public void onReplaced(BlockState state, World worldIn, BlockPos pos, BlockState newState, boolean isMoving) { + onAttachmentRemoved(worldIn, pos, state); + if (state.hasTileEntity() && state.getBlock() != newState.getBlock()) { + worldIn.removeTileEntity(pos); + } + } + + @Override + public BlockPos getBeltPositionForAttachment(IWorld world, BlockPos pos, BlockState state) { + return pos.offset(getBlockFacing(state)); + } + + @Override + public List getPotentialAttachmentPositions(IWorld world, BlockPos pos, BlockState beltState) { + return Arrays.asList(Direction.values()).stream().filter(d -> d != Direction.UP).map(pos::offset) + .collect(Collectors.toList()); + } + + public boolean startProcessingItem(BeltTileEntity te, TransportedItemStack transported, BeltAttachmentState state) { + BlockPos pos = state.attachmentPos; + World world = te.getWorld(); + ItemStack stack = transported.stack; + + FilteringBehaviour filtering = TileEntityBehaviour.get(world, pos, FilteringBehaviour.TYPE); + ExtractingBehaviour extracting = TileEntityBehaviour.get(world, pos, ExtractingBehaviour.TYPE); + + if (extracting == null) + return false; + if (filtering != null && (!filtering.test(stack) || stack.getCount() < filtering.getFilter().getCount())) + return false; + + return true; + } + + public boolean processItem(BeltTileEntity te, TransportedItemStack transported, BeltAttachmentState state) { + BlockPos pos = state.attachmentPos; + World world = te.getWorld(); + ExtractingBehaviour extracting = TileEntityBehaviour.get(world, pos, ExtractingBehaviour.TYPE); + + if (extracting == null) + return false; + extracting.extract(); + return false; + } + +} diff --git a/src/main/java/com/simibubi/create/modules/logistics/block/belts/FunnelBlock.java b/src/main/java/com/simibubi/create/modules/logistics/block/belts/FunnelBlock.java index 6959070f5..0685b1ab6 100644 --- a/src/main/java/com/simibubi/create/modules/logistics/block/belts/FunnelBlock.java +++ b/src/main/java/com/simibubi/create/modules/logistics/block/belts/FunnelBlock.java @@ -10,10 +10,11 @@ import com.simibubi.create.modules.contraptions.relays.belt.AllBeltAttachments.B import com.simibubi.create.modules.contraptions.relays.belt.AllBeltAttachments.IBeltAttachment; import com.simibubi.create.modules.contraptions.relays.belt.BeltTileEntity; import com.simibubi.create.modules.contraptions.relays.belt.TransportedItemStack; -import com.simibubi.create.modules.logistics.block.IInventoryManipulator; import net.minecraft.block.Block; import net.minecraft.block.BlockState; +import net.minecraft.entity.Entity; +import net.minecraft.entity.item.ItemEntity; import net.minecraft.item.BlockItemUseContext; import net.minecraft.item.ItemStack; import net.minecraft.state.BooleanProperty; @@ -26,7 +27,6 @@ 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 FunnelBlock extends AttachedLogisticalBlock @@ -55,6 +55,22 @@ public class FunnelBlock extends AttachedLogisticalBlock protected boolean isVertical() { return false; } + + @Override + public void onEntityCollision(BlockState state, World worldIn, BlockPos pos, Entity entityIn) { + if (worldIn.isRemote) + return; + if (!(entityIn instanceof ItemEntity)) + return; + ItemEntity itemEntity = (ItemEntity) entityIn; + withTileEntityDo(worldIn, pos, te -> { + ItemStack remainder = te.tryToInsert(itemEntity.getItem()); + if (remainder.isEmpty()) + itemEntity.remove(); + if (remainder.getCount() < itemEntity.getItem().getCount()) + itemEntity.setItem(remainder); + }); + } @Override protected BlockState getVerticalDefaultState() { @@ -95,21 +111,6 @@ public class FunnelBlock extends AttachedLogisticalBlock @Override public void onBlockAdded(BlockState state, World worldIn, BlockPos pos, BlockState oldState, boolean isMoving) { onAttachmentPlaced(worldIn, pos, state); - updateObservedInventory(state, worldIn, pos); - } - - @Override - public void onNeighborChange(BlockState state, IWorldReader world, BlockPos pos, BlockPos neighbor) { - if (!neighbor.equals(pos.offset(state.get(HORIZONTAL_FACING)))) - return; - updateObservedInventory(state, world, pos); - } - - private void updateObservedInventory(BlockState state, IWorldReader world, BlockPos pos) { - IInventoryManipulator te = (IInventoryManipulator) world.getTileEntity(pos); - if (te == null) - return; - te.neighborChanged(); } @Override diff --git a/src/main/java/com/simibubi/create/modules/logistics/block/belts/FunnelTileEntity.java b/src/main/java/com/simibubi/create/modules/logistics/block/belts/FunnelTileEntity.java index dcaffaa09..e6aab658d 100644 --- a/src/main/java/com/simibubi/create/modules/logistics/block/belts/FunnelTileEntity.java +++ b/src/main/java/com/simibubi/create/modules/logistics/block/belts/FunnelTileEntity.java @@ -7,10 +7,10 @@ import com.simibubi.create.foundation.behaviour.base.SmartTileEntity; import com.simibubi.create.foundation.behaviour.base.TileEntityBehaviour; import com.simibubi.create.foundation.behaviour.filtering.FilteringBehaviour; import com.simibubi.create.foundation.behaviour.filtering.FilteringBehaviour.SlotPositioning; +import com.simibubi.create.foundation.behaviour.inventory.InsertingBehaviour; +import com.simibubi.create.foundation.behaviour.inventory.InventoryManagementBehaviour.Attachments; import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.VecHelper; -import com.simibubi.create.modules.contraptions.relays.belt.ItemHandlerBeltSegment; -import com.simibubi.create.modules.logistics.block.IInventoryManipulator; import com.simibubi.create.modules.logistics.block.extractor.ExtractorBlock; import net.minecraft.item.ItemStack; @@ -18,30 +18,22 @@ import net.minecraft.nbt.CompoundNBT; import net.minecraft.particles.ItemParticleData; import net.minecraft.particles.ParticleTypes; import net.minecraft.state.properties.BlockStateProperties; -import net.minecraft.tileentity.ITickableTileEntity; import net.minecraft.util.Direction; import net.minecraft.util.Direction.Axis; import net.minecraft.util.SoundCategory; import net.minecraft.util.SoundEvents; -import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3i; -import net.minecraftforge.common.util.LazyOptional; -import net.minecraftforge.items.IItemHandler; -import net.minecraftforge.items.ItemHandlerHelper; -public class FunnelTileEntity extends SmartTileEntity implements ITickableTileEntity, IInventoryManipulator { +public class FunnelTileEntity extends SmartTileEntity { private static FilteringBehaviour.SlotPositioning slots; private FilteringBehaviour filtering; - - private LazyOptional inventory; - protected boolean waitingForInventorySpace; + private InsertingBehaviour inserting; private ItemStack justEaten; public FunnelTileEntity() { super(AllTileEntities.BELT_FUNNEL.type); - inventory = LazyOptional.empty(); } @Override @@ -50,22 +42,12 @@ public class FunnelTileEntity extends SmartTileEntity implements ITickableTileEn createSlotPositioning(); filtering = new FilteringBehaviour(this).withCallback(this::filterChanged).withSlotPositioning(slots); behaviours.add(filtering); + inserting = new InsertingBehaviour(this, + Attachments.toward(() -> AttachedLogisticalBlock.getBlockFacing(getBlockState()))); + behaviours.add(inserting); } public void filterChanged(ItemStack stack) { - neighborChanged(); - } - - @Override - public void read(CompoundNBT compound) { - waitingForInventorySpace = compound.getBoolean("Waiting"); - super.read(compound); - } - - @Override - public CompoundNBT write(CompoundNBT compound) { - compound.putBoolean("Waiting", waitingForInventorySpace); - return super.write(compound); } @Override @@ -80,67 +62,29 @@ public class FunnelTileEntity extends SmartTileEntity implements ITickableTileEn @Override public void readClientUpdate(CompoundNBT tag) { super.readClientUpdate(tag); - if (!waitingForInventorySpace) - neighborChanged(); if (tag.contains("Nom")) justEaten = ItemStack.read(tag.getCompound("Nom")); } - @Override - public BlockPos getInventoryPos() { - return pos.offset(getBlockState().get(BlockStateProperties.HORIZONTAL_FACING)); - } - - @Override - public LazyOptional getInventory() { - return inventory; - } - @Override public void tick() { + super.tick(); if (world.isRemote && justEaten != null) { spawnParticles(justEaten); justEaten = null; } } - @Override - public void initialize() { - neighborChanged(); - super.initialize(); - } - - @Override - public void setInventory(LazyOptional inventory) { - this.inventory = inventory; - } - - @Override - public void neighborChanged() { - IInventoryManipulator.super.neighborChanged(); - waitingForInventorySpace = false; - if (!world.isRemote) - sendData(); - } - public ItemStack tryToInsert(ItemStack stack) { - if (!inventory.isPresent()) - return stack; - if (waitingForInventorySpace && !(inventory.orElse(null) instanceof ItemHandlerBeltSegment)) - return stack; if (!filtering.test(stack)) return stack; - IItemHandler inv = inventory.orElse(null); - ItemStack inserted = stack.copy(); - ItemStack remainder = ItemHandlerHelper.insertItemStacked(inv, inserted, false); - waitingForInventorySpace = true; + ItemStack remainder = inserting.insert(stack.copy(), false); if (remainder.isEmpty()) { if (!world.isRemote) world.playSound(null, pos, SoundEvents.ENTITY_GENERIC_EAT, SoundCategory.BLOCKS, .125f, 1f); justEaten = stack.copy(); - waitingForInventorySpace = false; } sendData(); diff --git a/src/main/resources/assets/create/blockstates/belt_tunnel_indicator.json b/src/main/resources/assets/create/blockstates/belt_tunnel_indicator.json new file mode 100644 index 000000000..387520796 --- /dev/null +++ b/src/main/resources/assets/create/blockstates/belt_tunnel_indicator.json @@ -0,0 +1,5 @@ +{ + "variants": { + "": { "model": "create:block/belt_tunnel/indicator" } + } +} \ No newline at end of file diff --git a/src/main/resources/assets/create/models/block/belt_tunnel/indicator.json b/src/main/resources/assets/create/models/block/belt_tunnel/indicator.json new file mode 100644 index 000000000..1558c2d43 --- /dev/null +++ b/src/main/resources/assets/create/models/block/belt_tunnel/indicator.json @@ -0,0 +1,22 @@ +{ + "credit": "Made with Blockbench", + "parent": "block/block", + "textures": { + "0": "create:block/belt_tunnel", + "particle": "create:block/belt_tunnel" + }, + "elements": [ + { + "from": [6, 10, 16], + "to": [10, 14, 17], + "faces": { + "north": {"uv": [4.75, 0, 5.75, 1], "texture": "#0"}, + "east": {"uv": [5.5, 0, 5.75, 1], "texture": "#0"}, + "south": {"uv": [4.75, 0, 5.75, 1], "texture": "#0"}, + "west": {"uv": [4.75, 0, 5, 1], "texture": "#0"}, + "up": {"uv": [4.75, 0, 5, 1], "rotation": 270, "texture": "#0"}, + "down": {"uv": [4.75, 0, 5, 1], "rotation": 90, "texture": "#0"} + } + } + ] +} \ No newline at end of file diff --git a/src/main/resources/assets/create/textures/block/belt_tunnel.png b/src/main/resources/assets/create/textures/block/belt_tunnel.png index 8f2cd7010dcbc0f33b4b804eab1e925eefca3d3c..e4272a45f67632ea06618b67dc2ecf621e51a86a 100644 GIT binary patch delta 2640 zcmV-W3a|B`5AYO_Bnkm@Qb$4nuFf3kks%v@zW@LZzX3P}QzQTY3I$0-K~#8N?O9uF z9A_0iv+KQhcb#23v7Ne!-BfNGph;XoA^`$XqzWF2C=wE>gm{ahwg{Do2Sh<>+(%Fz zP@AZ#6bTAMeSz@eHtGwdtwICDjv=w*ICgxgo%nvqu4ivEobSy1gnmDM;~p#6Eu0iXBb-ZONY$CyD56+sjpL@%tt9bFB92p zR*rfmPkwtDdL}2wszi(~eeeO*>V}t z7QnmbkDDF6BV^=F+EW{+iJ27T`5Z{|dwrV5{P`&n56iV5p8Qiugexlc@d~kcFwi?V zCW{9HqmxORP3m-S;=Y{g=^TZ_Wh^9Jh+zo^|MS@<)89WNi-!;z8y}HtYr({SKHz2`Yvd^!4KO2FVE{sd zO8};6%BZieqrSdRLG0*3htz zO*5z+J$iIaCJOfohstnj9&37Bd$M-7hGXZ@6gAbkb339tc3WK(VOanV^B``}Qvj5JKC?Ju4W0Fya*zVwI(W z50T#Qn^zY6++dRr`1};%;D&*P`~CBa1Oti&+K2fUD+D|5L47GK%OD*u~ zYybHa#PR=wQw<(D_(j&d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