Search in sources :

Example 11 with Inventory

use of net.minecraft.inventory.Inventory in project VariousOddities by Lyinginbedmon.

the class EntityWarg method initWargChest.

public void initWargChest() {
    Inventory inventory = this.wargChest;
    this.wargChest = new Inventory(getSizeInventory());
    if (inventory != null) {
        inventory.removeListener(this);
        int i = Math.min(inventory.getSizeInventory(), this.wargChest.getSizeInventory());
        for (int j = 0; j < i; ++j) {
            ItemStack stack = inventory.getStackInSlot(j);
            if (!stack.isEmpty())
                this.wargChest.setInventorySlotContents(j, stack.copy());
        }
    }
    this.wargChest.addListener(this);
}
Also used : ItemStack(net.minecraft.item.ItemStack) Inventory(net.minecraft.inventory.Inventory) IMountInventory(com.lying.variousoddities.entity.IMountInventory) IInventory(net.minecraft.inventory.IInventory)

Example 12 with Inventory

use of net.minecraft.inventory.Inventory in project FarmersDelight by vectorwing.

the class StoveBlock method use.

@Override
public ActionResultType use(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult hit) {
    ItemStack heldStack = player.getItemInHand(handIn);
    Item heldItem = heldStack.getItem();
    if (state.getValue(LIT)) {
        if (heldStack.getToolTypes().contains(ToolType.SHOVEL)) {
            extinguish(state, worldIn, pos);
            heldStack.hurtAndBreak(1, player, action -> action.broadcastBreakEvent(handIn));
            return ActionResultType.SUCCESS;
        } else if (heldItem == Items.WATER_BUCKET) {
            if (!worldIn.isClientSide()) {
                worldIn.playSound(null, pos, SoundEvents.GENERIC_EXTINGUISH_FIRE, SoundCategory.BLOCKS, 1.0F, 1.0F);
            }
            extinguish(state, worldIn, pos);
            if (!player.isCreative()) {
                player.setItemInHand(handIn, new ItemStack(Items.BUCKET));
            }
            return ActionResultType.SUCCESS;
        }
    } else {
        if (heldItem instanceof FlintAndSteelItem) {
            worldIn.playSound(player, pos, SoundEvents.FLINTANDSTEEL_USE, SoundCategory.BLOCKS, 1.0F, MathUtils.RAND.nextFloat() * 0.4F + 0.8F);
            worldIn.setBlock(pos, state.setValue(BlockStateProperties.LIT, Boolean.TRUE), 11);
            heldStack.hurtAndBreak(1, player, action -> action.broadcastBreakEvent(handIn));
            return ActionResultType.SUCCESS;
        } else if (heldItem instanceof FireChargeItem) {
            worldIn.playSound(null, pos, SoundEvents.FIRECHARGE_USE, SoundCategory.BLOCKS, 1.0F, (MathUtils.RAND.nextFloat() - MathUtils.RAND.nextFloat()) * 0.2F + 1.0F);
            worldIn.setBlock(pos, state.setValue(BlockStateProperties.LIT, Boolean.TRUE), 11);
            if (!player.isCreative()) {
                heldStack.shrink(1);
            }
            return ActionResultType.SUCCESS;
        }
    }
    TileEntity tileEntity = worldIn.getBlockEntity(pos);
    if (tileEntity instanceof StoveTileEntity) {
        StoveTileEntity stoveEntity = (StoveTileEntity) tileEntity;
        int stoveSlot = stoveEntity.getNextEmptySlot();
        if (stoveSlot < 0 || stoveEntity.isStoveBlockedAbove()) {
            return ActionResultType.PASS;
        }
        Optional<CampfireCookingRecipe> recipe = stoveEntity.getMatchingRecipe(new Inventory(heldStack), stoveSlot);
        if (recipe.isPresent()) {
            if (!worldIn.isClientSide && stoveEntity.addItem(player.abilities.instabuild ? heldStack.copy() : heldStack, recipe.get(), stoveSlot)) {
                return ActionResultType.SUCCESS;
            }
            return ActionResultType.CONSUME;
        }
    }
    return ActionResultType.PASS;
}
Also used : StoveTileEntity(vectorwing.farmersdelight.tile.StoveTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) Inventory(net.minecraft.inventory.Inventory) StoveTileEntity(vectorwing.farmersdelight.tile.StoveTileEntity) CampfireCookingRecipe(net.minecraft.item.crafting.CampfireCookingRecipe)

Example 13 with Inventory

use of net.minecraft.inventory.Inventory in project FarmersDelight by vectorwing.

the class SkilletTileEntity method addItemToCook.

public ItemStack addItemToCook(ItemStack addedStack, @Nullable PlayerEntity player) {
    Optional<CampfireCookingRecipe> recipe = getMatchingRecipe(new Inventory(addedStack));
    if (recipe.isPresent()) {
        cookingTimeTotal = SkilletBlock.getSkilletCookingTime(recipe.get().getCookingTime(), fireAspectLevel);
        boolean wasEmpty = getStoredStack().isEmpty();
        ItemStack remainderStack = inventory.insertItem(0, addedStack.copy(), false);
        if (!ItemStack.matches(remainderStack, addedStack)) {
            lastRecipeID = recipe.get().getId();
            cookingTime = 0;
            if (wasEmpty && level != null && isHeated(level, worldPosition)) {
                level.playSound(null, worldPosition.getX() + 0.5F, worldPosition.getY() + 0.5F, worldPosition.getZ() + 0.5F, ModSounds.BLOCK_SKILLET_ADD_FOOD.get(), SoundCategory.BLOCKS, 0.8F, 1.0F);
            }
            return remainderStack;
        }
    } else if (player != null) {
        player.displayClientMessage(TextUtils.getTranslation("block.skillet.invalid_item"), true);
    }
    return addedStack;
}
Also used : ItemStack(net.minecraft.item.ItemStack) Inventory(net.minecraft.inventory.Inventory) IInventory(net.minecraft.inventory.IInventory) CampfireCookingRecipe(net.minecraft.item.crafting.CampfireCookingRecipe)

Example 14 with Inventory

use of net.minecraft.inventory.Inventory in project FarmersDelight by vectorwing.

the class SkilletTileEntity method cookAndOutputItems.

private void cookAndOutputItems(ItemStack cookingStack) {
    if (level == null)
        return;
    ++cookingTime;
    if (cookingTime >= cookingTimeTotal) {
        Inventory wrapper = new Inventory(cookingStack);
        Optional<CampfireCookingRecipe> recipe = getMatchingRecipe(wrapper);
        if (recipe.isPresent()) {
            ItemStack resultStack = recipe.get().assemble(wrapper);
            Direction direction = getBlockState().getValue(SkilletBlock.FACING).getClockWise();
            ItemUtils.spawnItemEntity(level, resultStack.copy(), worldPosition.getX() + 0.5, worldPosition.getY() + 0.3, worldPosition.getZ() + 0.5, direction.getStepX() * 0.08F, 0.25F, direction.getStepZ() * 0.08F);
            cookingTime = 0;
            inventory.extractItem(0, 1, false);
        }
    }
}
Also used : ItemStack(net.minecraft.item.ItemStack) Direction(net.minecraft.util.Direction) Inventory(net.minecraft.inventory.Inventory) IInventory(net.minecraft.inventory.IInventory) CampfireCookingRecipe(net.minecraft.item.crafting.CampfireCookingRecipe)

Example 15 with Inventory

use of net.minecraft.inventory.Inventory in project FarmersDelight by vectorwing.

the class StoveTileEntity method cookAndOutputItems.

private void cookAndOutputItems() {
    if (level == null)
        return;
    boolean didInventoryChange = false;
    for (int i = 0; i < inventory.getSlots(); ++i) {
        ItemStack stoveStack = inventory.getStackInSlot(i);
        if (!stoveStack.isEmpty()) {
            ++cookingTimes[i];
            if (cookingTimes[i] >= cookingTimesTotal[i]) {
                IInventory inventoryWrapper = new Inventory(stoveStack);
                Optional<CampfireCookingRecipe> recipe = getMatchingRecipe(inventoryWrapper, i);
                if (recipe.isPresent()) {
                    ItemStack resultStack = recipe.get().getResultItem();
                    if (!resultStack.isEmpty()) {
                        ItemUtils.spawnItemEntity(level, resultStack.copy(), worldPosition.getX() + 0.5, worldPosition.getY() + 1.0, worldPosition.getZ() + 0.5, level.random.nextGaussian() * (double) 0.01F, 0.1F, level.random.nextGaussian() * (double) 0.01F);
                    }
                }
                inventory.setStackInSlot(i, ItemStack.EMPTY);
                didInventoryChange = true;
            }
        }
    }
    if (didInventoryChange) {
        inventoryChanged();
    }
}
Also used : IInventory(net.minecraft.inventory.IInventory) ItemStack(net.minecraft.item.ItemStack) Inventory(net.minecraft.inventory.Inventory) IInventory(net.minecraft.inventory.IInventory) CampfireCookingRecipe(net.minecraft.item.crafting.CampfireCookingRecipe)

Aggregations

Inventory (net.minecraft.inventory.Inventory)55 ItemStack (net.minecraft.item.ItemStack)36 IInventory (net.minecraft.inventory.IInventory)11 SimpleInventory (net.minecraft.inventory.SimpleInventory)10 PlayerEntity (net.minecraft.entity.player.PlayerEntity)7 PlayerInventory (net.minecraft.entity.player.PlayerInventory)7 BlockPos (net.minecraft.util.math.BlockPos)7 BlockEntity (net.minecraft.block.entity.BlockEntity)6 BlockState (net.minecraft.block.BlockState)5 CampfireCookingRecipe (net.minecraft.item.crafting.CampfireCookingRecipe)5 GenericContainerScreenHandler (net.minecraft.screen.GenericContainerScreenHandler)5 List (java.util.List)4 NbtCompound (net.minecraft.nbt.NbtCompound)4 ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)4 Identifier (net.minecraft.util.Identifier)4 World (net.minecraft.world.World)4 Optional (java.util.Optional)3 Entity (net.minecraft.entity.Entity)3 CompoundNBT (net.minecraft.nbt.CompoundNBT)3 Recipe (net.minecraft.recipe.Recipe)3