Search in sources :

Example 1 with CraftingRecipe

use of net.minecraft.world.item.crafting.CraftingRecipe in project Polymorph by TheIllusiveC4.

the class TomsStorageModule method selectRecipe.

@Override
public boolean selectRecipe(BlockEntity tileEntity, Recipe<?> recipe) {
    if (recipe instanceof CraftingRecipe && tileEntity instanceof TileEntityCraftingTerminal) {
        AccessorTileEntityCraftingTerminal te = (AccessorTileEntityCraftingTerminal) tileEntity;
        te.setCurrentRecipe((CraftingRecipe) recipe);
        te.callOnCraftingMatrixChanged();
        return true;
    }
    return false;
}
Also used : AccessorTileEntityCraftingTerminal(top.theillusivec4.polymorph.mixin.integration.toms_storage.AccessorTileEntityCraftingTerminal) TileEntityCraftingTerminal(com.tom.storagemod.tile.TileEntityCraftingTerminal) CraftingRecipe(net.minecraft.world.item.crafting.CraftingRecipe) AccessorTileEntityCraftingTerminal(top.theillusivec4.polymorph.mixin.integration.toms_storage.AccessorTileEntityCraftingTerminal)

Example 2 with CraftingRecipe

use of net.minecraft.world.item.crafting.CraftingRecipe in project improved-stations by shedaniel.

the class CraftingStationMenu method updateResult.

protected void updateResult(AbstractContainerMenu menu, Level level, Player player, CraftingContainer craftingInventory, ResultContainer resultInventory) {
    if (!level.isClientSide) {
        ServerPlayer serverPlayerEntity = (ServerPlayer) player;
        ItemStack itemStack = ItemStack.EMPTY;
        Optional<CraftingRecipe> optional = Objects.requireNonNull(level.getServer()).getRecipeManager().getRecipeFor(RecipeType.CRAFTING, craftingInventory, level);
        if (optional.isPresent()) {
            CraftingRecipe craftingRecipe = optional.get();
            if (resultInventory.setRecipeUsed(level, serverPlayerEntity, craftingRecipe)) {
                itemStack = craftingRecipe.assemble(craftingInventory);
            }
        }
        resultInventory.setItem(0, itemStack);
        menu.setRemoteSlot(0, itemStack);
        serverPlayerEntity.connection.send(new ClientboundContainerSetSlotPacket(menu.containerId, menu.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)

Example 3 with CraftingRecipe

use of net.minecraft.world.item.crafting.CraftingRecipe in project excavated_variants by lukebemish.

the class JeiCompat method registerRecipes.

@Override
public void registerRecipes(@NotNull IRecipeRegistration registration) {
    if (ExcavatedVariants.getConfig().add_conversion_recipes && ExcavatedVariants.getConfig().jei_rei_compat) {
        List<CraftingRecipe> recipes = new ArrayList<>();
        OreConversionRecipe.assembleOrNull();
        for (Pair<BaseOre, HashSet<BaseStone>> p : ExcavatedVariants.oreStoneList) {
            ArrayList<Item> items = new ArrayList<>();
            for (BaseStone stone : p.last()) {
                ResourceLocation rl = new ResourceLocation(ExcavatedVariants.MOD_ID, stone.id + "_" + p.first().id);
                Item item = Services.REGISTRY_UTIL.getItemById(rl);
                if (item != null) {
                    items.add(item);
                }
            }
            Item outItem = Services.REGISTRY_UTIL.getItemById(p.first().block_id.get(0));
            if (items.size() > 0 && outItem != null) {
                Ingredient input = Ingredient.of(items.stream().map(ItemStack::new));
                ItemStack output = new ItemStack(outItem);
                NonNullList<Ingredient> inputs = NonNullList.of(Ingredient.EMPTY, input);
                String ore_id = p.first().id;
                recipes.add(new ShapelessRecipe(new ResourceLocation(ExcavatedVariants.MOD_ID, ore_id + "_conversion"), "excavated_variants.ore_conversion", output, inputs));
            }
        }
        registration.addRecipes(RecipeTypes.CRAFTING, recipes);
    }
}
Also used : ArrayList(java.util.ArrayList) CraftingRecipe(net.minecraft.world.item.crafting.CraftingRecipe) BaseStone(io.github.lukebemish.excavated_variants.data.BaseStone) Item(net.minecraft.world.item.Item) BaseOre(io.github.lukebemish.excavated_variants.data.BaseOre) Ingredient(net.minecraft.world.item.crafting.Ingredient) ResourceLocation(net.minecraft.resources.ResourceLocation) ShapelessRecipe(net.minecraft.world.item.crafting.ShapelessRecipe) ItemStack(net.minecraft.world.item.ItemStack) HashSet(java.util.HashSet)

Example 4 with CraftingRecipe

use of net.minecraft.world.item.crafting.CraftingRecipe in project EvilCraft by CyclopsMC.

the class ContainerExaltedCrafter method slotsChanged.

@Override
public void slotsChanged(Container inventory) {
    if (initialized && !this.world.isClientSide()) {
        ItemStack itemstack = ItemStack.EMPTY;
        // Slightly altered logic from Container#slotChangedCraftingGrid
        CraftingRecipe irecipe = world.getServer().getRecipeManager().getRecipeFor(RecipeType.CRAFTING, craftingGrid, world).orElse(null);
        if (irecipe != null && result.setRecipeUsed(world, (ServerPlayer) player, irecipe)) {
            itemstack = irecipe.assemble(craftingGrid);
        }
        result.setItem(0, itemstack);
        ((ServerPlayer) this.player).connection.send(new ClientboundContainerSetSlotPacket(this.containerId, getStateId(), 9, itemstack));
        craftingGrid.save();
    }
}
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 5 with CraftingRecipe

use of net.minecraft.world.item.crafting.CraftingRecipe in project Create by Creators-of-Create.

the class BlueprintEntity method interactAt.

@Override
public InteractionResult interactAt(Player player, Vec3 vec, InteractionHand hand) {
    if (player instanceof FakePlayer)
        return InteractionResult.PASS;
    boolean holdingWrench = AllItems.WRENCH.isIn(player.getItemInHand(hand));
    BlueprintSection section = getSectionAt(vec);
    ItemStackHandler items = section.getItems();
    if (!holdingWrench && !level.isClientSide && !items.getStackInSlot(9).isEmpty()) {
        IItemHandlerModifiable playerInv = new InvWrapper(player.getInventory());
        boolean firstPass = true;
        int amountCrafted = 0;
        ForgeHooks.setCraftingPlayer(player);
        Optional<CraftingRecipe> recipe = Optional.empty();
        do {
            Map<Integer, ItemStack> stacksTaken = new HashMap<>();
            Map<Integer, ItemStack> craftingGrid = new HashMap<>();
            boolean success = true;
            Search: for (int i = 0; i < 9; i++) {
                ItemStack requestedItem = items.getStackInSlot(i);
                if (requestedItem.isEmpty()) {
                    craftingGrid.put(i, ItemStack.EMPTY);
                    continue;
                }
                for (int slot = 0; slot < playerInv.getSlots(); slot++) {
                    if (!FilterItem.test(level, playerInv.getStackInSlot(slot), requestedItem))
                        continue;
                    ItemStack currentItem = playerInv.extractItem(slot, 1, false);
                    if (stacksTaken.containsKey(slot))
                        stacksTaken.get(slot).grow(1);
                    else
                        stacksTaken.put(slot, currentItem.copy());
                    craftingGrid.put(i, currentItem);
                    continue Search;
                }
                success = false;
                break;
            }
            if (success) {
                CraftingContainer craftingInventory = new BlueprintCraftingInventory(craftingGrid);
                if (!recipe.isPresent())
                    recipe = level.getRecipeManager().getRecipeFor(RecipeType.CRAFTING, craftingInventory, level);
                ItemStack result = recipe.filter(r -> r.matches(craftingInventory, level)).map(r -> r.assemble(craftingInventory)).orElse(ItemStack.EMPTY);
                if (result.isEmpty()) {
                    success = false;
                } else if (result.getCount() + amountCrafted > 64) {
                    success = false;
                } else {
                    amountCrafted += result.getCount();
                    result.onCraftedBy(player.level, player, 1);
                    ForgeEventFactory.firePlayerCraftingEvent(player, result, craftingInventory);
                    NonNullList<ItemStack> nonnulllist = level.getRecipeManager().getRemainingItemsFor(RecipeType.CRAFTING, craftingInventory, level);
                    if (firstPass)
                        level.playSound(null, player.blockPosition(), SoundEvents.ITEM_PICKUP, SoundSource.PLAYERS, .2f, 1f + Create.RANDOM.nextFloat());
                    player.getInventory().placeItemBackInInventory(result);
                    for (ItemStack itemStack : nonnulllist) player.getInventory().placeItemBackInInventory(itemStack);
                    firstPass = false;
                }
            }
            if (!success) {
                for (Entry<Integer, ItemStack> entry : stacksTaken.entrySet()) playerInv.insertItem(entry.getKey(), entry.getValue(), false);
                break;
            }
        } while (player.isShiftKeyDown());
        ForgeHooks.setCraftingPlayer(null);
        return InteractionResult.SUCCESS;
    }
    int i = section.index;
    if (!level.isClientSide && player instanceof ServerPlayer) {
        NetworkHooks.openGui((ServerPlayer) player, section, buf -> {
            buf.writeVarInt(getId());
            buf.writeVarInt(i);
        });
    }
    return InteractionResult.SUCCESS;
}
Also used : VecHelper(com.simibubi.create.foundation.utility.VecHelper) AABB(net.minecraft.world.phys.AABB) Direction(net.minecraft.core.Direction) ItemUseType(com.simibubi.create.content.schematics.ItemRequirement.ItemUseType) ForgeMod(net.minecraftforge.common.ForgeMod) Inventory(net.minecraft.world.entity.player.Inventory) Dist(net.minecraftforge.api.distmarker.Dist) Pose(net.minecraft.world.entity.Pose) Create(com.simibubi.create.Create) Map(java.util.Map) NonNullList(net.minecraft.core.NonNullList) IItemHandlerModifiable(net.minecraftforge.items.IItemHandlerModifiable) RecipeType(net.minecraft.world.item.crafting.RecipeType) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) HangingEntity(net.minecraft.world.entity.decoration.HangingEntity) GameRules(net.minecraft.world.level.GameRules) InteractionResult(net.minecraft.world.InteractionResult) IInteractionChecker(com.simibubi.create.foundation.utility.IInteractionChecker) Player(net.minecraft.world.entity.player.Player) CompoundTag(net.minecraft.nbt.CompoundTag) CraftingContainer(net.minecraft.world.inventory.CraftingContainer) Couple(com.simibubi.create.foundation.utility.Couple) BlockPos(net.minecraft.core.BlockPos) ItemStackHandler(net.minecraftforge.items.ItemStackHandler) Entry(java.util.Map.Entry) Optional(java.util.Optional) Packet(net.minecraft.network.protocol.Packet) MenuProvider(net.minecraft.world.MenuProvider) ItemStack(net.minecraft.world.item.ItemStack) Level(net.minecraft.world.level.Level) ISpecialEntityItemRequirement(com.simibubi.create.content.schematics.ISpecialEntityItemRequirement) NetworkHooks(net.minecraftforge.network.NetworkHooks) SoundSource(net.minecraft.sounds.SoundSource) ForgeHooks(net.minecraftforge.common.ForgeHooks) Tag(net.minecraft.nbt.Tag) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn) ForgeEventFactory(net.minecraftforge.event.ForgeEventFactory) EntityType(net.minecraft.world.entity.EntityType) FilterItem(com.simibubi.create.content.logistics.item.filter.FilterItem) AbstractContainerMenu(net.minecraft.world.inventory.AbstractContainerMenu) BlockState(net.minecraft.world.level.block.state.BlockState) HashMap(java.util.HashMap) FriendlyByteBuf(net.minecraft.network.FriendlyByteBuf) AllItems(com.simibubi.create.AllItems) Axis(net.minecraft.core.Direction.Axis) ServerPlayer(net.minecraft.server.level.ServerPlayer) InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) IEntityAdditionalSpawnData(net.minecraftforge.entity.IEntityAdditionalSpawnData) SoundEvents(net.minecraft.sounds.SoundEvents) AllEntityTypes(com.simibubi.create.AllEntityTypes) ItemRequirement(com.simibubi.create.content.schematics.ItemRequirement) Nullable(javax.annotation.Nullable) DiodeBlock(net.minecraft.world.level.block.DiodeBlock) Component(net.minecraft.network.chat.Component) CraftingRecipe(net.minecraft.world.item.crafting.CraftingRecipe) HitResult(net.minecraft.world.phys.HitResult) Validate(org.apache.commons.lang3.Validate) Entity(net.minecraft.world.entity.Entity) Vec3(net.minecraft.world.phys.Vec3) ISyncPersistentData(com.simibubi.create.foundation.networking.ISyncPersistentData) EntityDimensions(net.minecraft.world.entity.EntityDimensions) Block(net.minecraft.world.level.block.Block) InteractionHand(net.minecraft.world.InteractionHand) Mth(net.minecraft.util.Mth) FakePlayer(net.minecraftforge.common.util.FakePlayer) ItemStackHandler(net.minecraftforge.items.ItemStackHandler) HashMap(java.util.HashMap) CraftingRecipe(net.minecraft.world.item.crafting.CraftingRecipe) FakePlayer(net.minecraftforge.common.util.FakePlayer) IItemHandlerModifiable(net.minecraftforge.items.IItemHandlerModifiable) CraftingContainer(net.minecraft.world.inventory.CraftingContainer) NonNullList(net.minecraft.core.NonNullList) InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) ServerPlayer(net.minecraft.server.level.ServerPlayer) ItemStack(net.minecraft.world.item.ItemStack)

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