use of hellfirepvp.astralsorcery.common.util.tile.TileInventory in project AstralSorcery by HellFirePvP.
the class ActiveSimpleAltarRecipe method consumeInputs.
public void consumeInputs(TileAltar altar) {
TileInventory inv = altar.getInventory();
AltarRecipeGrid grid = this.recipeToCraft.getInputs();
for (int slot = 0; slot < AltarRecipeGrid.MAX_INVENTORY_SIZE; slot++) {
Ingredient input = grid.getIngredient(slot);
if (input instanceof FluidIngredient) {
ItemStack stack = inv.getStackInSlot(slot);
FluidActionResult far = FluidUtil.tryEmptyContainer(stack, VoidFluidHandler.INSTANCE, FluidAttributes.BUCKET_VOLUME, null, true);
if (far.isSuccess()) {
inv.setStackInSlot(slot, far.getResult());
}
} else {
ItemUtils.decrementItem(inv, slot, altar::dropItemOnTop);
}
}
for (CraftingFocusStack input : this.focusStacks) {
TileSpectralRelay tar = MiscUtils.getTileAt(altar.getWorld(), input.getRealPosition(), TileSpectralRelay.class, true);
if (tar != null) {
TileInventory tarInventory = tar.getInventory();
if (input.getInput() != null && input.getInput().getIngredient() instanceof FluidIngredient) {
ItemStack stack = tarInventory.getStackInSlot(0);
FluidActionResult far = FluidUtil.tryEmptyContainer(stack, VoidFluidHandler.INSTANCE, FluidAttributes.BUCKET_VOLUME, null, true);
if (far.isSuccess()) {
tarInventory.setStackInSlot(0, far.getResult());
}
} else {
ItemUtils.decrementItem(tarInventory, 0, altar::dropItemOnTop);
}
}
}
}
use of hellfirepvp.astralsorcery.common.util.tile.TileInventory in project AstralSorcery by HellFirePvP.
the class BlockSpectralRelay method onBlockActivated.
@Override
public ActionResultType onBlockActivated(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockRayTraceResult hit) {
if (!world.isRemote()) {
ItemStack held = player.getHeldItem(hand);
TileSpectralRelay tar = MiscUtils.getTileAt(world, pos, TileSpectralRelay.class, true);
if (tar != null) {
TileInventory inv = tar.getInventory();
if (!held.isEmpty()) {
if (!inv.getStackInSlot(0).isEmpty()) {
ItemStack stack = inv.getStackInSlot(0);
player.inventory.placeItemBackInInventory(world, stack);
inv.setStackInSlot(0, ItemStack.EMPTY);
tar.markForUpdate();
TileSpectralRelay.cascadeRelayProximityUpdates(world, pos);
}
if (!world.isAirBlock(pos.up())) {
return ActionResultType.PASS;
}
inv.setStackInSlot(0, ItemUtils.copyStackWithSize(held, 1));
world.playSound(null, pos.getX(), pos.getY(), pos.getZ(), SoundEvents.ENTITY_ITEM_PICKUP, SoundCategory.PLAYERS, 0.2F, ((world.rand.nextFloat() - world.rand.nextFloat()) * 0.7F + 1.0F) * 2.0F);
if (!player.isCreative()) {
held.shrink(1);
}
tar.updateAltarLinkState();
TileSpectralRelay.cascadeRelayProximityUpdates(world, pos);
tar.markForUpdate();
} else {
if (!inv.getStackInSlot(0).isEmpty()) {
ItemStack stack = inv.getStackInSlot(0);
player.inventory.placeItemBackInInventory(world, stack);
inv.setStackInSlot(0, ItemStack.EMPTY);
TileSpectralRelay.cascadeRelayProximityUpdates(world, pos);
tar.markForUpdate();
}
}
}
}
return ActionResultType.SUCCESS;
}
Aggregations