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
This commit is contained in:
simibubi 2020-01-10 22:55:43 +01:00
parent 7059cf2737
commit e1a1ce46db
17 changed files with 287 additions and 160 deletions

View file

@ -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()),

View file

@ -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()),

View file

@ -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)

View file

@ -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();
});

View file

@ -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<BeltTunnelTileEntity> 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;

View file

@ -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) {

View file

@ -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<BeltTunnel
BlockPos currentPos, BlockPos facingPos) {
withTileEntityDo(worldIn, currentPos, BeltTunnelTileEntity::initFlaps);
BlockState tunnelState = getTunnelState(worldIn, currentPos);
if (tunnelState.get(HORIZONTAL_AXIS) == state.get(HORIZONTAL_AXIS)) {
if (hasWindow(tunnelState) == hasWindow(state))
return state;
}
return tunnelState;
}
public static void updateTunnel(World world, BlockPos pos) {
BlockState tunnel = world.getBlockState(pos);
BlockState newTunnel = getTunnelState(world, pos);
if (tunnel != newTunnel)
if (tunnel != newTunnel) {
world.setBlockState(pos, newTunnel, 3);
TileEntity te = world.getTileEntity(pos);
if (te != null && (te instanceof BeltTunnelTileEntity))
((BeltTunnelTileEntity) te).initFlaps();
}
}
public static List<BeltTunnelTileEntity> getSynchronizedGroup(World world, BlockPos pos, Direction flapFacing) {
List<BeltTunnelTileEntity> 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<BeltTunnel
@Override
public ActionResultType onWrenched(BlockState state, ItemUseContext context) {
// Toggle sync
if (toggleSync(context.getWorld(), context.getPos(), context.getFace()))
return ActionResultType.SUCCESS;
// Toggle windows
if (!hasWindow(state))
return IWrenchable.super.onWrenched(state, context);
Shape next = state.get(SHAPE);
@ -175,11 +212,19 @@ public class BeltTunnelBlock extends Block implements IWithTileEntity<BeltTunnel
default:
break;
}
if (!context.getWorld().isRemote)
if (!context.getWorld().isRemote)
context.getWorld().setBlockState(context.getPos(), state.with(SHAPE, next), 2);
return ActionResultType.SUCCESS;
}
private boolean toggleSync(World world, BlockPos pos, Direction face) {
TileEntity te = world.getTileEntity(pos);
if (te == null || !(te instanceof BeltTunnelTileEntity))
return false;
BeltTunnelTileEntity tunnel = (BeltTunnelTileEntity) te;
return tunnel.toggleSyncForFlap(face);
}
@Override
public void neighborChanged(BlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos,
boolean isMoving) {

View file

@ -9,6 +9,7 @@ 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.item.ItemStack;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.state.properties.BlockStateProperties;
import net.minecraft.tileentity.ITickableTileEntity;
@ -24,6 +25,7 @@ import net.minecraftforge.items.IItemHandler;
public class BeltTunnelTileEntity extends SyncedTileEntity implements ITickableTileEntity {
public HashMap<Direction, InterpolatedChasingValue> flaps;
public HashMap<Direction, ItemStack> syncedFlaps;
private LazyOptional<IItemHandler> 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());
}

View file

@ -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<BeltTun
public void renderTileEntityFast(BeltTunnelTileEntity te, double x, double y, double z, float partialTicks,
int destroyStage, BufferBuilder buffer) {
BlockState flapState = AllBlocks.BELT_TUNNEL_FLAP.get().getDefaultState();
BlockState indicatorState = AllBlocks.BELT_TUNNEL_INDICATOR.get().getDefaultState();
SuperByteBuffer flapBuffer = CreateClient.bufferCache.renderGenericBlockModel(flapState);
SuperByteBuffer indicatorBuffer = CreateClient.bufferCache.renderGenericBlockModel(indicatorState);
BlockPos pos = te.getPos();
World world = getWorld();
@ -41,9 +44,18 @@ public class BeltTunnelTileEntityRenderer extends TileEntityRendererFast<BeltTun
f *= -1;
float intensity = segment == 3 ? 1.5f : segment + 1;
float flapAngle = MathHelper.sin((float) ((1 - Math.abs(f)) * Math.PI * intensity)) * 30 * -f;
float abs = Math.abs(f);
float flapAngle = MathHelper.sin((float) ((1 - abs) * Math.PI * intensity)) * 30 * -f;
flapAngle = (float) (flapAngle / 180 * Math.PI);
if (te.syncedFlaps.containsKey(direction)) {
float lightIntensity = abs * abs * abs;
int color = ColorHelper.mixColors(0x808080, 0xFFFFFF, lightIntensity);
indicatorBuffer.rotateCentered(Axis.Y, (float) ((horizontalAngle + 90) / 180f * Math.PI))
.translate(x, y, z).color(color)
.light(world.getCombinedLight(pos, (int) (12 * lightIntensity))).renderInto(buffer);
}
flapBuffer.translate(0, 0, -segment * 3 / 16f);
flapBuffer.translate(flapPivotX, flapPivotY, flapPivotZ).rotate(Axis.Z, flapAngle)
.translate(-flapPivotX, -flapPivotY, -flapPivotZ);

View file

@ -1,57 +0,0 @@
package com.simibubi.create.modules.logistics.block;
import net.minecraft.block.BlockState;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler;
public interface IInventoryManipulator {
public default World getWorld() {
return ((TileEntity) this).getWorld();
}
public default BlockPos getPos() {
return ((TileEntity) this).getPos();
}
public BlockPos getInventoryPos();
public LazyOptional<IItemHandler> getInventory();
public void setInventory(LazyOptional<IItemHandler> 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<IItemHandler> 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();
}
}
}

View file

@ -44,13 +44,13 @@ public class RedstoneLinkTileEntity extends SmartTileEntity {
@Override
public void addBehavioursDeferred(List<TileEntityBehaviour> 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

View file

@ -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<BlockPos> 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;
}
}

View file

@ -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

View file

@ -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<IItemHandler> 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<IItemHandler> 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<IItemHandler> 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();

View file

@ -0,0 +1,5 @@
{
"variants": {
"": { "model": "create:block/belt_tunnel/indicator" }
}
}

View file

@ -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"}
}
}
]
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 2.6 KiB