use of com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack in project Create by Creators-of-Create.
the class BeltTileEntity method tryInsertingFromSide.
private ItemStack tryInsertingFromSide(TransportedItemStack transportedStack, Direction side, boolean simulate) {
BeltTileEntity nextBeltController = getControllerTE();
ItemStack inserted = transportedStack.stack;
ItemStack empty = ItemStack.EMPTY;
if (nextBeltController == null)
return inserted;
BeltInventory nextInventory = nextBeltController.getInventory();
if (nextInventory == null)
return inserted;
BlockEntity teAbove = level.getBlockEntity(worldPosition.above());
if (teAbove instanceof BrassTunnelTileEntity) {
BrassTunnelTileEntity tunnelTE = (BrassTunnelTileEntity) teAbove;
if (tunnelTE.hasDistributionBehaviour()) {
if (!tunnelTE.getStackToDistribute().isEmpty())
return inserted;
if (!tunnelTE.testFlapFilter(side.getOpposite(), inserted))
return inserted;
if (!simulate) {
BeltTunnelInteractionHandler.flapTunnel(nextInventory, index, side.getOpposite(), true);
tunnelTE.setStackToDistribute(inserted);
}
return empty;
}
}
if (getSpeed() == 0)
return inserted;
if (getMovementFacing() == side.getOpposite())
return inserted;
if (!nextInventory.canInsertAtFromSide(index, side))
return inserted;
if (simulate)
return empty;
transportedStack = transportedStack.copy();
transportedStack.beltPosition = index + .5f - Math.signum(getDirectionAwareBeltMovementSpeed()) / 16f;
Direction movementFacing = getMovementFacing();
if (!side.getAxis().isVertical()) {
if (movementFacing != side) {
transportedStack.sideOffset = side.getAxisDirection().getStep() * .35f;
if (side.getAxis() == Axis.X)
transportedStack.sideOffset *= -1;
} else
transportedStack.beltPosition = getDirectionAwareBeltMovementSpeed() > 0 ? index : index + 1;
}
transportedStack.prevSideOffset = transportedStack.sideOffset;
transportedStack.insertedAt = index;
transportedStack.insertedFrom = side;
transportedStack.prevBeltPosition = transportedStack.beltPosition;
BeltTunnelInteractionHandler.flapTunnel(nextInventory, index, side.getOpposite(), true);
nextInventory.addItem(transportedStack);
nextBeltController.setChanged();
nextBeltController.sendData();
return empty;
}
use of com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack in project Create by Creators-of-Create.
the class ChromaticCompoundItem method onEntityItemUpdate.
@Override
public boolean onEntityItemUpdate(ItemStack stack, ItemEntity entity) {
double y = entity.getY();
double yMotion = entity.getDeltaMovement().y;
Level world = entity.level;
CompoundTag data = entity.getPersistentData();
CompoundTag itemData = entity.getItem().getOrCreateTag();
Vec3 positionVec = entity.position();
CRecipes config = AllConfigs.SERVER.recipes;
if (world.isClientSide) {
int light = itemData.getInt("CollectingLight");
if (world.random.nextInt(config.lightSourceCountForRefinedRadiance.get() + 20) < light) {
Vec3 start = VecHelper.offsetRandomly(positionVec, world.random, 3);
Vec3 motion = positionVec.subtract(start).normalize().scale(.2f);
world.addParticle(ParticleTypes.END_ROD, start.x, start.y, start.z, motion.x, motion.y, motion.z);
}
return false;
}
// Convert to Shadow steel if in void
if (y < 0 && y - yMotion < -10 && config.enableShadowSteelRecipe.get()) {
ItemStack newStack = AllItems.SHADOW_STEEL.asStack();
newStack.setCount(stack.getCount());
data.putBoolean("JustCreated", true);
entity.setItem(newStack);
}
if (!config.enableRefinedRadianceRecipe.get())
return false;
// Convert to Refined Radiance if eaten enough light sources
if (itemData.getInt("CollectingLight") >= config.lightSourceCountForRefinedRadiance.get()) {
ItemStack newStack = AllItems.REFINED_RADIANCE.asStack();
ItemEntity newEntity = new ItemEntity(world, entity.getX(), entity.getY(), entity.getZ(), newStack);
newEntity.setDeltaMovement(entity.getDeltaMovement());
newEntity.getPersistentData().putBoolean("JustCreated", true);
itemData.remove("CollectingLight");
world.addFreshEntity(newEntity);
stack.split(1);
entity.setItem(stack);
if (stack.isEmpty())
entity.discard();
return false;
}
// Is inside beacon beam?
boolean isOverBeacon = false;
int entityX = Mth.floor(entity.getX());
int entityZ = Mth.floor(entity.getZ());
int localWorldHeight = world.getHeight(Heightmap.Types.WORLD_SURFACE, entityX, entityZ);
BlockPos.MutableBlockPos testPos = new BlockPos.MutableBlockPos(entityX, Math.min(Mth.floor(entity.getY()), localWorldHeight), entityZ);
while (testPos.getY() > 0) {
testPos.move(Direction.DOWN);
BlockState state = world.getBlockState(testPos);
if (state.getLightBlock(world, testPos) >= 15 && state.getBlock() != Blocks.BEDROCK)
break;
if (state.getBlock() == Blocks.BEACON) {
BlockEntity te = world.getBlockEntity(testPos);
if (!(te instanceof BeaconBlockEntity))
break;
BeaconBlockEntity bte = (BeaconBlockEntity) te;
if (!bte.beamSections.isEmpty())
isOverBeacon = true;
break;
}
}
if (isOverBeacon) {
ItemStack newStack = AllItems.REFINED_RADIANCE.asStack();
newStack.setCount(stack.getCount());
data.putBoolean("JustCreated", true);
entity.setItem(newStack);
return false;
}
// Find a light source and eat it.
Random r = world.random;
int range = 3;
float rate = 1 / 2f;
if (r.nextFloat() > rate)
return false;
BlockPos randomOffset = new BlockPos(VecHelper.offsetRandomly(positionVec, r, range));
BlockState state = world.getBlockState(randomOffset);
TransportedItemStackHandlerBehaviour behaviour = TileEntityBehaviour.get(world, randomOffset, TransportedItemStackHandlerBehaviour.TYPE);
// Find a placed light source
if (behaviour == null) {
if (checkLight(stack, entity, world, itemData, positionVec, randomOffset, state))
world.destroyBlock(randomOffset, false);
return false;
}
// Find a light source from a depot/belt (chunk rebuild safe)
MutableBoolean success = new MutableBoolean(false);
behaviour.handleProcessingOnAllItems(ts -> {
ItemStack heldStack = ts.stack;
if (!(heldStack.getItem() instanceof BlockItem))
return TransportedResult.doNothing();
BlockItem blockItem = (BlockItem) heldStack.getItem();
if (blockItem.getBlock() == null)
return TransportedResult.doNothing();
BlockState stateToCheck = blockItem.getBlock().defaultBlockState();
if (!success.getValue() && checkLight(stack, entity, world, itemData, positionVec, randomOffset, stateToCheck)) {
success.setTrue();
if (ts.stack.getCount() == 1)
return TransportedResult.removeItem();
TransportedItemStack left = ts.copy();
left.stack.shrink(1);
return TransportedResult.convertTo(left);
}
return TransportedResult.doNothing();
});
return false;
}
use of com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack in project Create by Creators-of-Create.
the class BeltDeployerCallbacks method onItemReceived.
public static ProcessingResult onItemReceived(TransportedItemStack s, TransportedItemStackHandlerBehaviour i, DeployerTileEntity deployerTileEntity) {
if (deployerTileEntity.getSpeed() == 0)
return ProcessingResult.PASS;
if (deployerTileEntity.mode == Mode.PUNCH)
return ProcessingResult.PASS;
BlockState blockState = deployerTileEntity.getBlockState();
if (!blockState.hasProperty(FACING) || blockState.getValue(FACING) != Direction.DOWN)
return ProcessingResult.PASS;
if (deployerTileEntity.state != State.WAITING)
return ProcessingResult.HOLD;
if (deployerTileEntity.redstoneLocked)
return ProcessingResult.PASS;
DeployerFakePlayer player = deployerTileEntity.getPlayer();
ItemStack held = player == null ? ItemStack.EMPTY : player.getMainHandItem();
if (held.isEmpty())
return ProcessingResult.HOLD;
if (deployerTileEntity.getRecipe(s.stack) == null)
return ProcessingResult.PASS;
deployerTileEntity.start();
return ProcessingResult.HOLD;
}
use of com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack in project Create by Creators-of-Create.
the class ItemDrainItemHandler method extractItem.
@Override
public ItemStack extractItem(int slot, int amount, boolean 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.notifyUpdate();
}
return extracted;
}
use of com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack in project Create by Creators-of-Create.
the class ItemDrainItemHandler method insertItem.
@Override
public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) {
if (!te.getHeldItemStack().isEmpty())
return stack;
ItemStack returned = ItemStack.EMPTY;
if (stack.getCount() > 1 && EmptyingByBasin.canItemBeEmptied(te.getLevel(), stack)) {
returned = ItemHandlerHelper.copyStackWithSize(stack, stack.getCount() - 1);
stack = ItemHandlerHelper.copyStackWithSize(stack, 1);
}
if (!simulate) {
TransportedItemStack heldItem = new TransportedItemStack(stack);
heldItem.prevBeltPosition = 0;
te.setHeldItem(heldItem, side.getOpposite());
te.notifyUpdate();
}
return returned;
}
Aggregations