Jump to content

[1.10.2] Container GUI slot calculation problem


luckie12

Recommended Posts

I made a custom gui :

bigchest.png

Its a 99 slot container

I cant get the slots index to work...

i have this now:

 

	for (int y = 0; y < 11; ++y) {
		for (int x = 0; x < 9; ++x) {
			this.addSlotToContainer(new Slot(te, x+y*11, 8 + x * 18, 14 + y * 18));
		}
	}

But at the slots, the only top row works with saving items, when u put something in row 2 or anywhere else it dissapears...

i cant get the

x+y*11,

part right...

 

I hope someone can help me with this.

 

Thankyou :D

Link to comment
Share on other sites

Think you got it a bit off. Haven't touched containers since 1.7.10, but I do remember what hell I had with 'em. (They are the bane of my existence).

 

Any slots "outside" the texture? Hover the mouse just outside the outer slots, and see if anything highlights like the slots.

 

Quick look shows ContainerChest uses:

for (int j = 0; j < this.numRows; ++j)
        {
            for (int k = 0; k < 9; ++k)
            {
                this.addSlotToContainer(new Slot(chestInventory, k + j * 9, 8 + k * 18, 18 + j * 18));
            }
        }

Or rather, more dynamically:

for (int y = 0; y < maxRows; ++y)
        {
            for (int x = 0; x < maxSlotsPerLine; ++x)
            {                                         //Index                  xpos         ypos
                this.addSlotToContainer(new Slot(tile, x + y * maxSlotsPerLine, 8 + x * 18, 18 + y * 18));
            }
        }

You seem to be using x+y*maxRows rather than x+y*maxSlotsPerLine.

Do you have a github or similar repository with your current code? I'd like to see the whole container-class as well as the Gui-class.

Also previously known as eAndPi.

"Pi, is there a station coming up where we can board your train of thought?" -Kronnn

Published Mods: Underworld

Handy links: Vic_'s Forge events Own WIP Tutorials.

Link to comment
Share on other sites

There are no slots outside of it, not that we can see, maybe outside my screen somewhere :P

 

I have NO idea how to use github to upload haha

 

but i can use pastebin for better overview then using the code tags haha

 

This is my container class

 

http://pastebin.com/nqnXCH36

 

And this is the gui Class

 

http://pastebin.com/1CbM6Ehv

 

Sorry if its still not the best way to share codes haha

Link to comment
Share on other sites

I still had no luck getting this right, i looked at some examples but i guess my calculation is just baaaaad at the index,

 

the slots higlight all perfectly, but from row2- the rest of the rows, the items dissapear.

Row1 saves the items.

 

There are no slots OUTSIDE the gui visible on hover

Link to comment
Share on other sites

Can I see your TE class.

* Edit shouldn't the 11 be a 9 for when you are calculating the index?

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.

Link to comment
Share on other sites

This is my TE

 

package Fatal1tyGC.BitofTuts.tileentities;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.util.text.TextComponentTranslation;

public class TileEntityBigChest extends TileEntity implements IInventory{

private ItemStack[] inventory;
private String customName;

public TileEntityBigChest(){
	this.inventory = new ItemStack[this.getSizeInventory()];
}

public String getCustomName() {
	return customName;
}

public void setCustomName(String customName) {
	this.customName = customName;
}

@Override
public String getName() {
	return this.hasCustomName() ? this.customName : "Big Chest";
}
@Override
public boolean hasCustomName() {
	return this.customName != null && !this.customName.equals("");
}

@Override
public ITextComponent getDisplayName() {
	return this.hasCustomName() ? new TextComponentString(this.getName()) : new TextComponentTranslation(this.getName());
}

@Override
public int getSizeInventory() {
	return 9;
}

@Override
public ItemStack getStackInSlot(int index) {
    if (index < 0 || index >= this.getSizeInventory())
        return null;
    return this.inventory[index];
}

@Override
public ItemStack decrStackSize(int index, int count) {
    if (this.getStackInSlot(index) != null) {
        ItemStack itemstack;

        if (this.getStackInSlot(index).stackSize <= count) {
            itemstack = this.getStackInSlot(index);
            this.setInventorySlotContents(index, null);
            this.markDirty();
            return itemstack;
        } else {
            itemstack = this.getStackInSlot(index).splitStack(count);

            if (this.getStackInSlot(index).stackSize <= 0) {
                this.setInventorySlotContents(index, null);
            } else {
                //Just to show that changes happened
                this.setInventorySlotContents(index, this.getStackInSlot(index));
            }

            this.markDirty();
            return itemstack;
        }
    } else {
        return null;
    }
}

@Override
public void setInventorySlotContents(int index, ItemStack stack) {
    if (index < 0 || index >= this.getSizeInventory())
        return;

    if (stack != null && stack.stackSize > this.getInventoryStackLimit())
        stack.stackSize = this.getInventoryStackLimit();
        
    if (stack != null && stack.stackSize == 0)
        stack = null;

    this.inventory[index] = stack;
    this.markDirty();
}

@Override
public ItemStack removeStackFromSlot(int index) {
    ItemStack stack = this.getStackInSlot(index);
    this.setInventorySlotContents(index, null);
    return stack;
}

@Override
public int getInventoryStackLimit() {
	return 64;
}

public boolean isUseableByPlayer(EntityPlayer player){
	return this.worldObj.getTileEntity(this.getPos()) == this && player.getDistanceSq(this.pos.add(0.5,0.5,0.5)) <= 64;
}

@Override
public void openInventory(EntityPlayer player) {
}
@Override
public void closeInventory(EntityPlayer player) {	
}

@Override
public boolean isItemValidForSlot(int index, ItemStack stack) {
	return true;
}

@Override
public int getField(int id) {
	return 0;
}

@Override
public void setField(int id, int value) {
}

@Override
public int getFieldCount() {
	return 0;
}

@Override
public void clear() {
	for(int i = 0; i < this.getSizeInventory(); i++)
		this.setInventorySlotContents(i, null);
}


@Override
public NBTTagCompound writeToNBT(NBTTagCompound nbt) {
    super.writeToNBT(nbt);

    NBTTagList list = new NBTTagList();
    for (int i = 0; i < this.getSizeInventory(); ++i) {
        if (this.getStackInSlot(i) != null) {
            NBTTagCompound stackTag = new NBTTagCompound();
            stackTag.setByte("Slot", (byte) i);
            this.getStackInSlot(i).writeToNBT(stackTag);
            list.appendTag(stackTag);
        }
    }
    nbt.setTag("Items", list);

    if (this.hasCustomName()) {
        nbt.setString("CustomName", this.getCustomName());
    }
	return nbt;
}


@Override
public void readFromNBT(NBTTagCompound nbt) {
    super.readFromNBT(nbt);

    NBTTagList list = nbt.getTagList("Items", 10);
    for (int i = 0; i < list.tagCount(); ++i) {
        NBTTagCompound stackTag = list.getCompoundTagAt(i);
        int slot = stackTag.getByte("Slot") & 255;
        this.setInventorySlotContents(slot, ItemStack.loadItemStackFromNBT(stackTag));
    }

    if (nbt.hasKey("CustomName", ) {
        this.setCustomName(nbt.getString("CustomName"));
    }
}

}

 

I just tested with 9 instead of 11 and that didnt change anything, still the exact same thing

Link to comment
Share on other sites

getSizeInventory returns 9 kinda surprised you didn't get an Array out of Bounds Exception..

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.

Link to comment
Share on other sites

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

    • Slot Bank BNI adalah pilihan tergacor untuk memulai bermain slot judi Online dimuka bumi saat ini. Jika anda mempunyai Bank BNI, Anda berkesempatan mendapatkan Akun Pro atau ID pro untuk bermain slot. Tunggu apa lagi? Segera daftarkan diri anda sekarang dan dapatkan kemewahan menang maxwin di Museumbola.
    • Halo para penggemar slot online! Apakah Anda mencari pengalaman bermain slot yang seru dan menguntungkan? Apakah Anda ingin menikmati slot gacor dari server Thailand sambil melakukan deposit melalui Mandiri dengan kesempatan meraih kemenangan besar? Anda telah sampai di tempat yang tepat! Kami di WINNING303 siap memberikan Anda pengalaman bermain yang mengasyikkan dan menguntungkan. Mengapa Memilih WINNING303? WINNING303 telah dikenal sebagai salah satu platform terbaik untuk bermain slot dengan berbagai keunggulan yang kami tawarkan kepada para pemain kami. Berikut adalah beberapa alasan mengapa Anda harus memilih WINNING303: Slot Gacor dari Server Thailand Kami menyajikan koleksi slot gacor terbaik dari server Thailand yang pastinya akan memberikan Anda pengalaman bermain yang menarik dan menguntungkan. Nikmati berbagai jenis permainan slot dengan tingkat kemenangan yang tinggi dan jackpot yang menarik. Deposit Mudah Melalui Mandiri Kami memahami pentingnya kemudahan dalam bertransaksi bagi para pemain kami. Oleh karena itu, kami menyediakan layanan deposit melalui bank Mandiri, salah satu bank terbesar di Indonesia. Proses depositnya cepat, mudah, dan aman, sehingga Anda dapat langsung memulai petualangan bermain tanpa hambatan. Peluang Maxwin Besar Di WINNING303, kami selalu memberikan peluang untuk meraih kemenangan besar. Dengan berbagai promosi dan bonus menarik yang kami sediakan, Anda memiliki kesempatan untuk memenangkan hadiah-hadiah yang fantastis dan meraih maxwin dalam bermain slot.  
    • SLOT Ratubet77 adalah bocoran slot gacor rekomendasi dari Ratubet77 yang bisa anda temukan di SLOT Ratubet77. Situs SLOT Ratubet77 hari ini yang kami bagikan di sini adalah yang terbaik dan bersiaplah untuk mengalami sensasi tak terlupakan dalam permainan slot online. Temukan game SLOT Ratubet77 terbaik dengan 100 pilihan provider ternama yang dipercaya akan memberikan kepuasan dan kemenangan hari ini untuk meraih x500. RTP SLOT Ratubet77 merupakan SLOT Ratubet77 hari ini yang telah menjadi pilihan utama bagi pemain judi online di seluruh Indonesia. Setiap harinya jutaan pemain memasuki dunia maya untuk memperoleh hiburan seru dan kemenangan besar dalam bermain slot dengan adanya bocoran RTP SLOT Ratubet77. Tidak ada yang lebih menyenangkan daripada mengungguli mesin slot dan meraih jackpot x500 yang menggiurkan di situs SLOT Ratubet77 hari ini yang telah disediakan SLOT Ratubet77. Menangkan jackpot besar x500 rajanya maxwin dari segala slot dan raih kemenangan spektakuler di situs Ratubet77 terbaik 2024 adalah tempat yang menyediakan mesin slot dengan peluang kemenangan lebih tinggi daripada situs slot lainnya. Bagi anda yang mencari pengalaman judi slot paling seru dan mendebarkan, situs bo SLOT Ratubet77 terbaik 2024 adalah pilihan yang tepat. Jelajahi dunia slot online melalui situs SLOT Ratubet77 di link SLOT Ratubet77. DAFTAR SEKARANG DAFTAR SEKARANG DAFTAR SEKARANG
    • I am currently running the 1.20.1 Occultcraft modpack in Curseforge and am having numerous troubles making a mob farm with the apotheosis mod. When trying to modify the stats of the spawners specific stats such as the range, spawn count, and max entities reset to default after every spawn. When the spawners spawn boss mobs with certain attributes, that I'm not sure of, the building it is in explode even with mob griefing turned off. This has happened multiple times with varying sizes for the explosions. I was wonder if there is any way to disable these explosions from happening or disable boss abilities with something in the game. I also wanted to know a fix for the resetting stats on spawners and why this is happening.
    • SLOT Bank BSI adalah pilihan terbaik untuk Anda yang ingin merasakan sensasi bermain slot dengan layanan dari Bank BSI. Dengan keamanan terjamin, beragam pilihan permainan, kemudahan deposit via Bank BSI, dan berbagai bonus menarik, kami siap memberikan Anda pengalaman bermain yang tak terlupakan. Bergabunglah dengan kami sekarang dan mulailah petualangan seru Anda!    
  • Topics

×
×
  • Create New...

Important Information

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