use of com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack in project Create by Creators-of-Create.
the class DepotBehaviour method insert.
public ItemStack insert(TransportedItemStack heldItem, boolean simulate) {
if (!canAcceptItems.get())
return heldItem.stack;
if (canMergeItems()) {
int remainingSpace = getRemainingSpace();
ItemStack inserted = heldItem.stack;
if (remainingSpace <= 0)
return inserted;
if (this.heldItem != null && !ItemHelper.canItemStackAmountsStack(this.heldItem.stack, inserted))
return inserted;
ItemStack returned = ItemStack.EMPTY;
if (remainingSpace < inserted.getCount()) {
returned = ItemHandlerHelper.copyStackWithSize(heldItem.stack, inserted.getCount() - remainingSpace);
if (!simulate) {
TransportedItemStack copy = heldItem.copy();
copy.stack.setCount(remainingSpace);
if (this.heldItem != null)
incoming.add(copy);
else
this.heldItem = copy;
}
} else {
if (!simulate) {
if (this.heldItem != null)
incoming.add(heldItem);
else
this.heldItem = heldItem;
}
}
return returned;
}
if (!simulate) {
if (this.isEmpty()) {
if (heldItem.insertedFrom.getAxis().isHorizontal())
AllSoundEvents.DEPOT_SLIDE.playOnServer(getWorld(), getPos());
else
AllSoundEvents.DEPOT_PLOP.playOnServer(getWorld(), getPos());
}
this.heldItem = heldItem;
}
return ItemStack.EMPTY;
}
use of com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack in project Create by Creators-of-Create.
the class DepotBehaviour method tick.
@Override
public void tick() {
super.tick();
Level world = tileEntity.getLevel();
for (Iterator<TransportedItemStack> iterator = incoming.iterator(); iterator.hasNext(); ) {
TransportedItemStack ts = iterator.next();
if (!tick(ts))
continue;
if (world.isClientSide && !tileEntity.isVirtual())
continue;
if (heldItem == null) {
heldItem = ts;
} else {
if (!ItemHelper.canItemStackAmountsStack(heldItem.stack, ts.stack)) {
Vec3 vec = VecHelper.getCenterOf(tileEntity.getBlockPos());
Containers.dropItemStack(tileEntity.getLevel(), vec.x, vec.y + .5f, vec.z, ts.stack);
} else {
heldItem.stack.grow(ts.stack.getCount());
}
}
iterator.remove();
tileEntity.notifyUpdate();
}
if (heldItem == null)
return;
if (!tick(heldItem))
return;
BlockPos pos = tileEntity.getBlockPos();
if (world.isClientSide)
return;
if (handleBeltFunnelOutput())
return;
BeltProcessingBehaviour processingBehaviour = TileEntityBehaviour.get(world, pos.above(2), BeltProcessingBehaviour.TYPE);
if (processingBehaviour == null)
return;
if (!heldItem.locked && BeltProcessingBehaviour.isBlocked(world, pos))
return;
ItemStack previousItem = heldItem.stack;
boolean wasLocked = heldItem.locked;
ProcessingResult result = wasLocked ? processingBehaviour.handleHeldItem(heldItem, transportedHandler) : processingBehaviour.handleReceivedItem(heldItem, transportedHandler);
if (result == ProcessingResult.REMOVE) {
heldItem = null;
tileEntity.sendData();
return;
}
heldItem.locked = result == ProcessingResult.HOLD;
if (heldItem.locked != wasLocked || !previousItem.equals(heldItem.stack, false))
tileEntity.sendData();
}
use of com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack in project Create by Creators-of-Create.
the class SharedDepotBlockMethods method onReplaced.
public static void onReplaced(BlockState state, Level worldIn, BlockPos pos, BlockState newState, boolean isMoving) {
if (!state.hasBlockEntity() || state.getBlock() == newState.getBlock())
return;
DepotBehaviour behaviour = get(worldIn, pos);
if (behaviour == null)
return;
ItemHelper.dropContents(worldIn, pos, behaviour.processingOutputBuffer);
for (TransportedItemStack transportedItemStack : behaviour.incoming) Containers.dropItemStack(worldIn, pos.getX(), pos.getY(), pos.getZ(), transportedItemStack.stack);
if (!behaviour.getHeldItemStack().isEmpty())
Containers.dropItemStack(worldIn, pos.getX(), pos.getY(), pos.getZ(), behaviour.getHeldItemStack());
worldIn.removeBlockEntity(pos);
}
use of com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack in project Create by Creators-of-Create.
the class SharedDepotBlockMethods method onUse.
public static InteractionResult onUse(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult ray) {
if (ray.getDirection() != Direction.UP)
return InteractionResult.PASS;
if (world.isClientSide)
return InteractionResult.SUCCESS;
DepotBehaviour behaviour = get(world, pos);
if (behaviour == null)
return InteractionResult.PASS;
if (!behaviour.canAcceptItems.get())
return InteractionResult.SUCCESS;
ItemStack heldItem = player.getItemInHand(hand);
boolean wasEmptyHanded = heldItem.isEmpty();
boolean shouldntPlaceItem = AllBlocks.MECHANICAL_ARM.isIn(heldItem);
ItemStack mainItemStack = behaviour.getHeldItemStack();
if (!mainItemStack.isEmpty()) {
player.getInventory().placeItemBackInInventory(mainItemStack);
behaviour.removeHeldItem();
world.playSound(null, pos, SoundEvents.ITEM_PICKUP, SoundSource.PLAYERS, .2f, 1f + Create.RANDOM.nextFloat());
}
ItemStackHandler outputs = behaviour.processingOutputBuffer;
for (int i = 0; i < outputs.getSlots(); i++) player.getInventory().placeItemBackInInventory(outputs.extractItem(i, 64, false));
if (!wasEmptyHanded && !shouldntPlaceItem) {
TransportedItemStack transported = new TransportedItemStack(heldItem);
transported.insertedFrom = player.getDirection();
transported.prevBeltPosition = .25f;
transported.beltPosition = .25f;
behaviour.setHeldItem(transported);
player.setItemInHand(hand, ItemStack.EMPTY);
AllSoundEvents.DEPOT_SLIDE.playOnServer(world, pos);
}
behaviour.tileEntity.notifyUpdate();
return InteractionResult.SUCCESS;
}
use of com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack in project Create by Creators-of-Create.
the class DepotItemHandler method extractItem.
@Override
public ItemStack extractItem(int slot, int amount, boolean simulate) {
if (slot != MAIN_SLOT)
return te.processingOutputBuffer.extractItem(slot - 1, amount, simulate);
TransportedItemStack held = te.heldItem;
if (held == null)
return ItemStack.EMPTY;
ItemStack stack = held.stack.copy();
ItemStack extracted = stack.split(amount);
if (!simulate) {
te.heldItem.stack = stack;
if (stack.isEmpty())
te.heldItem = null;
te.tileEntity.notifyUpdate();
}
return extracted;
}
Aggregations