Search in sources :

Example 1 with Inventory

use of net.minecraft.inventory.Inventory in project Overloaded by CJ-MC-Mods.

the class EnergyInventoryBasedRecipeProcessor method processRecipeAndStoreOutput.

private ItemStack processRecipeAndStoreOutput(ItemStack stack, boolean simulate) {
    Inventory inventory = new Inventory(stack.copy());
    List<T> recipesForInput = getRecipe(inventory);
    if (recipesForInput.isEmpty()) {
        return inventory.getItem(0);
    }
    T recipe = recipesForInput.get(0);
    ItemStack result;
    while (!inventory.getItem(0).isEmpty() && !(result = recipe.assemble(inventory)).isEmpty()) {
        int energyCost = energyCostPerRecipeOperation(recipe);
        if (energyCost != this.extractEnergy(energyCost, true)) {
            break;
        }
        ItemStack outputLeftOvers = insertItem(output, result, true);
        if (!outputLeftOvers.isEmpty()) {
            break;
        }
        insertItem(output, result, simulate);
        this.extractEnergy(energyCost, simulate);
        int deduct = recipe.getIngredients().get(0).getItems()[0].getCount();
        inventory.getItem(0).shrink(deduct);
    }
    return inventory.getItem(0);
// NonNullList<ItemStack> leftOvers = recipe.getRemainingItems(inventory);
// 
// if (leftOvers.isEmpty() || leftOvers.stream().allMatch(ItemStack::isEmpty)) {
// return ItemStack.EMPTY;
// }
// if (leftOvers.size() > 1) {
// Overloaded.logger.warn(
// "Deleting Item due to to many recipe leftovers. Items: "
// + leftOvers.subList(1, leftOvers.size() - 1).stream()
// .map(ItemStack::toString)
// .collect(Collectors.joining(",")));
// }
// return leftOvers.get(0);
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT) ItemStack(net.minecraft.item.ItemStack) Inventory(net.minecraft.inventory.Inventory) IInventory(net.minecraft.inventory.IInventory)

Example 2 with Inventory

use of net.minecraft.inventory.Inventory in project nbt-crafting by Siphalor.

the class MixinBrewingSlotPotion method canInsert.

@Inject(method = "canInsert(Lnet/minecraft/item/ItemStack;)Z", at = @At("RETURN"), cancellable = true)
public void canInsert(ItemStack stack, CallbackInfoReturnable<Boolean> callbackInfoReturnable) {
    if (callbackInfoReturnable.getReturnValue() || matches(stack)) {
        callbackInfoReturnable.setReturnValue(true);
        return;
    }
    RecipeManagerAccessor recipeManager;
    if (inventory instanceof BrewingStandBlockEntity) {
        recipeManager = (RecipeManagerAccessor) ((BrewingStandBlockEntity) inventory).getWorld().getRecipeManager();
    } else if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {
        recipeManager = (RecipeManagerAccessor) NbtCraftingClient.getClientRecipeManager();
    } else {
        NbtCrafting.logError("Failed to get recipe manager in brewing stand container class!");
        return;
    }
    Map<Identifier, Recipe<Inventory>> recipes = recipeManager.callGetAllOfType(NbtCrafting.BREWING_RECIPE_TYPE);
    callbackInfoReturnable.setReturnValue(recipes.values().stream().anyMatch(recipe -> recipe instanceof BrewingRecipe && ((BrewingRecipe) recipe).getBase().test(stack)));
}
Also used : FabricLoader(net.fabricmc.loader.api.FabricLoader) BrewingStandBlockEntity(net.minecraft.block.entity.BrewingStandBlockEntity) NbtCraftingClient(de.siphalor.nbtcrafting.client.NbtCraftingClient) Inject(org.spongepowered.asm.mixin.injection.Inject) Slot(net.minecraft.container.Slot) Inventory(net.minecraft.inventory.Inventory) Recipe(net.minecraft.recipe.Recipe) BrewingRecipe(de.siphalor.nbtcrafting.recipe.BrewingRecipe) CallbackInfoReturnable(org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable) RecipeManagerAccessor(de.siphalor.nbtcrafting.mixin.RecipeManagerAccessor) ItemStack(net.minecraft.item.ItemStack) Mixin(org.spongepowered.asm.mixin.Mixin) Map(java.util.Map) EnvType(net.fabricmc.api.EnvType) Identifier(net.minecraft.util.Identifier) Shadow(org.spongepowered.asm.mixin.Shadow) NbtCrafting(de.siphalor.nbtcrafting.NbtCrafting) At(org.spongepowered.asm.mixin.injection.At) RecipeManagerAccessor(de.siphalor.nbtcrafting.mixin.RecipeManagerAccessor) Identifier(net.minecraft.util.Identifier) Recipe(net.minecraft.recipe.Recipe) BrewingRecipe(de.siphalor.nbtcrafting.recipe.BrewingRecipe) BrewingStandBlockEntity(net.minecraft.block.entity.BrewingStandBlockEntity) BrewingRecipe(de.siphalor.nbtcrafting.recipe.BrewingRecipe) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 3 with Inventory

use of net.minecraft.inventory.Inventory in project MasaGadget by plusls.

the class PcaSyncUtil method sync.

public static void sync(List<Box> boxes) {
    ClientWorld world = MinecraftClient.getInstance().world;
    if (world == null) {
        return;
    }
    PcaSyncUtil.lastUpdatePos = null;
    BlockPos lastUpdatePos = null;
    for (Box box : boxes) {
        BlockPos pos1 = box.getPos1();
        BlockPos pos2 = box.getPos2();
        if (pos1 == null || pos2 == null) {
            continue;
        }
        int maxX = Math.max(pos1.getX(), pos2.getX());
        int maxY = Math.max(pos1.getY(), pos2.getY());
        int maxZ = Math.max(pos1.getZ(), pos2.getZ());
        int minX = Math.min(pos1.getX(), pos2.getX());
        int minY = Math.min(pos1.getY(), pos2.getY());
        int minZ = Math.min(pos1.getZ(), pos2.getZ());
        // 参考 PositionUtils。createAABBFrom
        List<Entity> entities = world.getOtherEntities(null, PositionUtils.createAABB(minX, minY, minZ, maxX + 1, maxY + 1, maxZ + 1), EntityUtils.NOT_PLAYER);
        for (Entity entity : entities) {
            if (entity instanceof Inventory) {
                PcaSyncProtocol.syncEntity(entity.getId());
            }
        }
        for (int x = minX; x <= maxX; ++x) {
            for (int y = minY; y <= maxY; ++y) {
                for (int z = minZ; z <= maxZ; ++z) {
                    BlockPos pos = new BlockPos(x, y, z);
                    if (world.getBlockEntity(pos) != null) {
                        lastUpdatePos = pos;
                        PcaSyncProtocol.syncBlockEntity(pos);
                    }
                }
            }
        }
    }
    PcaSyncProtocol.cancelSyncBlockEntity();
    PcaSyncProtocol.cancelSyncEntity();
    PcaSyncUtil.lastUpdatePos = lastUpdatePos;
}
Also used : Entity(net.minecraft.entity.Entity) BlockPos(net.minecraft.util.math.BlockPos) Box(fi.dy.masa.litematica.selection.Box) ClientWorld(net.minecraft.client.world.ClientWorld) Inventory(net.minecraft.inventory.Inventory)

Example 4 with Inventory

use of net.minecraft.inventory.Inventory in project MasaGadget by plusls.

the class MixinRenderUtils method modifyInv.

@ModifyVariable(method = "renderInventoryOverlay", at = @At(value = "INVOKE", target = "Lfi/dy/masa/malilib/util/GuiUtils;getScaledWindowWidth()I", ordinal = 0, remap = false), ordinal = 0)
private static Inventory modifyInv(Inventory inv) {
    Inventory ret = inv;
    Entity traceEntity = TraceUtil.getTraceEntity();
    if (Configs.Tweakeroo.INVENTORY_PREVIEW_SUPPORT_SHULKER_BOX_ITEM_ENTITY.getBooleanValue() && ret == null && traceEntity instanceof ItemEntity) {
        ItemStack itemStack = ((ItemEntity) traceEntity).getStack();
        Item item = itemStack.getItem();
        NbtCompound invNbt = itemStack.getSubNbt("BlockEntityTag");
        DefaultedList<ItemStack> stacks = DefaultedList.ofSize(27, ItemStack.EMPTY);
        if (item instanceof BlockItem && ((BlockItem) item).getBlock() instanceof ShulkerBoxBlock) {
            ret = new SimpleInventory(27);
            if (invNbt != null) {
                Inventories.readNbt(invNbt, stacks);
            }
            for (int i = 0; i < 27; ++i) {
                ret.setStack(i, stacks.get(i));
            }
        }
    }
    return ret;
}
Also used : Entity(net.minecraft.entity.Entity) ItemEntity(net.minecraft.entity.ItemEntity) Item(net.minecraft.item.Item) BlockItem(net.minecraft.item.BlockItem) ItemEntity(net.minecraft.entity.ItemEntity) NbtCompound(net.minecraft.nbt.NbtCompound) ShulkerBoxBlock(net.minecraft.block.ShulkerBoxBlock) ItemStack(net.minecraft.item.ItemStack) BlockItem(net.minecraft.item.BlockItem) Inventory(net.minecraft.inventory.Inventory) SimpleInventory(net.minecraft.inventory.SimpleInventory) SimpleInventory(net.minecraft.inventory.SimpleInventory) ModifyVariable(org.spongepowered.asm.mixin.injection.ModifyVariable)

Example 5 with Inventory

use of net.minecraft.inventory.Inventory in project MasaGadget by plusls.

the class MixinWorldUtils method checkInventory.

@Inject(method = "handleEasyPlace", at = @At(value = "INVOKE", target = "Lfi/dy/masa/malilib/util/InfoUtils;showGuiOrInGameMessage(Lfi/dy/masa/malilib/gui/Message$MessageType;Ljava/lang/String;[Ljava/lang/Object;)V", ordinal = 0), cancellable = true)
private static void checkInventory(MinecraftClient mc, CallbackInfoReturnable<Boolean> cir) {
    if (!Configs.Litematica.BETTER_EASY_PLACE_MODE.getBooleanValue() || mc.world == null) {
        return;
    }
    HitResult trace = mc.crosshairTarget;
    if (trace != null && trace.getType() == HitResult.Type.BLOCK) {
        BlockHitResult blockHitResult = (BlockHitResult) trace;
        BlockPos pos = blockHitResult.getBlockPos();
        Block block = mc.world.getBlockState(pos).getBlock();
        if (block == Blocks.BEACON || mc.world.getBlockEntity(pos) instanceof Inventory) {
            cir.setReturnValue(false);
        }
    }
}
Also used : BlockHitResult(net.minecraft.util.hit.BlockHitResult) HitResult(net.minecraft.util.hit.HitResult) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) BlockHitResult(net.minecraft.util.hit.BlockHitResult) Inventory(net.minecraft.inventory.Inventory) Inject(org.spongepowered.asm.mixin.injection.Inject)

Aggregations

Inventory (net.minecraft.inventory.Inventory)29 ItemStack (net.minecraft.item.ItemStack)15 BlockPos (net.minecraft.util.math.BlockPos)5 IInventory (net.minecraft.inventory.IInventory)4 SimpleInventory (net.minecraft.inventory.SimpleInventory)4 GenericContainerScreenHandler (net.minecraft.screen.GenericContainerScreenHandler)4 BlockEntity (net.minecraft.block.entity.BlockEntity)3 Entity (net.minecraft.entity.Entity)3 NbtCompound (net.minecraft.nbt.NbtCompound)3 Recipe (net.minecraft.recipe.Recipe)3 ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)3 Identifier (net.minecraft.util.Identifier)3 NbtCrafting (de.siphalor.nbtcrafting.NbtCrafting)2 NbtCraftingClient (de.siphalor.nbtcrafting.client.NbtCraftingClient)2 RecipeManagerAccessor (de.siphalor.nbtcrafting.mixin.RecipeManagerAccessor)2 BrewingRecipe (de.siphalor.nbtcrafting.recipe.BrewingRecipe)2 List (java.util.List)2 Optional (java.util.Optional)2 Set (java.util.Set)2 SortedSet (java.util.SortedSet)2