Jump to content

Recommended Posts

Posted (edited)

I am trying to make a custom crafting table with only my custom recipes.

I don't think I have the best way of going about it, but it seems to work, except when I place an item in the first slot in the crafting matrix (index 1), it appears in the output slot (index 0), also I cannot figure out how to stop players from putting items in the output slot.

Also, do I have to manually listen for the GUI render event and cancel the rendering of the hotbar, health, etc...

Current code:

public class CulinaryWorkbenchContainer extends Container {
    private CulinaryWorkbenchRecipe recipe;
    private World world;
    private BlockPos table;
    private InventoryCrafting matrix;
    private InventoryCraftResult result;
    private EntityPlayer player;
    private Boolean closed = true;

    CulinaryWorkbenchContainer(InventoryPlayer playerInventory, World world, BlockPos table) {
        world = world;
        table = table;
        matrix = new InventoryCrafting(this, 3, 3);
        player = playerInventory.player;

        result = new InventoryCraftResult();

        addSlotToContainer(new Slot(matrix, 0, 124, 35));
        for (int i = 0; i < 3; i++) {
            for (int j = 1; j < 4; j++) {
                addSlotToContainer(new Slot(matrix, (j - 1) + i * 3, 30 + (j - 1) * 18, 17 + i * 18));
            }
        }

        for (int k = 0; k < 3; k++) {
            for (int i = 1; i < 10; i++) {
                addSlotToContainer(new Slot(playerInventory, (i - 1) + k * 9 + 9, 8 + (i - 1) * 18, 84 + k * 18));
            }
        }

        for (int i = 1; i < 10; i++) {
            addSlotToContainer(new Slot(playerInventory, i - 1, 8 + (i - 1) * 18, 142));
        }
    }

    @Override
    public boolean canInteractWith(EntityPlayer playerIn) {
        BlockPos pos = playerIn.rayTrace(6, 1.0f).getBlockPos();
        World world = playerIn.getEntityWorld();
        Block block = world.getBlockState(pos).getBlock();
        Boolean equals = block.equals(BlockRegistry.blocks[0]);
        double distance = playerIn.getDistanceSq(pos);
        Boolean equals2 = distance <= 8 * 8;
        return equals && equals2;
    }

    @Override
    public void onContainerClosed(EntityPlayer playerIn) {
        super.onContainerClosed(playerIn);

        if (!world.isRemote) {
            for (int i = 0; i < 9; ++i) {
                ItemStack itemstack = matrix.removeStackFromSlot(i);

                if (!itemstack.isEmpty()) {
                    playerIn.dropItem(itemstack, false);
                }
            }
        }
    }

    @Override
    public ItemStack transferStackInSlot(EntityPlayer playerIn, int index) {
        ItemStack itemstack = ItemStack.EMPTY;
        Slot slot = inventorySlots.get(index);

        if (slot != null && slot.getHasStack()) {
            ItemStack currentItem = slot.getStack();
            itemstack = currentItem.copy();

            if (index == 0) {
                if (!getSlot(0).equals(ItemStack.EMPTY)) {
                    currentItem.getItem().onCreated(currentItem, world, playerIn);
                    onPickupFromSlot(recipe);
                    slot.onSlotChange(currentItem, itemstack);
                }
            } else if (index >= 11 && index < 38) {
                if (!mergeItemStack(currentItem, 37, 46, false)) {
                    return ItemStack.EMPTY;
                }
            } else if (index >= 38 && index < 46) {
                if (!mergeItemStack(currentItem, 10, 37, false)) {
                    return ItemStack.EMPTY;
                }
                if (recipe != null)
                    putStackInSlot(0, recipe.output);
            } else if (!mergeItemStack(currentItem, 10, 46, false)) {
                return ItemStack.EMPTY;
            }

            if (currentItem.isEmpty()) {
                slot.putStack(ItemStack.EMPTY);
            } else {
                slot.onSlotChanged();
            }

            if (currentItem.getCount() == itemstack.getCount()) {
                return ItemStack.EMPTY;
            }
            slot.onTake(playerIn, currentItem);
            if (index == 0) {
                playerIn.dropItem(currentItem, false);
            }
        }

        return itemstack;
    }

    @Override
    public boolean canMergeSlot(ItemStack stack, Slot slotIn) {
        return slotIn.slotNumber != 0 && super.canMergeSlot(stack, slotIn);
    }

    @Override
    public void onCraftMatrixChanged(IInventory in) {
        Boolean recipeFound = false;
        for (CulinaryWorkbenchRecipe recipe : CulinaryCraft.recipes) {
            boolean found = true;
            if (recipe.shaped) {
                for (int i = 0; i < 9; i++) {
                    for (ItemStack ingredient : OreDictionary.getOres(recipe.ingredients[i])) {
                        if (!found) break;
                        ItemStack item = matrix.getStackInSlot(i);
                        if (ingredient.getItem() != item.getItem()) found = false;
                        if (ingredient.getCount() > item.getCount()) found = false;
                    }
                    if (!found) break;
                }
            } else {
                for (String sIngredient : recipe.ingredients) {
                    int addedAmt = 0;
                    for (int i = 0; i < 9; i++) {
                        for (ItemStack ingredient : OreDictionary.getOres(sIngredient)) {
                            ItemStack item = matrix.getStackInSlot(i);
                            if (ingredient.getItem().equals(item.getItem()) && item.getCount() == ingredient.getCount()) {
                                addedAmt += 1;
                            }
                        }
                    }
                    if (addedAmt != recipe.ingredients.length) {
                        found = false;
                    }
                }
            }
            if (found) {
                recipeFound = true;
                result.setInventorySlotContents(0, recipe.output);
                recipe = recipe;
            }
        }
        if(!recipeFound) {
            recipe = null;
        }
    }

    private void onPickupFromSlot(CulinaryWorkbenchRecipe recipe) {
        for (int i = 0; i < matrix.getSizeInventory(); i++) {
            ItemStack currentItem = matrix.getStackInSlot(i);

            if (currentItem != null) {
                NonNullList<ItemStack> ores = OreDictionary.getOres(recipe.ingredients[i]);
                for (int i2 = 0; i < ores.size(); i++) {
                    if (matrix.getStackInSlot(i).getItem() == ores.get(i2).getItem()) {
                        matrix.decrStackSize(i, recipe.amounts[i2]);
                    }
                }
                if (currentItem.getItem().hasContainerItem(currentItem)) {
                    ItemStack containerItem = currentItem.getItem().getContainerItem(currentItem);

                    if (containerItem.isItemStackDamageable() && containerItem.getItemDamage() > containerItem.getMaxDamage()) {
                        MinecraftForge.EVENT_BUS.post(new PlayerDestroyItemEvent(player, containerItem, EnumHand.MAIN_HAND));
                        containerItem = null;
                    }

                    if (containerItem != null || !player.inventory.addItemStackToInventory(containerItem)) {
                        if (matrix.getStackInSlot(i) == null) {
                            matrix.setInventorySlotContents(i, containerItem);
                        } else {
                            player.dropItem(containerItem, false);
                        }
                    }
                }
            }
        }
    }
}

Recipe class:

public class CulinaryWorkbenchRecipe {

    public String[] ingredients;
    public int[] amounts;
    public ItemStack output;
    public Boolean shaped;

    public CulinaryWorkbenchRecipe(String[] ingredients, int[] amounts, ItemStack output, Boolean shaped) {
        this.ingredients = ingredients;
        this.output = output;
        this.amounts = amounts;
        this.shaped = shaped;
    }
}

I don't think much else is needed.

(I plan to add recipes to a list in my main class, and add shaped/shapeless ore dict. recipes. I know I can have a class extend IRecipe but I don't think I need to)

Edited by Big_Bad_E
Posted (edited)

Update: My problem was the output slot and the first slot both had an index of 0. I solved this by making an index variable and increasing it by 1 when I add a slot. Also, I made it to where I get the GUI's name from the lang, so yeah.

 

Edit: Also, to my problem of not letting people put items in the output slot, I just made an extension of Slot, and overrided isItemValid().

Edited by Big_Bad_E
Posted

This stuff got really painful for me (I was however trying to save the items to another inventory)

hope my code helps you

https://github.com/Cadiboo/WIPTech/blob/master/src/main/java/cadiboo/wiptech/inventory/ContainerAssemblyTable.java

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I am playing a modpack with the web displays mod and I tried it out and when I logged back into my world i decided to get rid of the display i placed to move it and it started playing the video from last session and crashed my game, when i tried to start the game again it said it could not start becasue it could not delete a debug file that has the link in it that is no longer being displayed but is trying to, here is the debug folder.   [0201/091808.660:WARNING:chrome_browser_cloud_management_controller.cc(88)] Could not create policy manager as CBCM is not enabled. [0201/091930.426:INFO:CONSOLE(0)] "Error with Permissions-Policy header: Unrecognized feature: 'ch-ua-form-factors'.", source:  (0) [0201/091932.869:WARNING:browser_info.cc(309)] Returning a speculative frame for 25769803781 [6,5] [0201/091933.290:INFO:CONSOLE(5047)] "LegacyDataMixin will be applied to all legacy elements. Set `_legacyUndefinedCheck: true` on element class to enable.", source:  [0201/091933.529:WARNING:browser_info.cc(309)] Returning a speculative frame for 25769803781 [6,5] [0201/091933.529:WARNING:browser_info.cc(309)] Returning a speculative frame for 25769803781 [6,5] [0201/091933.530:WARNING:browser_info.cc(309)] Returning a speculative frame for 25769803781 [6,5] [0201/091933.530:WARNING:browser_info.cc(309)] Returning a speculative frame for 25769803781 [6,5] [0201/091933.557:INFO:CONSOLE(0)] "Error with Permissions-Policy header: Unrecognized feature: 'ch-ua-form-factors'.", source:  (0) [0201/091934.376:WARNING:obfuscated_file_util.cc(1410)] Failed to get origin+type directory: { uri: filesystem:https://www.youtube.com/temporary/, storage key: { origin: https://www.youtube.com, top-level site: https://youtube.com, nonce: <null>, ancestor chain bit: Same-Site }, bucket id: 1 } error:-4 [0201/091935.216:INFO:CONSOLE(0)] "Error with Permissions-Policy header: Unrecognized feature: 'ch-ua-form-factors'.", source:  (0) [0201/091935.241:INFO:CONSOLE(7990)] "Blocked script execution in 'about:blank' because the document's frame is sandboxed and the 'allow-scripts' permission is not set.", source: https://www.youtube.com/s/desktop/3df27587/jsbin/desktop_polymer.vflset/desktop_polymer.js (7990) [0201/091936.766:WARNING:browser_info.cc(309)] Returning a speculative frame for 38654705669 [9,5] [0201/091936.767:WARNING:browser_info.cc(309)] Returning a speculative frame for 38654705669 [9,5] [0201/091936.767:WARNING:browser_info.cc(309)] Returning a speculative frame for 38654705669 [9,5] [0201/091936.767:WARNING:browser_info.cc(309)] Returning a speculative frame for 38654705669 [9,5] [0201/091937.243:INFO:CONSOLE(5047)] "LegacyDataMixin will be applied to all legacy elements. Set `_legacyUndefinedCheck: true` on element class to enable.", source: https://www.youtube.com/s/desktop/3df27587/jsbin/desktop_polymer.vflset/desktop_polymer.js (5047) [0201/091938.283:INFO:CONSOLE(7990)] "Blocked script execution in 'about:blank' because the document's frame is sandboxed and the 'allow-scripts' permission is not set.", source: https://www.youtube.com/s/desktop/3df27587/jsbin/desktop_polymer.vflset/desktop_polymer.js (7990) [0201/091939.496:WARNING:browser_info.cc(309)] Returning a speculative frame for 38654705669 [9,5] [0201/091953.165:WARNING:browser_info.cc(309)] Returning a speculative frame for 38654705676 [9,12] [0201/091953.165:WARNING:browser_info.cc(309)] Returning a speculative frame for 38654705676 [9,12] [0201/091953.166:WARNING:browser_info.cc(309)] Returning a speculative frame for 38654705676 [9,12] [0201/091953.166:WARNING:browser_info.cc(309)] Returning a speculative frame for 38654705676 [9,12] [0201/091959.119:INFO:CONSOLE(0)] "The resource https://rr5---sn-o097znsr.googlevideo.com/generate_204?conn2 was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it has an appropriate `as` value and it is preloaded intentionally.", source: https://www.youtube.com/watch?v=gaRSMacERUQ (0) [0201/091959.119:INFO:CONSOLE(0)] "The resource https://i.ytimg.com/generate_204 was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it has an appropriate `as` value and it is preloaded intentionally.", source: https://www.youtube.com/watch?v=gaRSMacERUQ (0) [0201/091959.119:INFO:CONSOLE(0)] "The resource https://rr5---sn-o097znsr.googlevideo.com/generate_204 was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it has an appropriate `as` value and it is preloaded intentionally.", source: https://www.youtube.com/watch?v=gaRSMacERUQ (0) [0201/092014.122:INFO:CONSOLE(0)] "The resource https://rr5---sn-o097znsr.googlevideo.com/generate_204?conn2 was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it has an appropriate `as` value and it is preloaded intentionally.", source: https://www.youtube.com/watch?v=gaRSMacERUQ (0) [0201/092014.122:INFO:CONSOLE(0)] "The resource https://i.ytimg.com/generate_204 was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it has an appropriate `as` value and it is preloaded intentionally.", source: https://www.youtube.com/watch?v=gaRSMacERUQ (0) [0201/092014.122:INFO:CONSOLE(0)] "The resource https://rr5---sn-o097znsr.googlevideo.com/generate_204 was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it has an appropriate `as` value and it is preloaded intentionally.", source: https://www.youtube.com/watch?v=gaRSMacERUQ (0) [0201/092019.126:INFO:CONSOLE(0)] "The resource https://rr5---sn-o097znsr.googlevideo.com/generate_204?conn2 was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it has an appropriate `as` value and it is preloaded intentionally.", source: https://www.youtube.com/watch?v=gaRSMacERUQ (0) [0201/092019.126:INFO:CONSOLE(0)] "The resource https://i.ytimg.com/generate_204 was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it has an appropriate `as` value and it is preloaded intentionally.", source: https://www.youtube.com/watch?v=gaRSMacERUQ (0) [0201/092019.126:INFO:CONSOLE(0)] "The resource https://rr5---sn-o097znsr.googlevideo.com/generate_204 was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it has an appropriate `as` value and it is preloaded intentionally.", source: https://www.youtube.com/watch?v=gaRSMacERUQ (0) [0201/092024.512:INFO:CONSOLE(0)] "The resource https://rr5---sn-o097znsr.googlevideo.com/generate_204?conn2 was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it has an appropriate `as` value and it is preloaded intentionally.", source: https://www.youtube.com/watch?v=gaRSMacERUQ (0) [0201/092024.512:INFO:CONSOLE(0)] "The resource https://i.ytimg.com/generate_204 was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it has an appropriate `as` value and it is preloaded intentionally.", source: https://www.youtube.com/watch?v=gaRSMacERUQ (0) [0201/092024.512:INFO:CONSOLE(0)] "The resource https://rr5---sn-o097znsr.googlevideo.com/generate_204 was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it has an appropriate `as` value and it is preloaded intentionally.", source: https://www.youtube.com/watch?v=gaRSMacERUQ (0) [0201/092029.812:INFO:CONSOLE(0)] "The resource https://rr5---sn-o097znsr.googlevideo.com/generate_204?conn2 was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it has an appropriate `as` value and it is preloaded intentionally.", source: https://www.youtube.com/watch?v=gaRSMacERUQ (0) [0201/092029.812:INFO:CONSOLE(0)] "The resource https://i.ytimg.com/generate_204 was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it has an appropriate `as` value and it is preloaded intentionally.", source: https://www.youtube.com/watch?v=gaRSMacERUQ (0) [0201/092029.812:INFO:CONSOLE(0)] "The resource https://rr5---sn-o097znsr.googlevideo.com/generate_204 was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it has an appropriate `as` value and it is preloaded intentionally.", source: https://www.youtube.com/watch?v=gaRSMacERUQ (0) [0201/092036.154:INFO:CONSOLE(0)] "The resource https://rr5---sn-o097znsr.googlevideo.com/generate_204?conn2 was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it has an appropriate `as` value and it is preloaded intentionally.", source: https://www.youtube.com/watch?v=gaRSMacERUQ (0) [0201/092036.165:INFO:CONSOLE(0)] "The resource https://i.ytimg.com/generate_204 was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it has an appropriate `as` value and it is preloaded intentionally.", source: https://www.youtube.com/watch?v=gaRSMacERUQ (0) [0201/092036.165:INFO:CONSOLE(0)] "The resource https://rr5---sn-o097znsr.googlevideo.com/generate_204 was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it has an appropriate `as` value and it is preloaded intentionally.", source: https://www.youtube.com/watch?v=gaRSMacERUQ (0) [0201/092041.464:INFO:CONSOLE(0)] "The resource https://rr5---sn-o097znsr.googlevideo.com/generate_204?conn2 was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it has an appropriate `as` value and it is preloaded intentionally.", source: https://www.youtube.com/watch?v=gaRSMacERUQ (0) [0201/092041.464:INFO:CONSOLE(0)] "The resource https://i.ytimg.com/generate_204 was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it has an appropriate `as` value and it is preloaded intentionally.", source: https://www.youtube.com/watch?v=gaRSMacERUQ (0) [0201/092041.464:INFO:CONSOLE(0)] "The resource https://rr5---sn-o097znsr.googlevideo.com/generate_204 was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it has an appropriate `as` value and it is preloaded intentionally.", source: https://www.youtube.com/watch?v=gaRSMacERUQ (0) [0201/092051.842:INFO:CONSOLE(0)] "The resource https://rr5---sn-o097znsr.googlevideo.com/generate_204?conn2 was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it has an appropriate `as` value and it is preloaded intentionally.", source: https://www.youtube.com/watch?v=gaRSMacERUQ (0) [0201/092051.843:INFO:CONSOLE(0)] "The resource https://i.ytimg.com/generate_204 was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it has an appropriate `as` value and it is preloaded intentionally.", source: https://www.youtube.com/watch?v=gaRSMacERUQ (0) [0201/092051.843:INFO:CONSOLE(0)] "The resource https://rr5---sn-o097znsr.googlevideo.com/generate_204 was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it has an appropriate `as` value and it is preloaded intentionally.", source: https://www.youtube.com/watch?v=gaRSMacERUQ (0) [0201/092055.373:INFO:CONSOLE(0)] "The resource https://rr5---sn-o097znsr.googlevideo.com/generate_204?conn2 was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it has an appropriate `as` value and it is preloaded intentionally.", source: https://www.youtube.com/watch?v=gaRSMacERUQ (0) [0201/092055.373:INFO:CONSOLE(0)] "The resource https://i.ytimg.com/generate_204 was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it has an appropriate `as` value and it is preloaded intentionally.", source: https://www.youtube.com/watch?v=gaRSMacERUQ (0) [0201/092055.373:INFO:CONSOLE(0)] "The resource https://rr5---sn-o097znsr.googlevideo.com/generate_204 was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it has an appropriate `as` value and it is preloaded intentionally.", source: https://www.youtube.com/watch?v=gaRSMacERUQ (0)
    • If you are searching for mods, I would not search here, this is more of a support forum for using/creating mods with minecraft Forge. Try https://www.curseforge.com/minecraft if you are looking for mods/modpacks to use.
    • I was trying to find a mod that added something specific, and was unable to find it with what limited memory I had of seeing it. I don't know why there isn't an option to include words in overviews of mods. I could see it being in the sort tab near filters on the app in my opinion. It might help someone trying to find something specific, only based off something from the overview tab, but idk
    • Please read the FAQ and post logs as described there.   Also, do not just add a post onto someone else's thread with your issue, create a new one please.
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.