Jump to content

Recommended Posts

Posted

I've make a new block to craft something, but it has some problems.

When I take the result item, the number of material item doesn't appear to decrease. But if I take the material away, the number shows in right way.

For example, item A needs 3 item B and 2 item C to craft. When I take away A, number of B and C doesn't change.

When I close the block's gui and reopen it or take away B or C, the number decrease properly.

The code relevant to the problem is here:

public class WorkshopResultSlot extends Slot {

    private final IItemHandler field_75239_a;
    private final IInventory transferInv = new Inventory(3);
    private final PlayerEntity player;
    private int amountCrafted;
    public WorkshopRecipe workshopRecipe;
    public NonNullList<ItemStack> itemStacks = NonNullList.create();

    public WorkshopResultSlot(PlayerEntity player, IItemHandler craftingInventory, IInventory inventoryIn, int slotIndex, int xPosition, int yPosition) {
        super(inventoryIn, slotIndex, xPosition, yPosition);
        this.player = player;
        this.field_75239_a = craftingInventory;
        for(int i = 0; i < 3; i++){
            this.transferInv.setInventorySlotContents(i, this.field_75239_a.getStackInSlot(i));
        }
    }
  
  //other code...
  
    public ItemStack onTake(PlayerEntity thePlayer, ItemStack stack) {
        this.onCrafting(stack);
        net.minecraftforge.common.ForgeHooks.setCraftingPlayer(thePlayer);
        NonNullList<ItemStack> nonnulllist = thePlayer.world.getRecipeManager().getRecipeNonNull(IRecipeTypeArk.WORKSHOP, this.transferInv, thePlayer.world);
        net.minecraftforge.common.ForgeHooks.setCraftingPlayer(null);
        for (int i = 0; i < nonnulllist.size(); ++i) {
            ItemStack itemstack = this.field_75239_a.getStackInSlot(i);
            ItemStack itemstack1 = nonnulllist.get(i);
            int count = this.field_75239_a.getStackInSlot(i).getCount();
          //===============================
          //Belows is the problem code
          //===============================
            for(int j = 0; j < this.itemStacks.size(); ++j) {
                if (!itemstack.isEmpty()) {
                    if (this.itemStacks.get(j) != null) {
                        if (this.field_75239_a.getStackInSlot(i).getItem() == this.itemStacks.get(j).getItem()) {
                            this.field_75239_a.extractItem(i, this.itemStacks.get(j).getCount(), false);
                            count = this.field_75239_a.getStackInSlot(i).getCount();
                            itemstack = this.field_75239_a.getStackInSlot(i);
                            System.out.print(this.field_75239_a.getStackInSlot(i).getCount());
                          //The output is right, but in game the number doesn't change until I take the material item
                        }
                    }
                }
            }
          //====================================
                if (!itemstack1.isEmpty()) {
                    if (itemstack.isEmpty()) {
                        this.field_75239_a.insertItem(i, itemstack1, false);
                    } else if (ItemStack.areItemsEqual(itemstack, itemstack1) && ItemStack.areItemStackTagsEqual(itemstack, itemstack1)) {
                        itemstack1.grow(itemstack.getCount());
                        this.field_75239_a.insertItem(i, itemstack1, false);
                    } else if (!this.player.inventory.addItemStackToInventory(itemstack1)) {
                        this.player.dropItem(itemstack1, false);
                    }
                }
        }
        return stack;
    }
}

I mark the problem code. When I delete 'for' and replace 'j' with 'i', the item's number decrease when I take result item, and the decreased number is 'this.itemStacks.get(i).getCount()'. (But it isn't my purpose.)

 

I put the code to github, here is the link: https://github.com/NGYF/Arknights-Mod

The java files I think it is necessary:

All of https://github.com/NGYF/Arknights-Mod/tree/master/src/main/java/arknights/recipe

https://github.com/NGYF/Arknights-Mod/blob/master/src/main/java/arknights/container/WorkshopContainer.java

https://github.com/NGYF/Arknights-Mod/blob/master/src/main/java/arknights/tileentity/WorkshopEntity.java

 

Could you tell me how to deal with the problem? Thanks for your help!

Posted

Because, fundamentally, that code runs on the client and the client controls bugger all. Only the server can modify that data.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted
On 3/15/2020 at 9:21 PM, Draco18s said:

Because, fundamentally, that code runs on the client and the client controls bugger all. Only the server can modify that data.

 

Actually, the data changed correctly, but the number showed wrong. When I take away the item it shows the right number immediately.

And I can delete some code to make it decrease the same number as 'this.itemStacks.get(i).getCount()' immediately, so I don't think the code runs on the client.

But I don't have any idea to solve it. What do you think about it? Thank you.

Posted (edited)

Ah, I misunderstood the problem.

 

So basically what I said was inverted.

"The server controls that code and the client knows fuckall about the data until you pick the item up."

You either need to run similar code on the client or use packets.

Edited by Draco18s

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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 tried do download the essential mod to my mod pack but i didnt work. I paly on 1.21 and it should work. I use neoforge for my modding. The weird things is my friend somehow added the mod to his modpack and many others that I somehow can´t. Is there anything i can do? 
    • Thanks, I've now installed a slightly newer version and the server is at least starting up now.
    • i have the same issue. Found 1 Create mod class dependency(ies) in createdeco-1.3.3-1.19.2.jar, which are missing from the current create-1.19.2-0.5.1.i.jar Found 11 Create mod class dependency(ies) in createaddition-fabric+1.19.2-20230723a.jar, which are missing from the current create-1.19.2-0.5.1.i.jar Detailed walkthrough of mods which rely on missing Create mod classes: Mod: createaddition-fabric+1.19.2-20230723a.jar Missing classes of create: com/simibubi/create/compat/jei/category/sequencedAssembly/JeiSequencedAssemblySubCategory com/simibubi/create/compat/recipeViewerCommon/SequencedAssemblySubCategoryType com/simibubi/create/compat/rei/CreateREI com/simibubi/create/compat/rei/EmptyBackground com/simibubi/create/compat/rei/ItemIcon com/simibubi/create/compat/rei/category/CreateRecipeCategory com/simibubi/create/compat/rei/category/WidgetUtil com/simibubi/create/compat/rei/category/animations/AnimatedBlazeBurner com/simibubi/create/compat/rei/category/animations/AnimatedKinetics com/simibubi/create/compat/rei/category/sequencedAssembly/ReiSequencedAssemblySubCategory com/simibubi/create/compat/rei/display/CreateDisplay Mod: createdeco-1.3.3-1.19.2.jar Missing classes of create: com/simibubi/create/content/kinetics/fan/SplashingRecipe
    • The crash points to moonlight lib - try other builds or make a test without this mod and the mods requiring it
    • Do you have shaders enabled? There is an issue with the mod simpleclouds - remove this mod or disable shaders, if enabled  
  • Topics

×
×
  • Create New...

Important Information

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