use of com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack in project Create by Creators-of-Create.
the class BeltRenderer method renderItems.
protected void renderItems(BeltTileEntity te, float partialTicks, PoseStack ms, MultiBufferSource buffer, int light, int overlay) {
if (!te.isController())
return;
if (te.beltLength == 0)
return;
ms.pushPose();
Direction beltFacing = te.getBeltFacing();
Vec3i directionVec = beltFacing.getNormal();
Vec3 beltStartOffset = Vec3.atLowerCornerOf(directionVec).scale(-.5).add(.5, 15 / 16f, .5);
ms.translate(beltStartOffset.x, beltStartOffset.y, beltStartOffset.z);
BeltSlope slope = te.getBlockState().getValue(BeltBlock.SLOPE);
int verticality = slope == BeltSlope.DOWNWARD ? -1 : slope == BeltSlope.UPWARD ? 1 : 0;
boolean slopeAlongX = beltFacing.getAxis() == Axis.X;
boolean onContraption = te.getLevel() instanceof WrappedWorld;
for (TransportedItemStack transported : te.getInventory().getTransportedItems()) {
ms.pushPose();
TransformStack.cast(ms).nudge(transported.angle);
float offset;
float sideOffset;
float verticalMovement;
if (te.getSpeed() == 0) {
offset = transported.beltPosition;
sideOffset = transported.sideOffset;
} else {
offset = Mth.lerp(partialTicks, transported.prevBeltPosition, transported.beltPosition);
sideOffset = Mth.lerp(partialTicks, transported.prevSideOffset, transported.sideOffset);
}
if (offset < .5)
verticalMovement = 0;
else
verticalMovement = verticality * (Math.min(offset, te.beltLength - .5f) - .5f);
Vec3 offsetVec = Vec3.atLowerCornerOf(directionVec).scale(offset);
if (verticalMovement != 0)
offsetVec = offsetVec.add(0, verticalMovement, 0);
boolean onSlope = slope != BeltSlope.HORIZONTAL && Mth.clamp(offset, .5f, te.beltLength - .5f) == offset;
boolean tiltForward = (slope == BeltSlope.DOWNWARD ^ beltFacing.getAxisDirection() == AxisDirection.POSITIVE) == (beltFacing.getAxis() == Axis.Z);
float slopeAngle = onSlope ? tiltForward ? -45 : 45 : 0;
ms.translate(offsetVec.x, offsetVec.y, offsetVec.z);
boolean alongX = beltFacing.getClockWise().getAxis() == Axis.X;
if (!alongX)
sideOffset *= -1;
ms.translate(alongX ? sideOffset : 0, 0, alongX ? 0 : sideOffset);
int stackLight = onContraption ? light : getPackedLight(te, offset);
ItemRenderer itemRenderer = Minecraft.getInstance().getItemRenderer();
boolean renderUpright = BeltHelper.isItemUpright(transported.stack);
boolean blockItem = itemRenderer.getModel(transported.stack, te.getLevel(), null, 0).isGui3d();
int count = (int) (Mth.log2((int) (transported.stack.getCount()))) / 2;
Random r = new Random(transported.angle);
boolean slopeShadowOnly = renderUpright && onSlope;
float slopeOffset = 1 / 8f;
if (slopeShadowOnly)
ms.pushPose();
if (!renderUpright || slopeShadowOnly)
ms.mulPose(new Vector3f(slopeAlongX ? 0 : 1, 0, slopeAlongX ? 1 : 0).rotationDegrees(slopeAngle));
if (onSlope)
ms.translate(0, slopeOffset, 0);
ms.pushPose();
ms.translate(0, -1 / 8f + 0.005f, 0);
ShadowRenderHelper.renderShadow(ms, buffer, .75f, .2f);
ms.popPose();
if (slopeShadowOnly) {
ms.popPose();
ms.translate(0, slopeOffset, 0);
}
if (renderUpright) {
Entity renderViewEntity = Minecraft.getInstance().cameraEntity;
if (renderViewEntity != null) {
Vec3 positionVec = renderViewEntity.position();
Vec3 vectorForOffset = BeltHelper.getVectorForOffset(te, offset);
Vec3 diff = vectorForOffset.subtract(positionVec);
float yRot = (float) (Mth.atan2(diff.x, diff.z) + Math.PI);
ms.mulPose(Vector3f.YP.rotation(yRot));
}
ms.translate(0, 3 / 32d, 1 / 16f);
}
for (int i = 0; i <= count; i++) {
ms.pushPose();
ms.mulPose(Vector3f.YP.rotationDegrees(transported.angle));
if (!blockItem && !renderUpright) {
ms.translate(0, -.09375, 0);
ms.mulPose(Vector3f.XP.rotationDegrees(90));
}
if (blockItem) {
ms.translate(r.nextFloat() * .0625f * i, 0, r.nextFloat() * .0625f * i);
}
ms.scale(.5f, .5f, .5f);
itemRenderer.renderStatic(null, transported.stack, TransformType.FIXED, false, ms, buffer, te.getLevel(), stackLight, overlay, 0);
ms.popPose();
if (!renderUpright) {
if (!blockItem)
ms.mulPose(Vector3f.YP.rotationDegrees(10));
ms.translate(0, blockItem ? 1 / 64d : 1 / 16d, 0);
} else
ms.translate(0, 0, -1 / 16f);
}
ms.popPose();
}
ms.popPose();
}
use of com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack in project Create by Creators-of-Create.
the class BeltSlicer method useWrench.
public static InteractionResult useWrench(BlockState state, Level world, BlockPos pos, Player player, InteractionHand handIn, BlockHitResult hit, Feedback feedBack) {
BeltTileEntity controllerTE = BeltHelper.getControllerTE(world, pos);
if (controllerTE == null)
return InteractionResult.PASS;
if (state.getValue(BeltBlock.CASING) && hit.getDirection() != Direction.UP)
return InteractionResult.PASS;
if (state.getValue(BeltBlock.PART) == BeltPart.PULLEY && hit.getDirection().getAxis() != Axis.Y)
return InteractionResult.PASS;
int beltLength = controllerTE.beltLength;
if (beltLength == 2)
return InteractionResult.FAIL;
BlockPos beltVector = new BlockPos(BeltHelper.getBeltVector(state));
BeltPart part = state.getValue(BeltBlock.PART);
List<BlockPos> beltChain = BeltBlock.getBeltChain(world, controllerTE.getBlockPos());
boolean creative = player.isCreative();
// Shorten from End
if (hoveringEnd(state, hit)) {
if (world.isClientSide)
return InteractionResult.SUCCESS;
for (BlockPos blockPos : beltChain) {
BeltTileEntity belt = BeltHelper.getSegmentTE(world, blockPos);
if (belt == null)
continue;
belt.detachKinetics();
belt.invalidateItemHandler();
belt.beltLength = 0;
}
BeltInventory inventory = controllerTE.inventory;
BlockPos next = part == BeltPart.END ? pos.subtract(beltVector) : pos.offset(beltVector);
BlockState replacedState = world.getBlockState(next);
BeltTileEntity segmentTE = BeltHelper.getSegmentTE(world, next);
KineticTileEntity.switchToBlockState(world, next, state.setValue(BeltBlock.CASING, segmentTE != null && segmentTE.casing != CasingType.NONE));
world.setBlock(pos, Blocks.AIR.defaultBlockState(), Block.UPDATE_ALL | Block.UPDATE_MOVE_BY_PISTON);
world.removeBlockEntity(pos);
world.levelEvent(2001, pos, Block.getId(state));
if (!creative && AllBlocks.BELT.has(replacedState) && replacedState.getValue(BeltBlock.PART) == BeltPart.PULLEY)
player.getInventory().placeItemBackInInventory(AllBlocks.SHAFT.asStack());
// Eject overshooting items
if (part == BeltPart.END && inventory != null) {
List<TransportedItemStack> toEject = new ArrayList<>();
for (TransportedItemStack transportedItemStack : inventory.getTransportedItems()) if (transportedItemStack.beltPosition > beltLength - 1)
toEject.add(transportedItemStack);
toEject.forEach(inventory::eject);
toEject.forEach(inventory.getTransportedItems()::remove);
}
// Transfer items to new controller
if (part == BeltPart.START && segmentTE != null && inventory != null) {
controllerTE.inventory = null;
segmentTE.inventory = null;
segmentTE.setController(next);
for (TransportedItemStack transportedItemStack : inventory.getTransportedItems()) {
transportedItemStack.beltPosition -= 1;
if (transportedItemStack.beltPosition <= 0) {
ItemEntity entity = new ItemEntity(world, pos.getX() + .5f, pos.getY() + 11 / 16f, pos.getZ() + .5f, transportedItemStack.stack);
entity.setDeltaMovement(Vec3.ZERO);
entity.setDefaultPickUpDelay();
entity.hurtMarked = true;
world.addFreshEntity(entity);
} else
segmentTE.getInventory().addItem(transportedItemStack);
}
}
return InteractionResult.SUCCESS;
}
BeltTileEntity segmentTE = BeltHelper.getSegmentTE(world, pos);
if (segmentTE == null)
return InteractionResult.PASS;
// Split in half
int hitSegment = segmentTE.index;
Vec3 centerOf = VecHelper.getCenterOf(hit.getBlockPos());
Vec3 subtract = hit.getLocation().subtract(centerOf);
boolean towardPositive = subtract.dot(Vec3.atLowerCornerOf(beltVector)) > 0;
BlockPos next = !towardPositive ? pos.subtract(beltVector) : pos.offset(beltVector);
if (hitSegment == 0 || hitSegment == 1 && !towardPositive)
return InteractionResult.FAIL;
if (hitSegment == controllerTE.beltLength - 1 || hitSegment == controllerTE.beltLength - 2 && towardPositive)
return InteractionResult.FAIL;
// Look for shafts
if (!creative) {
int requiredShafts = 0;
if (!segmentTE.hasPulley())
requiredShafts++;
BlockState other = world.getBlockState(next);
if (AllBlocks.BELT.has(other) && other.getValue(BeltBlock.PART) == BeltPart.MIDDLE)
requiredShafts++;
int amountRetrieved = 0;
boolean beltFound = false;
Search: while (true) {
for (int i = 0; i < player.getInventory().getContainerSize(); ++i) {
if (amountRetrieved == requiredShafts && beltFound)
break Search;
ItemStack itemstack = player.getInventory().getItem(i);
if (itemstack.isEmpty())
continue;
int count = itemstack.getCount();
if (AllItems.BELT_CONNECTOR.isIn(itemstack)) {
if (!world.isClientSide)
itemstack.shrink(1);
beltFound = true;
continue;
}
if (AllBlocks.SHAFT.isIn(itemstack)) {
int taken = Math.min(count, requiredShafts - amountRetrieved);
if (!world.isClientSide)
if (taken == count)
player.getInventory().setItem(i, ItemStack.EMPTY);
else
itemstack.shrink(taken);
amountRetrieved += taken;
}
}
if (!world.isClientSide)
player.getInventory().placeItemBackInInventory(AllBlocks.SHAFT.asStack(amountRetrieved));
return InteractionResult.FAIL;
}
}
if (!world.isClientSide) {
for (BlockPos blockPos : beltChain) {
BeltTileEntity belt = BeltHelper.getSegmentTE(world, blockPos);
if (belt == null)
continue;
belt.detachKinetics();
belt.invalidateItemHandler();
belt.beltLength = 0;
}
BeltInventory inventory = controllerTE.inventory;
KineticTileEntity.switchToBlockState(world, pos, state.setValue(BeltBlock.PART, towardPositive ? BeltPart.END : BeltPart.START));
KineticTileEntity.switchToBlockState(world, next, world.getBlockState(next).setValue(BeltBlock.PART, towardPositive ? BeltPart.START : BeltPart.END));
world.playSound(null, pos, SoundEvents.WOOL_HIT, player == null ? SoundSource.BLOCKS : SoundSource.PLAYERS, 0.5F, 2.3F);
// Transfer items to new controller
BeltTileEntity newController = towardPositive ? BeltHelper.getSegmentTE(world, next) : segmentTE;
if (newController != null && inventory != null) {
newController.inventory = null;
newController.setController(newController.getBlockPos());
for (Iterator<TransportedItemStack> iterator = inventory.getTransportedItems().iterator(); iterator.hasNext(); ) {
TransportedItemStack transportedItemStack = iterator.next();
float newPosition = transportedItemStack.beltPosition - hitSegment - (towardPositive ? 1 : 0);
if (newPosition <= 0)
continue;
transportedItemStack.beltPosition = newPosition;
iterator.remove();
newController.getInventory().addItem(transportedItemStack);
}
}
}
return InteractionResult.SUCCESS;
}
use of com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack in project Create by Creators-of-Create.
the class BeltSlicer method useConnector.
public static InteractionResult useConnector(BlockState state, Level world, BlockPos pos, Player player, InteractionHand handIn, BlockHitResult hit, Feedback feedBack) {
BeltTileEntity controllerTE = BeltHelper.getControllerTE(world, pos);
if (controllerTE == null)
return InteractionResult.PASS;
int beltLength = controllerTE.beltLength;
if (beltLength == BeltConnectorItem.maxLength())
return InteractionResult.FAIL;
BlockPos beltVector = new BlockPos(BeltHelper.getBeltVector(state));
BeltPart part = state.getValue(BeltBlock.PART);
Direction facing = state.getValue(BeltBlock.HORIZONTAL_FACING);
List<BlockPos> beltChain = BeltBlock.getBeltChain(world, controllerTE.getBlockPos());
boolean creative = player.isCreative();
if (!hoveringEnd(state, hit))
return InteractionResult.PASS;
BlockPos next = part == BeltPart.START ? pos.subtract(beltVector) : pos.offset(beltVector);
BeltTileEntity mergedController = null;
int mergedBeltLength = 0;
// Merge Belts / Extend at End
BlockState nextState = world.getBlockState(next);
if (!nextState.getMaterial().isReplaceable()) {
if (!AllBlocks.BELT.has(nextState))
return InteractionResult.FAIL;
if (!beltStatesCompatible(state, nextState))
return InteractionResult.FAIL;
mergedController = BeltHelper.getControllerTE(world, next);
if (mergedController == null)
return InteractionResult.FAIL;
if (mergedController.beltLength + beltLength > BeltConnectorItem.maxLength())
return InteractionResult.FAIL;
mergedBeltLength = mergedController.beltLength;
if (!world.isClientSide) {
boolean flipBelt = facing != nextState.getValue(BeltBlock.HORIZONTAL_FACING);
Optional<DyeColor> color = controllerTE.color;
for (BlockPos blockPos : BeltBlock.getBeltChain(world, mergedController.getBlockPos())) {
BeltTileEntity belt = BeltHelper.getSegmentTE(world, blockPos);
if (belt == null)
continue;
belt.detachKinetics();
belt.invalidateItemHandler();
belt.beltLength = 0;
belt.color = color;
if (flipBelt)
world.setBlock(blockPos, flipBelt(world.getBlockState(blockPos)), Block.UPDATE_ALL | Block.UPDATE_MOVE_BY_PISTON);
}
// Reverse items
if (flipBelt && mergedController.inventory != null) {
List<TransportedItemStack> transportedItems = mergedController.inventory.getTransportedItems();
for (TransportedItemStack transportedItemStack : transportedItems) {
transportedItemStack.beltPosition = mergedBeltLength - transportedItemStack.beltPosition;
transportedItemStack.prevBeltPosition = mergedBeltLength - transportedItemStack.prevBeltPosition;
}
}
}
}
if (!world.isClientSide) {
for (BlockPos blockPos : beltChain) {
BeltTileEntity belt = BeltHelper.getSegmentTE(world, blockPos);
if (belt == null)
continue;
belt.detachKinetics();
belt.invalidateItemHandler();
belt.beltLength = 0;
}
BeltInventory inventory = controllerTE.inventory;
KineticTileEntity.switchToBlockState(world, pos, state.setValue(BeltBlock.PART, BeltPart.MIDDLE));
if (mergedController == null) {
// Attach at end
world.setBlock(next, state.setValue(BeltBlock.CASING, false), Block.UPDATE_ALL | Block.UPDATE_MOVE_BY_PISTON);
BeltTileEntity segmentTE = BeltHelper.getSegmentTE(world, next);
if (segmentTE != null)
segmentTE.color = controllerTE.color;
world.playSound(null, pos, SoundEvents.WOOL_PLACE, player == null ? SoundSource.BLOCKS : SoundSource.PLAYERS, 0.5F, 1F);
// Transfer items to new controller
if (part == BeltPart.START && segmentTE != null && inventory != null) {
segmentTE.setController(next);
for (TransportedItemStack transportedItemStack : inventory.getTransportedItems()) {
transportedItemStack.beltPosition += 1;
segmentTE.getInventory().addItem(transportedItemStack);
}
}
} else {
// Merge with other
BeltInventory mergedInventory = mergedController.inventory;
world.playSound(null, pos, SoundEvents.WOOL_HIT, player == null ? SoundSource.BLOCKS : SoundSource.PLAYERS, 0.5F, 1.3F);
BeltTileEntity segmentTE = BeltHelper.getSegmentTE(world, next);
KineticTileEntity.switchToBlockState(world, next, state.setValue(BeltBlock.CASING, segmentTE != null && segmentTE.casing != CasingType.NONE).setValue(BeltBlock.PART, BeltPart.MIDDLE));
if (!creative) {
player.getInventory().placeItemBackInInventory(AllBlocks.SHAFT.asStack(2));
player.getInventory().placeItemBackInInventory(AllItems.BELT_CONNECTOR.asStack());
}
// Transfer items to other controller
BlockPos search = controllerTE.getBlockPos();
for (int i = 0; i < 10000; i++) {
BlockState blockState = world.getBlockState(search);
if (!AllBlocks.BELT.has(blockState))
break;
if (blockState.getValue(BeltBlock.PART) != BeltPart.START) {
search = search.subtract(beltVector);
continue;
}
BeltTileEntity newController = BeltHelper.getSegmentTE(world, search);
if (newController != controllerTE && inventory != null) {
newController.setController(search);
controllerTE.inventory = null;
for (TransportedItemStack transportedItemStack : inventory.getTransportedItems()) {
transportedItemStack.beltPosition += mergedBeltLength;
newController.getInventory().addItem(transportedItemStack);
}
}
if (newController != mergedController && mergedInventory != null) {
newController.setController(search);
mergedController.inventory = null;
for (TransportedItemStack transportedItemStack : mergedInventory.getTransportedItems()) {
if (newController == controllerTE)
transportedItemStack.beltPosition += beltLength;
newController.getInventory().addItem(transportedItemStack);
}
}
break;
}
}
}
return InteractionResult.SUCCESS;
}
use of com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack in project Create by Creators-of-Create.
the class FanScenes method processing.
public static void processing(SceneBuilder scene, SceneBuildingUtil util) {
scene.title("fan_processing", "Processing Items using Encased Fans");
scene.configureBasePlate(1, 0, 5);
scene.world.showSection(util.select.layer(0).substract(util.select.position(0, 0, 4)), Direction.UP);
scene.idle(5);
scene.world.showSection(util.select.fromTo(6, 1, 2, 5, 1, 2).add(util.select.position(1, 1, 2)), Direction.DOWN);
scene.idle(25);
BlockPos blockPos = util.grid.at(4, 1, 2);
// blasting start
ElementLink<WorldSectionElement> blockInFront = scene.world.showIndependentSection(util.select.position(3, 1, 0), Direction.SOUTH);
scene.world.moveSection(blockInFront, util.vector.of(1, 0, 2), 0);
scene.world.setBlock(blockPos, Blocks.LAVA.defaultBlockState(), false);
scene.idle(10);
scene.overlay.showSelectionWithText(util.select.fromTo(blockPos, blockPos.west(2)), 80).colored(PonderPalette.RED).text("When passing through lava, the Air Flow becomes Heated");
scene.idle(80);
ItemStack stack = new ItemStack(Items.GOLD_ORE);
ItemStack smelted = new ItemStack(Items.GOLD_INGOT);
ElementLink<EntityElement> entityLink = scene.world.createItemEntity(util.vector.centerOf(blockPos.west(2).above(2)), util.vector.of(0, 0.1, 0), stack);
scene.idle(15);
scene.world.modifyEntity(entityLink, e -> e.setDeltaMovement(-0.2f, 0, 0));
Vec3 itemVec = util.vector.blockSurface(util.grid.at(1, 1, 2), Direction.EAST).add(0.1, 0, 0);
scene.overlay.showControls(new InputWindowElement(itemVec, Pointing.DOWN).withItem(stack), 20);
scene.idle(20);
scene.effects.emitParticles(itemVec.add(0, 0.2f, 0), Emitter.simple(ParticleTypes.LARGE_SMOKE, Vec3.ZERO), 1, 60);
scene.overlay.showText(80).colored(PonderPalette.WHITE).pointAt(itemVec).placeNearTarget().attachKeyFrame().text("Items caught in the area will be smelted");
scene.idle(60);
scene.world.modifyEntities(ItemEntity.class, ie -> ie.setItem(smelted));
scene.idle(40);
scene.overlay.showControls(new InputWindowElement(itemVec, Pointing.DOWN).withItem(smelted), 20);
scene.idle(20);
scene.world.modifyEntities(ItemEntity.class, Entity::discard);
scene.idle(20);
scene.overlay.showText(80).colored(PonderPalette.RED).pointAt(itemVec).placeNearTarget().text("Food items thrown here would be incinerated");
scene.idle(40);
// smoking start
BlockState campfire = Blocks.FIRE.defaultBlockState();
scene.world.hideIndependentSection(blockInFront, Direction.NORTH);
scene.idle(15);
scene.world.setBlock(util.grid.at(3, 1, 0), campfire, false);
scene.world.setBlock(blockPos, campfire, true);
blockInFront = scene.world.showIndependentSection(util.select.position(3, 1, 0), Direction.NORTH);
scene.world.moveSection(blockInFront, util.vector.of(1, 0, 2), 0);
scene.idle(50);
scene.overlay.showSelectionWithText(util.select.fromTo(blockPos, blockPos.west(2)), 60).colored(PonderPalette.BLACK).attachKeyFrame().text("Instead, a setup for Smoking using Fire should be used for them");
scene.idle(80);
// washing start
BlockState water = Blocks.WATER.defaultBlockState();
scene.world.hideIndependentSection(blockInFront, Direction.NORTH);
scene.idle(15);
scene.world.setBlock(util.grid.at(3, 1, 0), water, false);
scene.world.setBlock(blockPos, water, true);
blockInFront = scene.world.showIndependentSection(util.select.position(3, 1, 0), Direction.NORTH);
scene.world.moveSection(blockInFront, util.vector.of(1, 0, 2), 0);
scene.idle(20);
scene.overlay.showSelectionWithText(util.select.fromTo(blockPos, blockPos.west(2)), 60).colored(PonderPalette.MEDIUM).attachKeyFrame().text("Air Flows passing through water create a Washing Setup");
scene.idle(70);
stack = new ItemStack(Items.RED_SAND, 16);
ItemStack washed = new ItemStack(Items.GOLD_NUGGET, 16);
entityLink = scene.world.createItemEntity(util.vector.centerOf(blockPos.west(2).above(2)), util.vector.of(0, 0.1, 0), stack);
scene.idle(15);
scene.world.modifyEntity(entityLink, e -> e.setDeltaMovement(-0.2f, 0, 0));
scene.overlay.showControls(new InputWindowElement(itemVec, Pointing.DOWN).withItem(stack), 20);
scene.idle(20);
scene.effects.emitParticles(itemVec.add(0, 0.2f, 0), Emitter.simple(ParticleTypes.SPIT, Vec3.ZERO), 1, 60);
scene.overlay.showText(50).colored(PonderPalette.WHITE).pointAt(itemVec).placeNearTarget().text("Some interesting new processing can be done with it");
scene.idle(60);
scene.world.modifyEntities(ItemEntity.class, ie -> ie.setItem(washed));
scene.overlay.showControls(new InputWindowElement(itemVec, Pointing.DOWN).withItem(washed), 20);
scene.idle(20);
scene.world.modifyEntities(ItemEntity.class, Entity::discard);
scene.idle(20);
scene.overlay.showText(100).colored(PonderPalette.RED).pointAt(util.vector.topOf(blockPos.east())).placeNearTarget().attachKeyFrame().text("The Speed of the Fan does NOT affect the processing speed, only its range");
scene.world.destroyBlock(util.grid.at(1, 1, 2));
scene.idle(110);
ElementLink<WorldSectionElement> cogs = scene.world.makeSectionIndependent(util.select.fromTo(6, 1, 2, 6, 0, 3).add(util.select.fromTo(4, 0, 2, 5, 0, 2)));
scene.world.modifyKineticSpeed(util.select.position(5, 2, 2), f -> f / 3f);
scene.world.moveSection(cogs, util.vector.of(0, 1, 0), 15);
scene.world.moveSection(blockInFront, util.vector.of(0, 1, 0), 15);
scene.world.destroyBlock(blockPos.east());
scene.world.showSection(util.select.position(blockPos.east().above()), Direction.DOWN);
scene.world.setBlock(blockPos.above(), Blocks.WATER.defaultBlockState(), false);
ItemStack sand = new ItemStack(Items.SAND);
ItemStack clay = new ItemStack(Items.CLAY_BALL);
scene.idle(20);
BlockPos depos = util.grid.at(3, 4, 2);
ElementLink<WorldSectionElement> depot = scene.world.showIndependentSection(util.select.position(depos), Direction.DOWN);
scene.world.moveSection(depot, util.vector.of(-1, -3, 0), 0);
scene.world.createItemOnBeltLike(depos, Direction.NORTH, sand);
scene.idle(10);
Vec3 depotTop = util.vector.topOf(2, 1, 2).add(0, 0.25, 0);
scene.effects.emitParticles(depotTop, Emitter.simple(ParticleTypes.SPIT, Vec3.ZERO), .5f, 30);
scene.idle(30);
scene.world.modifyTileNBT(util.select.position(depos), DepotTileEntity.class, nbt -> nbt.put("HeldItem", new TransportedItemStack(clay).serializeNBT()));
scene.effects.emitParticles(depotTop, Emitter.simple(ParticleTypes.SPIT, Vec3.ZERO), .5f, 30);
scene.overlay.showText(90).pointAt(depotTop).attachKeyFrame().text("Fan Processing can also be applied to Items on Depots and Belts");
scene.idle(100);
scene.world.moveSection(depot, util.vector.of(-1, 0, 0), 15);
scene.idle(15);
ElementLink<WorldSectionElement> largeCog = scene.world.showIndependentSection(util.select.position(1, 2, 4), Direction.UP);
ElementLink<WorldSectionElement> belt = scene.world.showIndependentSection(util.select.fromTo(3, 3, 1, 1, 3, 3), Direction.DOWN);
scene.world.moveSection(largeCog, util.vector.of(-1, -2, 0), 0);
scene.world.moveSection(belt, util.vector.of(-1, -2, 0), 0);
ElementLink<BeltItemElement> transported = scene.world.createItemOnBelt(util.grid.at(3, 3, 3), Direction.SOUTH, sand);
scene.idle(60);
scene.effects.emitParticles(depotTop, Emitter.simple(ParticleTypes.SPIT, Vec3.ZERO), .5f, 25);
scene.idle(25);
scene.world.changeBeltItemTo(transported, new ItemStack(Items.CLAY_BALL));
scene.effects.emitParticles(depotTop, Emitter.simple(ParticleTypes.SPIT, Vec3.ZERO), .5f, 25);
scene.idle(60);
scene.world.setKineticSpeed(util.select.position(1, 2, 4).add(util.select.fromTo(3, 3, 1, 1, 3, 3)), 0);
}
use of com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack in project Create by Creators-of-Create.
the class EjectorTileEntity method launchItems.
protected void launchItems() {
ItemStack heldItemStack = depotBehaviour.getHeldItemStack();
Direction funnelFacing = getFacing().getOpposite();
if (AbstractFunnelBlock.getFunnelFacing(level.getBlockState(worldPosition.above())) == funnelFacing) {
DirectBeltInputBehaviour directOutput = getBehaviour(DirectBeltInputBehaviour.TYPE);
if (depotBehaviour.heldItem != null) {
ItemStack remainder = directOutput.tryExportingToBeltFunnel(heldItemStack, funnelFacing, false);
if (remainder == null)
;
else if (remainder.isEmpty())
depotBehaviour.removeHeldItem();
else if (!remainder.sameItem(heldItemStack))
depotBehaviour.heldItem.stack = remainder;
}
for (Iterator<TransportedItemStack> iterator = depotBehaviour.incoming.iterator(); iterator.hasNext(); ) {
TransportedItemStack transportedItemStack = iterator.next();
ItemStack stack = transportedItemStack.stack;
ItemStack remainder = directOutput.tryExportingToBeltFunnel(stack, funnelFacing, false);
if (remainder == null)
;
else if (remainder.isEmpty())
iterator.remove();
else if (!remainder.sameItem(stack))
transportedItemStack.stack = remainder;
}
ItemStackHandler outputs = depotBehaviour.processingOutputBuffer;
for (int i = 0; i < outputs.getSlots(); i++) {
ItemStack remainder = directOutput.tryExportingToBeltFunnel(outputs.getStackInSlot(i), funnelFacing, false);
if (remainder != null)
outputs.setStackInSlot(i, remainder);
}
return;
}
if (!level.isClientSide)
for (Direction d : Iterate.directions) {
BlockState blockState = level.getBlockState(worldPosition.relative(d));
if (!(blockState.getBlock() instanceof ObserverBlock))
continue;
if (blockState.getValue(ObserverBlock.FACING) != d.getOpposite())
continue;
blockState.updateShape(d.getOpposite(), blockState, level, worldPosition.relative(d), worldPosition);
}
if (depotBehaviour.heldItem != null) {
addToLaunchedItems(heldItemStack);
depotBehaviour.removeHeldItem();
}
for (TransportedItemStack transportedItemStack : depotBehaviour.incoming) addToLaunchedItems(transportedItemStack.stack);
depotBehaviour.incoming.clear();
ItemStackHandler outputs = depotBehaviour.processingOutputBuffer;
for (int i = 0; i < outputs.getSlots(); i++) {
ItemStack extractItem = outputs.extractItem(i, 64, false);
if (!extractItem.isEmpty())
addToLaunchedItems(extractItem);
}
}
Aggregations