Search in sources :

Example 6 with SimpleInventory

use of net.minecraft.inventory.SimpleInventory in project CopperEquipment by Redy1aye.

the class DryerBlockEntity method hasRecipe.

private static boolean hasRecipe(DryerBlockEntity entity) {
    World world = entity.world;
    SimpleInventory inventory = new SimpleInventory(entity.inventory.size());
    for (int i = 0; i < entity.inventory.size(); i++) {
        inventory.setStack(i, entity.getStack(i));
    }
    assert world != null;
    Optional<DryerRecipes> match = world.getRecipeManager().getFirstMatch(DryerRecipes.Type.INSTANCE, inventory, world);
    return match.isPresent() && canInsertAmountIntoOutputSlot(inventory) && canInsertItemIntoOutputSlot(inventory, match.get().getOutput());
}
Also used : World(net.minecraft.world.World) ServerWorld(net.minecraft.server.world.ServerWorld) SimpleInventory(net.minecraft.inventory.SimpleInventory)

Example 7 with SimpleInventory

use of net.minecraft.inventory.SimpleInventory in project Capybara-Fabricated by ZestyBlaze.

the class CapybaraEntity method interactMob.

@Override
public ActionResult interactMob(PlayerEntity player, Hand hand) {
    final ItemStack stack = player.getStackInHand(hand);
    if (player.isSneaking()) {
        if (stack.getItem() == Blocks.CHEST.asItem()) {
            if (inventory == null || inventory.size() < 27) {
                inventory = new SimpleInventory(27);
                dataTracker.set(CHESTS, 1);
                if (!player.getAbilities().creativeMode) {
                    stack.decrement(1);
                }
                return ActionResult.SUCCESS;
            } else if (inventory.size() < 54) {
                Inventory inv = new SimpleInventory(54);
                for (int i = 0; i < 27; i++) {
                    inv.setStack(i, inventory.getStack(i));
                }
                inventory = inv;
                dataTracker.set(CHESTS, 2);
                if (!player.getAbilities().creativeMode) {
                    stack.decrement(1);
                }
                return ActionResult.SUCCESS;
            }
        }
        if (stack.getItem() == Items.STICK) {
            this.setSitting(!this.isSitting());
        } else {
            player.openHandledScreen(this);
            return ActionResult.SUCCESS;
        }
    } else if (TEMPT_ITEMS.get().contains(stack.getItem()) && !isTamed()) {
        if (this.random.nextInt(3) == 0) {
            this.setOwner(player);
            this.navigation.stop();
            this.setTarget(null);
            this.setSitting(true);
            this.world.sendEntityStatus(this, (byte) 7);
        }
        if (!player.getAbilities().creativeMode) {
            stack.decrement(1);
        } else {
            this.world.sendEntityStatus(this, (byte) 6);
        }
        return ActionResult.SUCCESS;
    } else if (!this.hasPassengers() && !player.shouldCancelInteraction() && !this.isBaby() && !isInSittingPose()) {
        boolean flag = this.isBreedingItem(player.getStackInHand(hand));
        if (!flag && !this.hasPassengers() && !player.shouldCancelInteraction()) {
            if (!this.world.isClient) {
                player.startRiding(this);
            }
            return ActionResult.SUCCESS;
        }
    } else if (!this.getPassengerList().isEmpty()) {
        removeAllPassengers();
    }
    return super.interactMob(player, hand);
}
Also used : ItemStack(net.minecraft.item.ItemStack) SimpleInventory(net.minecraft.inventory.SimpleInventory) Inventory(net.minecraft.inventory.Inventory) SimpleInventory(net.minecraft.inventory.SimpleInventory) PlayerInventory(net.minecraft.entity.player.PlayerInventory)

Example 8 with SimpleInventory

use of net.minecraft.inventory.SimpleInventory in project Capybara-Fabricated by ZestyBlaze.

the class CapybaraEntity method readCustomDataFromNbt.

@Override
public void readCustomDataFromNbt(NbtCompound nbt) {
    super.readCustomDataFromNbt(nbt);
    if (nbt.contains("Inventory")) {
        final NbtList inv = nbt.getList("Inventory", 10);
        inventory = new SimpleInventory(inv.size());
        for (int i = 0; i < inv.size(); i++) {
            inventory.setStack(i, ItemStack.fromNbt(inv.getCompound(i)));
        }
        dataTracker.set(CHESTS, inv.size() > 27 ? 2 : 1);
    }
}
Also used : NbtList(net.minecraft.nbt.NbtList) SimpleInventory(net.minecraft.inventory.SimpleInventory)

Example 9 with SimpleInventory

use of net.minecraft.inventory.SimpleInventory in project alaskanativecraft by Platymemo.

the class DryingRackBlockEntity method updateItemsBeingDried.

@SuppressWarnings("unused")
public static void updateItemsBeingDried(World world, BlockPos pos, BlockState state, @NotNull DryingRackBlockEntity dryingRackBlockEntity) {
    for (int i = 0; i < dryingRackBlockEntity.itemsBeingDried.size(); ++i) {
        ItemStack itemStack = dryingRackBlockEntity.itemsBeingDried.get(i);
        if (!itemStack.isEmpty()) {
            dryingRackBlockEntity.dryingTimes[i]++;
            if (dryingRackBlockEntity.dryingTimes[i] >= dryingRackBlockEntity.dryingTotalTimes[i]) {
                // Don't want it to keep counting up unnecessarily high
                dryingRackBlockEntity.dryingTimes[i] = dryingRackBlockEntity.dryingTotalTimes[i];
                Inventory inventory = new SimpleInventory(itemStack);
                ItemStack itemStack2 = world.getRecipeManager().getFirstMatch(AlaskaRecipes.DRYING, inventory, world).map((dryingRecipe) -> dryingRecipe.craft(inventory)).orElse(itemStack);
                dryingRackBlockEntity.itemsBeingDried.set(i, itemStack2);
                dryingRackBlockEntity.updateListeners();
            }
        }
    }
}
Also used : Packet(net.minecraft.network.Packet) BlockEntity(net.minecraft.block.entity.BlockEntity) World(net.minecraft.world.World) DryingRecipe(com.github.platymemo.alaskanativecraft.recipe.DryingRecipe) Inventory(net.minecraft.inventory.Inventory) AlaskaBlocks(com.github.platymemo.alaskanativecraft.block.AlaskaBlocks) SimpleInventory(net.minecraft.inventory.SimpleInventory) BlockPos(net.minecraft.util.math.BlockPos) DefaultedList(net.minecraft.util.collection.DefaultedList) AlaskaRecipes(com.github.platymemo.alaskanativecraft.recipe.AlaskaRecipes) BlockEntityUpdateS2CPacket(net.minecraft.network.packet.s2c.play.BlockEntityUpdateS2CPacket) ItemStack(net.minecraft.item.ItemStack) NbtCompound(net.minecraft.nbt.NbtCompound) Nullable(org.jetbrains.annotations.Nullable) ClientPlayPacketListener(net.minecraft.network.listener.ClientPlayPacketListener) MathHelper(net.minecraft.util.math.MathHelper) Inventories(net.minecraft.inventory.Inventories) Optional(java.util.Optional) BlockState(net.minecraft.block.BlockState) NotNull(org.jetbrains.annotations.NotNull) Clearable(net.minecraft.util.Clearable) ItemScatterer(net.minecraft.util.ItemScatterer) ItemStack(net.minecraft.item.ItemStack) Inventory(net.minecraft.inventory.Inventory) SimpleInventory(net.minecraft.inventory.SimpleInventory) SimpleInventory(net.minecraft.inventory.SimpleInventory)

Example 10 with SimpleInventory

use of net.minecraft.inventory.SimpleInventory in project Fabric-Course-118 by Kaupenjoe.

the class OrichalcumBlasterEntity method hasRecipe.

private static boolean hasRecipe(OrichalcumBlasterEntity entity) {
    World world = entity.world;
    SimpleInventory inventory = new SimpleInventory(entity.inventory.size());
    for (int i = 0; i < entity.inventory.size(); i++) {
        inventory.setStack(i, entity.getStack(i));
    }
    Optional<OrichalcumBlasterRecipe> match = world.getRecipeManager().getFirstMatch(OrichalcumBlasterRecipe.Type.INSTANCE, inventory, world);
    return match.isPresent() && canInsertAmountIntoOutputSlot(inventory) && canInsertItemIntoOutputSlot(inventory, match.get().getOutput());
}
Also used : OrichalcumBlasterRecipe(net.kaupenjoe.mccourse.recipe.OrichalcumBlasterRecipe) World(net.minecraft.world.World) SimpleInventory(net.minecraft.inventory.SimpleInventory)

Aggregations

SimpleInventory (net.minecraft.inventory.SimpleInventory)22 ItemStack (net.minecraft.item.ItemStack)14 World (net.minecraft.world.World)13 Inventory (net.minecraft.inventory.Inventory)5 NbtCompound (net.minecraft.nbt.NbtCompound)3 CirtictForgeRecipe (net.DakotaPride.moreweaponry.recipe.CirtictForgeRecipe)2 CoreForgeRecipe (net.DakotaPride.moreweaponry.recipe.CoreForgeRecipe)2 EssenceTranslatorRecipe (net.DakotaPride.moreweaponry.recipe.EssenceTranslatorRecipe)2 OrichalcumBlasterRecipe (net.kaupenjoe.mccourse.recipe.OrichalcumBlasterRecipe)2 MythrilBlasterRecipe (net.kaupenjoe.tutorialmod.recipe.MythrilBlasterRecipe)2 Entity (net.minecraft.entity.Entity)2 PlayerInventory (net.minecraft.entity.player.PlayerInventory)2 BlockItem (net.minecraft.item.BlockItem)2 NbtList (net.minecraft.nbt.NbtList)2 GenericContainerScreenHandler (net.minecraft.screen.GenericContainerScreenHandler)2 SimpleNamedScreenHandlerFactory (net.minecraft.screen.SimpleNamedScreenHandlerFactory)2 ServerWorld (net.minecraft.server.world.ServerWorld)2 CuttingRecipe (com.everlastsino.cate.recipe.recipes.CuttingRecipe)1 AlaskaBlocks (com.github.platymemo.alaskanativecraft.block.AlaskaBlocks)1 AlaskaRecipes (com.github.platymemo.alaskanativecraft.recipe.AlaskaRecipes)1