Search in sources :

Example 6 with CraftingRecipe

use of net.minecraft.world.item.crafting.CraftingRecipe in project BCLib by paulevsGitch.

the class GridRecipe method build.

public void build() {
    if (!exist) {
        return;
    }
    int height = shape.length;
    int width = shape[0].length();
    ItemStack result = new ItemStack(output, count);
    NonNullList<Ingredient> materials = this.getMaterials(width, height);
    CraftingRecipe recipe = shaped ? new ShapedRecipe(id, group, width, height, materials, result) : new ShapelessRecipe(id, group, result, materials);
    BCLRecipeManager.addRecipe(type, recipe);
}
Also used : Ingredient(net.minecraft.world.item.crafting.Ingredient) ShapedRecipe(net.minecraft.world.item.crafting.ShapedRecipe) ShapelessRecipe(net.minecraft.world.item.crafting.ShapelessRecipe) CraftingRecipe(net.minecraft.world.item.crafting.CraftingRecipe) ItemStack(net.minecraft.world.item.ItemStack)

Example 7 with CraftingRecipe

use of net.minecraft.world.item.crafting.CraftingRecipe in project Cyclic by Lothrazar.

the class ContainerWorkbench method updateCraftingResult.

protected static void updateCraftingResult(int id, int stateId, Level world, Player player, CraftingContainer inventory, ResultContainer inventoryResult) {
    if (!world.isClientSide) {
        ServerPlayer sp = (ServerPlayer) player;
        ItemStack itemstack = ItemStack.EMPTY;
        Optional<CraftingRecipe> optional = world.getServer().getRecipeManager().getRecipeFor(RecipeType.CRAFTING, inventory, world);
        if (optional.isPresent()) {
            CraftingRecipe recipe = optional.get();
            if (inventoryResult.setRecipeUsed(world, sp, recipe)) {
                itemstack = recipe.assemble(inventory);
            }
        }
        inventoryResult.setItem(0, itemstack);
        sp.connection.send(new ClientboundContainerSetSlotPacket(id, stateId, 0, itemstack));
    }
}
Also used : ServerPlayer(net.minecraft.server.level.ServerPlayer) ClientboundContainerSetSlotPacket(net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket) CraftingRecipe(net.minecraft.world.item.crafting.CraftingRecipe) ItemStack(net.minecraft.world.item.ItemStack)

Example 8 with CraftingRecipe

use of net.minecraft.world.item.crafting.CraftingRecipe in project Cyclic by Lothrazar.

the class CraftingStickContainer method slotsChanged.

@Override
public void slotsChanged(Container inventory) {
    Level world = playerInventory.player.level;
    if (!world.isClientSide) {
        ServerPlayer player = (ServerPlayer) playerInventory.player;
        ItemStack itemstack = ItemStack.EMPTY;
        Optional<CraftingRecipe> optional = world.getServer().getRecipeManager().getRecipeFor(RecipeType.CRAFTING, craftMatrix, world);
        if (optional.isPresent()) {
            CraftingRecipe icraftingrecipe = optional.get();
            if (craftResult.setRecipeUsed(world, player, icraftingrecipe)) {
                itemstack = icraftingrecipe.assemble(craftMatrix);
            }
        }
        craftResult.setItem(0, itemstack);
        player.connection.send(new ClientboundContainerSetSlotPacket(containerId, this.getStateId(), 0, itemstack));
    }
}
Also used : ServerPlayer(net.minecraft.server.level.ServerPlayer) ClientboundContainerSetSlotPacket(net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket) Level(net.minecraft.world.level.Level) CraftingRecipe(net.minecraft.world.item.crafting.CraftingRecipe) ItemStack(net.minecraft.world.item.ItemStack)

Example 9 with CraftingRecipe

use of net.minecraft.world.item.crafting.CraftingRecipe in project The-Aether by Gilded-Games.

the class AccessoriesContainer method slotsChanged.

@Override
public void slotsChanged(@Nonnull Container inventoryIn) {
    if (!this.player.level.isClientSide) {
        ServerPlayer playerMP = (ServerPlayer) this.player;
        ItemStack itemStack = ItemStack.EMPTY;
        MinecraftServer server = this.player.level.getServer();
        if (server == null) {
            return;
        }
        Optional<CraftingRecipe> recipe = server.getRecipeManager().getRecipeFor(RecipeType.CRAFTING, this.craftMatrix, this.player.level);
        if (recipe.isPresent()) {
            CraftingRecipe craftingRecipe = recipe.get();
            if (this.craftResult.setRecipeUsed(this.player.level, playerMP, craftingRecipe)) {
                itemStack = craftingRecipe.assemble(this.craftMatrix);
            }
        }
        this.craftResult.setItem(0, itemStack);
        this.setRemoteSlot(0, itemStack);
        playerMP.connection.send(new ClientboundContainerSetSlotPacket(this.containerId, this.incrementStateId(), 0, itemStack));
    }
}
Also used : ServerPlayer(net.minecraft.server.level.ServerPlayer) ClientboundContainerSetSlotPacket(net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket) CraftingRecipe(net.minecraft.world.item.crafting.CraftingRecipe) ItemStack(net.minecraft.world.item.ItemStack) MinecraftServer(net.minecraft.server.MinecraftServer)

Example 10 with CraftingRecipe

use of net.minecraft.world.item.crafting.CraftingRecipe in project LaserIO by Direwolf20-MC.

the class JEIIntegration method onRuntimeAvailable.

@Override
public void onRuntimeAvailable(IJeiRuntime jeiRuntime) {
    IRecipeManager recipeRegistry = jeiRuntime.getRecipeManager();
    RecipeManager recipeManager = Minecraft.getInstance().level.getRecipeManager();
    List<CraftingRecipe> hiddenRecipes = new ArrayList<>();
    hiddenRecipes.add((CraftingRecipe) recipeManager.byKey(new ResourceLocation(Registration.Card_Item.getId() + "_nbtclear")).get());
    hiddenRecipes.add((CraftingRecipe) recipeManager.byKey(new ResourceLocation(Registration.Filter_Basic.getId() + "_nbtclear")).get());
    hiddenRecipes.add((CraftingRecipe) recipeManager.byKey(new ResourceLocation(Registration.Filter_Count.getId() + "_nbtclear")).get());
    hiddenRecipes.add((CraftingRecipe) recipeManager.byKey(new ResourceLocation(Registration.Filter_Tag.getId() + "_nbtclear")).get());
    hiddenRecipes.add((CraftingRecipe) recipeManager.byKey(new ResourceLocation(Registration.Filter_Mod.getId() + "_nbtclear")).get());
    recipeRegistry.hideRecipes(RecipeTypes.CRAFTING, hiddenRecipes);
}
Also used : IRecipeManager(mezz.jei.api.recipe.IRecipeManager) ResourceLocation(net.minecraft.resources.ResourceLocation) IRecipeManager(mezz.jei.api.recipe.IRecipeManager) RecipeManager(net.minecraft.world.item.crafting.RecipeManager) ArrayList(java.util.ArrayList) CraftingRecipe(net.minecraft.world.item.crafting.CraftingRecipe)

Aggregations

CraftingRecipe (net.minecraft.world.item.crafting.CraftingRecipe)25 ItemStack (net.minecraft.world.item.ItemStack)22 ServerPlayer (net.minecraft.server.level.ServerPlayer)10 ClientboundContainerSetSlotPacket (net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket)9 Ingredient (net.minecraft.world.item.crafting.Ingredient)7 NonNullList (net.minecraft.core.NonNullList)4 ResourceLocation (net.minecraft.resources.ResourceLocation)4 CraftingContainer (net.minecraft.world.inventory.CraftingContainer)4 Item (net.minecraft.world.item.Item)4 ShapelessRecipe (net.minecraft.world.item.crafting.ShapelessRecipe)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 RecipeManager (net.minecraft.world.item.crafting.RecipeManager)3 AllItems (com.simibubi.create.AllItems)2 Create (com.simibubi.create.Create)2 FilterItem (com.simibubi.create.content.logistics.item.filter.FilterItem)2 Arrays (java.util.Arrays)2 List (java.util.List)2 ItemTags (net.minecraft.tags.ItemTags)2