Jump to content

Recommended Posts

Posted (edited)

I am trying to make a Tile Entity that stores one item and its amount.

I have a Container which has one slot, that is where you should put the item. The item goes up to the 32 bit integer limit.

My problems are:

Shift clicking is weird, slots 9-10 just go to each other 2-8 goes to 19-26, slot 27-35 and 1 crashes game with this error:

Caused by: java.lang.NullPointerException
	at net.minecraft.inventory.Container.slotClick(Container.java:271) ~[Container.class:?]
	at net.minecraft.client.multiplayer.PlayerControllerMP.windowClick(PlayerControllerMP.java:610) ~[PlayerControllerMP.class:?]
	at net.minecraft.client.gui.inventory.GuiContainer.handleMouseClick(GuiContainer.java:693) ~[GuiContainer.class:?]
	at net.minecraft.client.gui.inventory.GuiContainer.mouseClicked(GuiContainer.java:430) ~[GuiContainer.class:?]
	at net.minecraft.client.gui.GuiScreen.handleMouseInput(GuiScreen.java:611) ~[GuiScreen.class:?]
	at net.minecraft.client.gui.GuiScreen.handleInput(GuiScreen.java:576) ~[GuiScreen.class:?]
	at net.minecraft.client.Minecraft.runTick(Minecraft.java:1884) ~[Minecraft.class:?]
	... 15 more

I'm just gonna post a video cause it's easier to explain.

(Ima add textures/models later ofc)

Container:

public class QuantumContainer extends Container {

    QuantumContainer(InventoryPlayer inventory, TEQuantumStorage tile) {
        SlotItemHandler slot = new SlotQuantum(new QuantumHandler(tile), 36, 80, 40);
        addSlotToContainer(slot);
        slot.putStack(new ItemStack(tile.getItem(), tile.getAmount()));
        int i;
        for (i = 0; i < 3; ++i) {
            for (int j = 0; j < 9; ++j) {
                addSlotToContainer(new Slot(inventory, j + i * 9 + 9,
                        8 + j * 18, 84 + i * 18));
            }
        }
        // add hotbar slots
        for (i = 0; i < 9; ++i) {
            addSlotToContainer(new Slot(inventory, i, 8 + i * 18,
                    142));
        }
    }

    @Override
    @ParametersAreNonnullByDefault
    public boolean canInteractWith(EntityPlayer playerIn) {
        return true;
    }

    @Override
    @MethodsReturnNonnullByDefault
    public ItemStack transferStackInSlot(EntityPlayer playerIn, int slotIndex) {
        ItemStack itemStack1 = null;
        Slot slot = inventorySlots.get(slotIndex);

        if (slot != null && slot.getHasStack()) {
            ItemStack itemStack2 = slot.getStack();
            itemStack1 = itemStack2.copy();
            // player inventory slots
            if (slotIndex >= 9 && slotIndex < 36) {
                if (!mergeItemStack(itemStack2, 9, 35, false))
                    return null;
                // hotbar slots
            } else if (slotIndex < 9 && !mergeItemStack(itemStack2, 2, 28, false)) {
                if (!mergeItemStack(itemStack2, 0, 8, false))
                    return null;
            } else if (!mergeItemStack(itemStack2, 0, 37, false)) {
                return null;
            }
            if (itemStack2.getCount() == 0) {
                slot.putStack(ItemStack.EMPTY);
            } else {
                slot.onSlotChanged();
            }
            if (itemStack2.getCount() == itemStack1.getCount()) {
                return null;
            }
        }
        return itemStack1;
    }
}

QuantumHandler:

private ItemStack stack;
    private TEQuantumStorage tile;

    public QuantumHandler(TEQuantumStorage tile) {
        this.tile = tile;
    }

    @Override
    public int getSlots() {
        return 1;
    }

    @Nonnull
    @Override
    public ItemStack getStackInSlot(int slot) {
        return stack;
    }

    @Nonnull
    @Override
    public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate) {
        tile.setItem(stack.getItem());
        tile.addAmount(stack.getCount());
        this.stack = stack;
        this.stack.setCount(tile.getAmount());
        tile.markDirty();
        ItemStack stack1 = stack.copy();
        if(stack.getCount() == 1) {
            stack1.setCount(stack1.getCount() - 1);
            return stack1;
        } else
            return ItemStack.EMPTY;
    }

    @Nonnull
    @Override
    public ItemStack extractItem(int slot, int amount, boolean simulate) {
        ItemStack stack = this.stack.copy();
        if (stack.getCount() > 64) {
            stack.setCount(64);
        }
        if(amount == 1 && tile.getAmount() > 0)
            stack.setCount(1);
        else
            if(tile.getAmount() < 64)
                stack.setCount(tile.getAmount());
        tile.addAmount(-amount);
        this.stack.setCount(this.stack.getCount() - amount);
        tile.markDirty();
        return stack;
    }

    @Override
    public int getSlotLimit(int slot) {
        return 2147483647;
    }

    @Override
    public void setStackInSlot(int slot, @Nonnull ItemStack stack) {
        this.stack = stack;
        tile.markDirty();
    }

SlotQantum:

public class SlotQuantum extends SlotItemHandler {
    public SlotQuantum(IItemHandler handler, int index, int xPosition, int yPosition) {
        super(handler, index, xPosition, yPosition);
    }

    @Override
    public int getSlotStackLimit() {
        return 2147483647;
    }
}

Tile Entity:

public class TEQuantumStorage extends TileEntity {

    private Item item;
    private int amount;

    @Override
    public void readFromNBT(NBTTagCompound nbt) {
        super.readFromNBT(nbt);
        this.item = Item.getItemById(nbt.getInteger("item"));
        this.amount = nbt.getInteger("amount");
    }


    @Override
    public NBTTagCompound writeToNBT(NBTTagCompound nbt) {
        super.writeToNBT(nbt);
        nbt.setInteger("item", Item.getIdFromItem(item));
        nbt.setInteger("amount", amount);
        return nbt;
    }

    public int getAmount() {
        return amount;
    }

    public void setAmount(int amount) {
        this.amount = amount;
    }

    public Item getItem() {
        return item;
    }

    public void setItem(Item item) {
        this.item = item;
    }
}

Sorry for code dump, but I've been at this for hours and have no idea what I'm doing wrong.

Edited by Big_Bad_E
Posted

Override getMaxStack size or something?

have a look at how AppliedEnergistics or another open source storage mod does it

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)

Posted
14 hours ago, Cadiboo said:

Override getMaxStack size or something?

have a look at how AppliedEnergistics or another open source storage mod does it

No, I am not trying to have a super large item stack, I am trying to store it as a number in the tile entity's NBT data along with the item. Then I can use that to let the player get the item. It's literally the Deep Storage Unit.

Posted
2 hours ago, Big_Bad_E said:

I'm just gonna bump this because Draco is online

Lol

20 hours ago, Big_Bad_E said:

GenericSlotHolder implements IInventory

Dont do this use the IItenHandler capability instead.

 

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted
20 hours ago, Animefan8888 said:

Lol

Dont do this use the IItenHandler capability instead.

 

How would I use IItemHandler? I can't set slot's inventory to it because it doesn't implement IInventory.

It looks nice but I can't use it.

 

Also back to the original question what's wrong with my code?

Posted
22 hours ago, Big_Bad_E said:

I'm just gonna bump this because Draco is online

I will then proceed to ignore the fuck out of it because I was on an airplane, and got home at 1am after having almost missed my connecting flight in Phoenix because my first leg was 45 60 minutes late leaving and the gate attendant told me "You'll have 34 minutes between flights, you'll be fine." I had 22 minutes, minus the "doors close 10 minutes before the departure time" so 12 minutes to get from gate B4 to A25.

 

Storing large stacks? You're going to need two inventory slots, an input and an output. The output always contains a stack of size Max(available, 64). The input slot is always empty. When a stack is placed into the input and it matches the contents, destroy the stack and add its size to the TE's integer value of contents.

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 (edited)
1 hour ago, Draco18s said:

I will then proceed to ignore the fuck out of it because I was on an airplane, and got home at 1am after having almost missed my connecting flight in Phoenix because my first leg was 45 60 minutes late leaving and the gate attendant told me "You'll have 34 minutes between flights, you'll be fine." I had 22 minutes, minus the "doors close 10 minutes before the departure time" so 12 minutes to get from gate B4 to A25.

 

Storing large stacks? You're going to need two inventory slots, an input and an output. The output always contains a stack of size Max(available, 64). The input slot is always empty. When a stack is placed into the input and it matches the contents, destroy the stack and add its size to the TE's integer value of contents.

Oh, didn't know, sorry about ur airplane problems. How come we can mass produce nuclear weapons but we cant move from point A to point B in an airplane easily.

 

Input and output is a good idea i'm going to try it.

 

Still being weird, see updated code/errors above.

Edited by Big_Bad_E
Posted
4 hours ago, Big_Bad_E said:

How would I use IItemHandler? I can't set slot's inventory to it because it doesn't implement IInventory.

It looks nice but I can't use it.

Use SlotItemHandler instead of Slot.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted (edited)
20 hours ago, Animefan8888 said:

Use SlotItemHandler instead of Slot.

Will look into it.

 

I am now using SlotItemHandler, good idea with that one.

Edited by Big_Bad_E
Posted
6 hours ago, Big_Bad_E said:

I just gave up, I've spent way too long working on this.

Move on to something else for a couple days, then come back to this. This should be very easy to achieve, and when you come back to it in a couple days with a new perspective, it shouldn’t take you very much time at all to do it! Good luck!

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)

Posted
23 minutes ago, Cadiboo said:

Move on to something else for a couple days, then come back to this. This should be very easy to achieve, and when you come back to it in a couple days with a new perspective, it shouldn’t take you very much time at all to do it! Good luck!

My main problem is that I can't figure out what is wrong with my code, and when I use one solution, tons more pop up. Like implements IItemHandler now the input slot only takes one item which won't disappear, and I can't test output, and for some reason when I close the GUI with an item the amount gets set to -22 and it crashes. I've updated my code but I've just run into a lack of solutions. For some reason slot events aren't being called and I'm just frustrated.

 

Now that I'm thinking about it i'm just going to make a slot with a max item limit of the 32 bit integer limit.

Posted
1 minute ago, Big_Bad_E said:

My main problem is that I can't figure out what is wrong with my code, and when I use one solution, tons more pop up. Like implements IItemHandler now the input slot only takes one item which won't disappear, and I can't test output, and for some reason when I close the GUI with an item the amount gets set to -22 and it crashes. I've updated my code but I've just run into a lack of solutions. For some reason slot events aren't being called and I'm just frustrated.

 

Now that I'm thinking about it i'm just going to make a slot with a max item limit of the 32 bit integer limit.

Use forges IItemHandler system with 2 slots input & output, when a stack goes into the input delete it and add it’s value to your tiles data. Write the code for output later

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)

Posted
1 hour ago, Cadiboo said:

Use forges IItemHandler system with 2 slots input & output, when a stack goes into the input delete it and add it’s value to your tiles data. Write the code for output later

I'd rather just make a single stack. I think it would generally be easier.

Posted
1 minute ago, Big_Bad_E said:

I'd rather just make a single stack. I think it would generally be easier.

Use an IItemHandler that has one slot and access to the TEs amount field and override insertItem and extractItem as well as getStack or getStacks(whatever that method is called in IItemHandler) and return the appropriate values and update the stack inside the IItemHandler based on the amount filed. No need for a fancy slot.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted
7 minutes ago, Animefan8888 said:

Use an IItemHandler that has one slot and access to the TEs amount field and override insertItem and extractItem as well as getStack or getStacks(whatever that method is called in IItemHandler) and return the appropriate values and update the stack inside the IItemHandler based on the amount filed. No need for a fancy slot.

That's what i'm doing.

Posted
1 hour ago, Big_Bad_E said:

That's what i'm doing.

Well considering you have not posted your updated code how was I supposed to know that or help you anymore than that.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted
11 hours ago, Animefan8888 said:

Well considering you have not posted your updated code how was I supposed to know that or help you anymore than that.

I haven't updated my code cause I haven't coded it yet. And:

12 hours ago, Big_Bad_E said:

I'd rather just make a single stack. I think it would generally be easier.

 

On 8/11/2018 at 8:10 PM, Big_Bad_E said:

Will look into it.

 

I am now using SlotItemHandler, good idea with that one.

I did say what I was going to do.

Posted

Couple questions:

How do I update the Container/GUI to display the updated item?

How do I stop the block from being placed when I open the GUI?

 

I can fix the shift click problems myself.

Posted
3 hours ago, Big_Bad_E said:

How do I update the Container/GUI to display the updated item?

Send a packet to the player there are multiple ways to do this, but show your code and I can tell you which on to use. 

3 hours ago, Big_Bad_E said:

How do I stop the block from being placed when I open the GUI?

Return true in onBlockActivated

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted
15 minutes ago, Animefan8888 said:

Send a packet to the player there are multiple ways to do this, but show your code and I can tell you which on to use. 

Return true in onBlockActivated

My code is updated, I've never used packets with Forge so it will be fun to try :)

Posted

Are you sure packets are the way to go?

I made some packets, and it updated the server, but not the client's slot.

 

How do I get the slot itself to update? I think there is another ItemStack list somewhere that is called to draw the itemstacks. I am gonna look through the itemstack draw method and the container close/update method cause that also updates it.

Posted
28 minutes ago, Big_Bad_E said:

Are you sure packets are the way to go?

I made some packets, and it updated the server, but not the client's slot.

Are you sending the data to the client or to the server?

29 minutes ago, Big_Bad_E said:

How do I get the slot itself to update?

If changing the IItemHandlers stack on the client doesnt update the container/gui have your packet also update the container.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted
9 minutes ago, Animefan8888 said:

Are you sending the data to the client or to the server?

If changing the IItemHandlers stack on the client doesnt update the container/gui have your packet also update the container.

The data was sent client to server.

 

My problem was the container had updated data but for some reason the GUI's instance of the data wasn't updated, so I manually just got the itemstack from the TileEntity and used it to update the GUI.

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

    • Reach Out To Rapid Digital: What sapp Info: +1 41 4 80 7 14 85 Email INFO: rap iddi gita lrecov ery @ exe cs. com Hello, my name is Jayson, and I’m 35 years old from the United Kingdom. My family and I recently endured an incredibly challenging experience that I wouldn’t wish on anyone. We became victims of a cryptocurrency investment fraud scheme that saw us lose a staggering $807,000 in USDT and Bitcoins. The fraudsters had created a convincing facade, and we were lured into investing, only to discover later that the platform was a complete scam. We were left devastated, not just financially, but emotionally, as we had trusted these people and believed in the legitimacy of the investment. After the initial shock wore off, we desperately searched for ways to recover the lost funds. It seemed like an impossible task, and we felt as though there was no hope. That’s when, by sheer luck, we stumbled across a post about Rapid Digital Recovery, a cryptocurrency and funds recovery organization with a proven track record in cybersecurity and fraud recovery. We decided to reach out to them, and from the first interaction, we were impressed with their professionalism and transparency. They explained the recovery process in detail and reassured us that they had the skills and expertise to track down the perpetrators and recover our funds. This gave us a renewed sense of hope, something we hadn’t felt in months. What truly stood out during our experience with Rapid Digital Recovery was their dedication to the recovery process. The team went above and beyond, using sophisticated tracking tools and cyber forensics to gather critical information. Within a matter of weeks, they had successfully located the funds and traced the scam back to the fraudsters responsible. They worked with the authorities to ensure the criminals were held accountable for their actions. To our relief, the team at Rapid Digital Recovery was able to recover every single penny we had lost. The funds were returned in full, and the sense of closure we felt was invaluable. We couldn’t have imagined such a positive outcome in the early stages of our recovery journey, and we are deeply grateful for the work they did. If you ever find yourself in a similar situation, I highly recommend contacting Rapid Digital Recovery. Their expertise, transparency, and dedication to their clients make them the go-to choice for anyone seeking to recover lost cryptocurrency or funds. They truly gave us back our financial future.  
    • This is my first time modding anything, so maybe just skill issue. I'm using Forge 54.0.12 and Temurin 21.0.5+11-LTS I wanted to create a custom keybind and to check whether it works I'd like to send a chat message. I tried using Minecraft.getInstance().player.sendSystemMessage(Component.literal("test")); but IntelliJ couldnt resolve sendSystemMessage(...). Since I saw people using it in earlier versions, I tried the same thing with 1.20.6(- 50.1.0), where it works fine, now I can't figure out if this is intentional and whether there are other options for sending chat messages. On that note, is there more documentation than https://docs.minecraftforge.net/en/1.21.x/? It seems very incomplete compared to something like the Oracle Java docs
    • Hi, i'm having this error and I wanna fix it. we try: -Reload drivers -Eliminate .minecraft -Eliminate Java -Restart launcher -Verify if minecraft is using gpu -Mods  in .minecraft is empty -Install the latest and recomended version of forge idk what i have to do, help me pls. the lastest log is: https://mclo.gs/WAMao8x  
    • Read the FAQ, Rule #2. (https://forums.minecraftforge.net/topic/125488-rules-and-frequently-asked-questions-faq/)  
  • Topics

×
×
  • Create New...

Important Information

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