Search in sources :

Example 1 with TileInventory

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);
            }
        }
    }
}
Also used : FluidIngredient(hellfirepvp.astralsorcery.common.crafting.helper.ingredient.FluidIngredient) Ingredient(net.minecraft.item.crafting.Ingredient) WrappedIngredient(hellfirepvp.astralsorcery.common.crafting.helper.WrappedIngredient) FluidIngredient(hellfirepvp.astralsorcery.common.crafting.helper.ingredient.FluidIngredient) TileSpectralRelay(hellfirepvp.astralsorcery.common.tile.TileSpectralRelay) TileInventory(hellfirepvp.astralsorcery.common.util.tile.TileInventory) ItemStack(net.minecraft.item.ItemStack) FluidActionResult(net.minecraftforge.fluids.FluidActionResult) CraftingFocusStack(hellfirepvp.astralsorcery.common.crafting.helper.CraftingFocusStack)

Example 2 with TileInventory

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;
}
Also used : TileSpectralRelay(hellfirepvp.astralsorcery.common.tile.TileSpectralRelay) ItemStack(net.minecraft.item.ItemStack) TileInventory(hellfirepvp.astralsorcery.common.util.tile.TileInventory)

Aggregations

TileSpectralRelay (hellfirepvp.astralsorcery.common.tile.TileSpectralRelay)2 TileInventory (hellfirepvp.astralsorcery.common.util.tile.TileInventory)2 ItemStack (net.minecraft.item.ItemStack)2 CraftingFocusStack (hellfirepvp.astralsorcery.common.crafting.helper.CraftingFocusStack)1 WrappedIngredient (hellfirepvp.astralsorcery.common.crafting.helper.WrappedIngredient)1 FluidIngredient (hellfirepvp.astralsorcery.common.crafting.helper.ingredient.FluidIngredient)1 Ingredient (net.minecraft.item.crafting.Ingredient)1 FluidActionResult (net.minecraftforge.fluids.FluidActionResult)1