use of com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack in project createaddition by mrh0.
the class TeslaCoilTileEntity method chargeAE2.
protected boolean chargeAE2(ItemStack stack, TransportedItemStack transported, TransportedItemStackHandlerBehaviour handler) {
if (!CreateAddition.AE2_ACTIVE)
return false;
if (!AE2.isCertusQuartz(stack))
return false;
int energyRemoved = energy.internalConsumeEnergy(getConsumption());
if (energyRemoved >= getConsumption() && level.random.nextFloat() > CERTUS_QUARTZ_CHANCE) {
TransportedItemStack left = transported.copy();
left.stack.shrink(1);
List<TransportedItemStack> r = new ArrayList<>();
r.add(new TransportedItemStack(AE2.getChargedCertusQuartz(1)));
// .ifPresent(is -> r.add(new TransportedItemStack(is)));
handler.handleProcessingOnItem(transported, TransportedResult.convertToAndLeaveHeld(r, left));
}
return true;
}
use of com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack in project Create by Creators-of-Create.
the class ItemDrainTileEntity method tryInsertingFromSide.
private ItemStack tryInsertingFromSide(TransportedItemStack transportedStack, Direction side, boolean simulate) {
ItemStack inserted = transportedStack.stack;
ItemStack returned = ItemStack.EMPTY;
if (!getHeldItemStack().isEmpty())
return inserted;
if (inserted.getCount() > 1 && EmptyingByBasin.canItemBeEmptied(level, inserted)) {
returned = ItemHandlerHelper.copyStackWithSize(inserted, inserted.getCount() - 1);
inserted = ItemHandlerHelper.copyStackWithSize(inserted, 1);
}
if (simulate)
return returned;
transportedStack = transportedStack.copy();
transportedStack.beltPosition = side.getAxis().isVertical() ? .5f : 0;
transportedStack.prevSideOffset = transportedStack.sideOffset;
transportedStack.prevBeltPosition = transportedStack.beltPosition;
setHeldItem(transportedStack, side);
setChanged();
sendData();
return returned;
}
use of com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack in project Create by Creators-of-Create.
the class BeltPressingCallbacks method whenItemHeld.
static ProcessingResult whenItemHeld(TransportedItemStack transported, TransportedItemStackHandlerBehaviour handler, MechanicalPressTileEntity pressTe) {
if (pressTe.getSpeed() == 0)
return PASS;
if (!pressTe.running)
return PASS;
if (pressTe.runningTicks != MechanicalPressTileEntity.CYCLE / 2)
return HOLD;
Optional<PressingRecipe> recipe = pressTe.getRecipe(transported.stack);
pressTe.pressedItems.clear();
pressTe.pressedItems.add(transported.stack);
if (!recipe.isPresent())
return PASS;
boolean bulk = MechanicalPressTileEntity.canProcessInBulk() || transported.stack.getCount() == 1;
List<TransportedItemStack> collect = InWorldProcessing.applyRecipeOn(bulk ? transported.stack : ItemHandlerHelper.copyStackWithSize(transported.stack, 1), recipe.get()).stream().map(stack -> {
TransportedItemStack copy = transported.copy();
boolean centered = BeltHelper.isItemUpright(stack);
copy.stack = stack;
copy.locked = true;
copy.angle = centered ? 180 : Create.RANDOM.nextInt(360);
return copy;
}).collect(Collectors.toList());
if (bulk) {
if (collect.isEmpty())
handler.handleProcessingOnItem(transported, TransportedResult.removeItem());
else
handler.handleProcessingOnItem(transported, TransportedResult.convertTo(collect));
} else {
TransportedItemStack left = transported.copy();
left.stack.shrink(1);
if (collect.isEmpty())
handler.handleProcessingOnItem(transported, TransportedResult.convertTo(left));
else
handler.handleProcessingOnItem(transported, TransportedResult.convertToAndLeaveHeld(collect, left));
}
AllTriggers.triggerForNearbyPlayers(AllTriggers.BONK, pressTe.getLevel(), pressTe.getBlockPos(), 4);
pressTe.sendData();
return HOLD;
}
use of com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack in project Create by Creators-of-Create.
the class BeltDeployerCallbacks method whenItemHeld.
public static ProcessingResult whenItemHeld(TransportedItemStack s, TransportedItemStackHandlerBehaviour i, DeployerTileEntity deployerTileEntity) {
if (deployerTileEntity.getSpeed() == 0)
return ProcessingResult.PASS;
BlockState blockState = deployerTileEntity.getBlockState();
if (!blockState.hasProperty(FACING) || blockState.getValue(FACING) != Direction.DOWN)
return ProcessingResult.PASS;
DeployerFakePlayer player = deployerTileEntity.getPlayer();
ItemStack held = player == null ? ItemStack.EMPTY : player.getMainHandItem();
if (held.isEmpty())
return ProcessingResult.HOLD;
Recipe<?> recipe = deployerTileEntity.getRecipe(s.stack);
if (recipe == null)
return ProcessingResult.PASS;
if (deployerTileEntity.state == State.RETRACTING && deployerTileEntity.timer == 1000) {
activate(s, i, deployerTileEntity, recipe);
return ProcessingResult.HOLD;
}
if (deployerTileEntity.state == State.WAITING) {
if (deployerTileEntity.redstoneLocked)
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 BeltDeployerCallbacks method activate.
public static void activate(TransportedItemStack transported, TransportedItemStackHandlerBehaviour handler, DeployerTileEntity deployerTileEntity, Recipe<?> recipe) {
List<TransportedItemStack> collect = InWorldProcessing.applyRecipeOn(ItemHandlerHelper.copyStackWithSize(transported.stack, 1), recipe).stream().map(stack -> {
TransportedItemStack copy = transported.copy();
boolean centered = BeltHelper.isItemUpright(stack);
copy.stack = stack;
copy.locked = true;
copy.angle = centered ? 180 : Create.RANDOM.nextInt(360);
return copy;
}).map(t -> {
t.locked = false;
return t;
}).collect(Collectors.toList());
TransportedItemStack left = transported.copy();
deployerTileEntity.player.spawnedItemEffects = transported.stack.copy();
left.stack.shrink(1);
if (collect.isEmpty())
handler.handleProcessingOnItem(transported, TransportedResult.convertTo(left));
else
handler.handleProcessingOnItem(transported, TransportedResult.convertToAndLeaveHeld(collect, left));
ItemStack heldItem = deployerTileEntity.player.getMainHandItem();
boolean unbreakable = heldItem.hasTag() && heldItem.getTag().getBoolean("Unbreakable");
boolean keepHeld = recipe instanceof DeployerApplicationRecipe && ((DeployerApplicationRecipe) recipe).shouldKeepHeldItem();
if (!unbreakable && !keepHeld) {
if (heldItem.isDamageableItem())
heldItem.hurtAndBreak(1, deployerTileEntity.player, s -> s.broadcastBreakEvent(InteractionHand.MAIN_HAND));
else
heldItem.shrink(1);
}
BlockPos pos = deployerTileEntity.getBlockPos();
Level world = deployerTileEntity.getLevel();
if (heldItem.isEmpty())
world.playSound(null, pos, SoundEvents.ITEM_BREAK, SoundSource.BLOCKS, .25f, 1);
world.playSound(null, pos, SoundEvents.ITEM_PICKUP, SoundSource.BLOCKS, .25f, .75f);
if (recipe instanceof SandPaperPolishingRecipe)
AllSoundEvents.SANDING_SHORT.playOnServer(world, pos, .35f, 1f);
deployerTileEntity.sendData();
}
Aggregations