Jump to content

[1.6.4][SOLVED]Ghost Items in Container


AceScottie

Recommended Posts

I have looked into this quite a lot and all the usual errors are not present in my code.

Whole creating a new container and shift-clicking items in or out of the container, the items will leave a ghost item behind. After looking around its mostly the slotObject.onSlotChanged(); area that needs to be added or edited however i already have that code as it should be (i think).

 

Container.class

 

 

 

package OreManager.container;

 

import OreManager.block.TileEntityOreModel;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.entity.player.InventoryPlayer;

import net.minecraft.inventory.Container;

import net.minecraft.inventory.Slot;

import net.minecraft.item.ItemStack;

 

public class ChangeContainer extends Container {

 

@Override

public boolean canInteractWith(EntityPlayer entityplayer) {

return TileEntity.isUseableByPlayer(entityplayer);

}

 

protected TileEntityOreModel TileEntity;

 

 

public ChangeContainer(InventoryPlayer inventoryPlayer, TileEntityOreModel TE) {

TileEntity = TE;

 

 

for(int i = 0; i < 1; i++) {

for(int j = 0; j < 1; j++) {

addSlotToContainer(new Slot(TileEntity, j + i * 3, 25 + j * 18, 18 + i * 18));

 

}

}

for(int i = 0; i < 1; i++) {

for(int j = 0; j < 1; j++) {

addSlotToContainer(new Slot(TileEntity, j + i * 3, 76 + j * 18, 18 + i * 18));

 

}

}

bindPlayerInventory(inventoryPlayer);

 

}

 

private void bindPlayerInventory(InventoryPlayer inventoryPlayer) {

for(int i = 0; i < 3; i++) {

for(int j = 0; j < 9; j++) {

addSlotToContainer( new Slot(inventoryPlayer, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));

}

}

for(int i = 0; i < 9; i++) {

addSlotToContainer(new Slot(inventoryPlayer, i, 8 + i * 18, 142));

}

 

}

 

 

@Override

public ItemStack transferStackInSlot(EntityPlayer player, int par2) {

 

 

 

ItemStack itemstack = null;

Slot slotObject = (Slot)inventorySlots.get(par2);

Slot inSlot = (Slot) this.inventorySlots.get(0);

Slot outSlot = (Slot) this.inventorySlots.get(1);

if(slotObject != null && slotObject.getHasStack()) {

ItemStack stackInSlot = slotObject.getStack();

itemstack = stackInSlot.copy();

 

if (par2 < 2) {

if(!this.mergeItemStack(stackInSlot, 2, 35, true)) {

return null;

 

}

slotObject.onSlotChange(stackInSlot, itemstack);

}

else if(!this.mergeItemStack(stackInSlot, 0, 2, false)){

return null;

}

if (!this.mergeItemStack(stackInSlot, 31, 40, false)) {

return null;

}

else if (par2 >= 31 && par2 < 40

&& !this.mergeItemStack(stackInSlot, 4, 31, false)) {

return null;

}

else if (!this.mergeItemStack(stackInSlot, 4, 40, false)) {

return null;

}

 

if(stackInSlot.stackSize == 0) {

slotObject.putStack((ItemStack)null);

 

}

else {

slotObject.onSlotChanged();

}

 

if(stackInSlot.stackSize == itemstack.stackSize) {

return null;

}

slotObject.onPickupFromSlot(player, stackInSlot);

}

return itemstack;

 

}

}

 

 

 

any other information can be provided on request.

I am still learning java so please show examples if necessary. I don't like to copy paste code, i like to know what the code does and how it does it.

 

(This is an old mod i plan to update to 1.7.10 once i finished this section of it)

 

Link to comment
Share on other sites

I thought it was a pretty basic class so i haven't looked much into this one.

 

 

 

public class OreChangerGuiHandler implements IGuiHandler {

 

@Override

    public Object getServerGuiElement(int id, EntityPlayer player, World world,

                    int x, int y, int z) {

            TileEntity tileEntity = world.getBlockTileEntity(x, y, z);

            if(tileEntity instanceof TileEntityOreModel){

                    return new ChangeContainer(player.inventory, (TileEntityOreModel) tileEntity);

            }

            return null;

    }

    @Override

    public Object getClientGuiElement(int id, EntityPlayer player, World world,

                    int x, int y, int z) {

            TileEntity tileEntity = world.getBlockTileEntity(x, y, z);

            if(tileEntity instanceof TileEntityOreModel){

                    return new OreChangerGUI(player.inventory, (TileEntityOreModel) tileEntity);

            }

            return null;

 

    }

 

 

 

actually thinking about it, if this is because of a serverside - clientside issue it may have something to do with my proxy classes. Back when i first started modding having a clommon proxy and a client proxy really messed up the mod i was working on and just kept throwing out errors. removing the classes made the mod work so i paid hem no mind.

Just in case ill include my current client proxy although my common proxy is completly empty apart from the basic public class commonproxy line

 

 

 

public class ClientProxy extends CommonProxy {

 

 

public void registerOreManager() {

ClientRegistry.bindTileEntitySpecialRenderer(TileEntityOreModel.class, new RenderOreManager());

 

MinecraftForgeClient.registerItemRenderer(OreManager.blockOreChanger.blockID, new ItemRenderOreManager());

 

//LanguageRegistry.instance().addStringLocalization();

 

}

}

 

 

Link to comment
Share on other sites

No, your GuiHandler looks fine, and the proxies shouldn't have anything to do with it. Are you doing anything out of the ordinary in the Gui class? For reference, this is all you need for a functional container-based gui class.

 

How about your custom IInventory class, anything funky in there?

 

Otherwise, nothing really comes to mind. You do have a lot of unused and unnecessary code in your Container, stuff like:

// using loops for one iteration:
for(int i = 0; i < 1; i++) {
  for(int j = 0; j < 1; j++) {
  }
}

// unused variables:
Slot inSlot = (Slot) this.inventorySlots.get(0);
Slot outSlot = (Slot) this.inventorySlots.get(1);

Link to comment
Share on other sites

Yea there is a lot of unused or unneeded code  while I'm working on it. i generally run optimizations after it actually works so I know i can test other things if what I'm doing isn't working.

 

My GUI class

 

 

public class OreChangerGUI extends GuiContainer {

public static final ResourceLocation field_110421_t = new ResourceLocation("OreManager:textures/gui/OreChanger.png");

 

public OreChangerGUI(InventoryPlayer inventoryPlayer, TileEntityOreModel TileEntity) {

super(new ChangeContainer(inventoryPlayer, TileEntity));

 

}

 

@Override

protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3) {

GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);

this.mc.getTextureManager().bindTexture(field_110421_t);

int k = (this.width - this. xSize) / 2;

int y = (this.height - this.ySize) / 2;

this.drawTexturedModalRect(k, y, 0, 2, xSize, ySize);

 

}

 

//@Override

protected void drawGuiContainerForgroundLayout(int param1, int param2) {

fontRenderer.drawString("OreChangerimput", 8, 6, 4210752);

fontRenderer.drawString(StatCollector.translateToLocal("oremanager:/gui/OreChanger.png"), 8, ySize - 96 + 2, 4210752);

 

}

 

 

}

 

 

 

 

and i don't actually have a custom IInventory class. I was trying to get ISidedInventory working but this lead to some strange issues so i plan to take a look into that later. Right now my TileEntity Class just extends IInventory (net.minecraft)

Link to comment
Share on other sites

I dont Have any IInventory class of my own. am I'm importing the one from net.minecraft.inventory.IInventory

 

I dont know if this will help with solving this but i have uploaded all my source code to my dropbox account so it can be downloaded quickly and easily.

[edited out] Oremanager.zip [/edited out]

Link to comment
Share on other sites

Not gonna download a random file from the internet. Make a GitHub for your mod.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

Ok i added the !world.isRemote but still no change, not getting any errors and i have tried it with and without the other pieces of code in that function.

 

 

 

@Override

public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int metadata, float hitx, float hity, float hitz){

if (!world.isRemote){

FMLNetworkHandler.openGui(player, OreManager.instance, OreManager.guiIdOreManagerGUI, world, x, y, z);;

}

 

TileEntity tileEntity = world.getBlockTileEntity(x, y, z);

if(tileEntity == null || player.isSneaking()) {

return false;

}

player.openGui(OreManager.instance, 0, world, x, y, z);

return true;

}

 

 

Link to comment
Share on other sites

If your TileEntity implements IInventory, then that is your custom inventory class.

 

sorry i literally just realized what you meant by this (i think).

You mean my Tile Entity class IS my IInventory class ? i feel really stupid now :)

Anyway i posted a link to a github with it all on so you can see everything i have. Please ignore any junk code i got rid of the for(int i = 0; i < 1; i++) part already as that was making another part stupid to manage.

Link to comment
Share on other sites

Ok i added the !world.isRemote but still no change, not getting any errors and i have tried it with and without the other pieces of code in that function.

 

 

 

@Override

public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int metadata, float hitx, float hity, float hitz){

if (!world.isRemote){

FMLNetworkHandler.openGui(player, OreManager.instance, OreManager.guiIdOreManagerGUI, world, x, y, z);;

}

 

TileEntity tileEntity = world.getBlockTileEntity(x, y, z);

if(tileEntity == null || player.isSneaking()) {

return false;

}

player.openGui(OreManager.instance, 0, world, x, y, z);

return true;

}

 

 

 

I dont know what this code is supposed to do at all.

Just use this:

 

 
if(!world.isRemote) {
        TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
        if (tileEntity != null) player.openGui(OreManager.instance, 0, world, x, y, z);
}
        return true;

Link to comment
Share on other sites

 

I dont know what this code is supposed to do at all.

Just use this:

 

 
if(!world.isRemote) {
        TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
        if (tileEntity != null) player.openGui(OreManager.instance, 0, world, x, y, z);
}
        return true;

 

still same, no change at all.

 

Dont know if this helps at all but a few related bugs are:

Shift clicking will put items into  slot2 (if slot1 is full) even though its set not to receive items (cant place them there by normal methods).

Using a hopper with more than 1 item will destroy the stack and only leave 1 item(both on input and output).

 

 

Updated github with new code https://github.com/AceScottie/OreManager

Link to comment
Share on other sites

After a little bit of searching i can safely say the issue im having is with my Container class.

I have found a little code online that i will post below which dose fix the ghost item but, however creates a few of its own.

~Firstly it only accepts ores (this is what i wanted anyway but may have to be modified for others)

~Secondly I can only shift click into the GUI, i cannot shift click them out.

~Lastly The very top left player inventory slot cannot shift click into the GUI

 

There are some lines commented out of the code, these lines were causing me to crash after a little while.

 

 

 

  public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2)

    {

    ItemStack var3 = null;

    Slot var4 = (Slot)this.inventorySlots.get(par2);

    if (var4 != null && var4.getHasStack())

    {

    ItemStack var5 = var4.getStack();

    var3 = var5.copy();

    if (par2 == 2)

    {

  // if (!this.mergeItemStack(var5, 3, 39, true))

  //  {

//    return null;

  //  }

    var4.onSlotChange(var5, var3);

    }

    else if (par2 != 1 && par2 != 0)

    {

    if (FurnaceRecipes.smelting().getSmeltingResult(var5) != null)

    {

    if (!this.mergeItemStack(var5, 0, 1, false))

    {

    return null;

    }

    }

    else if (TileEntityOreModel.isItemOre(var5))

    {

    if (!this.mergeItemStack(var5, 1, 2, false))

    {

    return null;

    }

    }

    else if (par2 >= 3 && par2 < 30)

    {

  //  if (!this.mergeItemStack(var5, 30, 39, false))

  // {

//    return null;

  // }

    }

    else if (par2 >= 30 && par2 < 39 && !this.mergeItemStack(var5, 3, 30, false))

    {

    return null;

    }

    }

  //  else if (!this.mergeItemStack(var5, 3, 39, false))

  //  {

//    return null;

  //  }

    if (var5.stackSize == 0)

    {

    var4.putStack((ItemStack)null);

    }

    else

    {

    var4.onSlotChanged();

    }

    if (var5.stackSize == var3.stackSize)

    {

    return null;

    }

    var4.onPickupFromSlot(par1EntityPlayer, var5);

    }

    return var3;

    }

 

 

 

I am currently in the process of comparing my original code to this one but to make sure ill put my code here

 

 

@Override

public ItemStack transferStackInSlot(EntityPlayer player, int par2) {

 

 

 

ItemStack itemstack = null;

Slot slotObject = (Slot)inventorySlots.get(par2);

Slot inSlot = (Slot) this.inventorySlots.get(0);

Slot outSlot = (Slot) this.inventorySlots.get(1);

if(slotObject != null && slotObject.getHasStack()) {

ItemStack stackInSlot = slotObject.getStack();

itemstack = stackInSlot.copy();

 

if (par2 < 2) {

if(!this.mergeItemStack(stackInSlot, 2, 35, true)) {

return null;

 

}

slotObject.onSlotChange(stackInSlot, itemstack);

}

else if(!this.mergeItemStack(stackInSlot, 0, 2, false)){

return null;

}

if (!this.mergeItemStack(stackInSlot, 31, 40, false)) {

return null;

}

else if (par2 >= 31 && par2 < 40

&& !this.mergeItemStack(stackInSlot, 4, 31, false)) {

return null;

}

else if (!this.mergeItemStack(stackInSlot, 4, 40, false)) {

return null;

}

 

if(stackInSlot.stackSize == 0) {

slotObject.putStack((ItemStack)null);

 

}

else {

slotObject.onSlotChanged();

}

 

if(stackInSlot.stackSize == itemstack.stackSize) {

return null;

}

slotObject.onPickupFromSlot(player, stackInSlot);

}

return itemstack;

 

}

 

 

Link to comment
Share on other sites

[sOLVED]

 

The problem was i had too much code :)

I had some left over code after bug ficxing an Item duplication bug (i put 9 slots in a 2 slot GUI).

Fixed it now.

 

In my Container class i have removed the following lines

 

 

 

if (!this.mergeItemStack(stackInSlot, 31, 40, false)) {

return null;

}

else if (par2 >= 31 && par2 < 40

&& !this.mergeItemStack(stackInSlot, 4, 31, false)) {

return null;

}

else if (!this.mergeItemStack(stackInSlot, 4, 40, false)) {

return null;

}

else if (par2 >= 30 && par2 < 39 && !this.mergeItemStack(stackInSlot, 3, 30, false))

    {

    return null;

    }

 

 

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Yes... You're right, this mod conflicts with very many other mods causing this error.
    • Hi, the microphone mod is not working on my Mac. It says “launcher does not support MacOS microphone permissions” Thank you in advance for answering.
    • Make sure you have Optifine installed as a mod. Go into Options > Video Settings > Shaders > and then click the shader you want Make sure the shader.zip files are in the shaderpacks folder inside the minecraft folder
    • It sounds like you're probably registering the item in the wrong place, try looking at this tutorial for how to register items:  Forge Modding Tutorial - Minecraft 1.20: Custom Items & Creative Mode Tab | #2 This (free) tutorial series is excellent, by the way, and I'd highly recommend watching through some or all of the videos. There may also be an error in the code I showed above since I was in a hurry, but it should be enough for the general idea. I can't be more specific since I don't know exactly what you plan to do.
    • Realizing I was a victim of a scam was a devastating blow. My initial investment of $89,000, driven by dreams of financial success and the buzz surrounding a new cryptocurrency project, turned into a nightmare. The project promised high returns and rapid gains, attracting many eager investors like myself. However, as time passed and inconsistencies began to surface, it became evident that I had made a grave mistake by not thoroughly vetting the brokerage company handling the investment. Feeling anxious and betrayed, I desperately searched for a way to recover my funds. It was during this frantic search that I stumbled upon the Lee Ultimate Hacker tool through a Facebook post. With little left to lose, I decided to reach out to their team for help. To my relief, they were quick to respond and immediately started recovering my compromised email and regaining access to my cryptocurrency wallets. The team at Lee Ultimate Hacker was incredibly professional and transparent throughout the process. They meticulously traced the digital footprints left by the scammers, employing advanced technological methods to unravel the complex network that had ensnared my funds. Their expertise in cybersecurity and recovery strategies gradually began to turn the tide in my favor. Although the scammers had already siphoned off $30,000 worth of Bitcoin, Lee Ultimate Hacker was relentless in their pursuit. They managed to expose the fraudulent activities of the scam operators, revealing their identities and the mechanisms they used to lure investors. This exposure was crucial not only for my case but also as a warning to the wider community about the perils of unverified investment schemes. As we progressed, it became a race against time to retrieve the remaining $59,000 before the scammers could vanish completely. Each step forward was met with new challenges, as these criminals constantly shifted tactics and moved their digital assets to evade capture. Nonetheless, the determination and skill of the recovery team kept us hopeful. Throughout this ordeal, I learned the hard value of caution and due diligence in investment, especially within the volatile world of cryptocurrency. The experience has been incredibly taxing, both emotionally and financially, but the support and results provided by Lee Ultimate Hacker have been indispensable. The recovery process is ongoing, and while the final outcome remains uncertain, the progress made so far gives me hope. The battle to recover the full amount of my investment continues, and with the expertise of Lee Ultimate Hacker, I remain optimistic about the eventual recovery of my funds. Their commitment to their clients and proficiency in handling such complex cases truly sets them apart in the field of cyber recovery. LEEULTIMATEHACKER@ AOL. COM   Support @ leeultimatehacker . com.  telegram:LEEULTIMATE   wh@tsapp +1  (715) 314  -  9248     
  • Topics

×
×
  • Create New...

Important Information

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