Jump to content

Ghost Item Problem


Moritz

Recommended Posts

Now i have a problem with my Ghost item.

 

It does Dissapier after you relog the game.

 

Here is my code. i did find out which function it is but not directly what directly the problem is.

 

 

Here my Tile Entity. I know it is a tile problem.

package speiger.src.tinychest.common.tileentity.tinychest;

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.network.INetworkManager;
import net.minecraft.network.packet.Packet;
import net.minecraft.network.packet.Packet132TileEntityData;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import cpw.mods.fml.common.FMLLog;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

public class TransDimensionaleTinyChest extends TileEntity implements IInventory
{
public ItemStack[] chest;
public String invName;
public int facing = 0;
public int[] storedItemStackSize = new int[9];
public ItemStack[] ID = new ItemStack[9];
public int sizes;
public int MaxStackSize = 64;
public boolean update = false;

public TransDimensionaleTinyChest(String name, int size)
{
	chest = new ItemStack[(size*3)];
	invName = name;
	sizes = size;
}

@SideOnly(Side.CLIENT)
public int getStorage(int par1)
{
	return (int)storedItemStackSize[par1];
}


@Override
public int getSizeInventory()
{
	return chest.length;
}


    public ItemStack getStackInSlot(int par1)
    {
        return this.chest[par1];
    }


    public ItemStack decrStackSize(int par1, int par2)
    {
        if (this.chest[par1] != null)
        {
            ItemStack var3;

            if (this.chest[par1].stackSize <= par2)
            {
                var3 = this.chest[par1];
                this.chest[par1] = null;
                return var3;
            }
            else
            {
                var3 = this.chest[par1].splitStack(par2);

                if (this.chest[par1].stackSize == 0)
                {
                    this.chest[par1] = null;
                }

                return var3;
            }
        }
        else
        {
            return null;
        }
    }

    
    public ItemStack getStackInSlotOnClosing(int par1)
    {
        if (this.chest[par1] != null)
        {
            ItemStack var2 = this.chest[par1];
            this.chest[par1] = null;
            return var2;
        }
        else
        {
            return null;
        }
    }

    
    public void setInventorySlotContents(int par1, ItemStack par2ItemStack)
    {
        this.chest[par1] = par2ItemStack;

        if (par2ItemStack != null && par2ItemStack.stackSize > this.getInventoryStackLimit())
        {
            par2ItemStack.stackSize = this.getInventoryStackLimit();
        }
    }

    
    public String getInvName()
    {
        return invName;
    }



public boolean isUseableByPlayer(EntityPlayer var1) 
{
	return true;
}


public void openChest() 
{
}

@Override
    public void readFromNBT(NBTTagCompound par1NBTTagCompound)
    {
        super.readFromNBT(par1NBTTagCompound);
        
        NBTTagList var5 = par1NBTTagCompound.getTagList("Items2");
        this.ID = new ItemStack[this.getSizeInventory()];

        for (int var6 = 0; var6 < var5.tagCount(); ++var6)
        {
            NBTTagCompound var7 = (NBTTagCompound)var5.tagAt(var6);
            byte var8 = var7.getByte("Slot2");

            if (var8 >= 0 && var8 < this.ID.length)
            {
                this.ID[var8] = ItemStack.loadItemStackFromNBT(var7);
            }
        }
        
        
        NBTTagList var2 = par1NBTTagCompound.getTagList("Items");
        this.chest = new ItemStack[this.getSizeInventory()];
        for (int var3 = 0; var3 < var2.tagCount(); ++var3)
        {
            NBTTagCompound var4 = (NBTTagCompound)var2.tagAt(var3);
            byte var6 = var4.getByte("Slot");

            if (var6 >= 0 && var6 < this.chest.length)
            {
                this.chest[var6] = ItemStack.loadItemStackFromNBT(var4);
            }
        }
        

        
        for(int i = 0;i<this.storedItemStackSize.length;i++)
        {
        	this.storedItemStackSize[i] = par1NBTTagCompound.getInteger("StoredItems"+i);
        }
        
        facing = par1NBTTagCompound.getInteger("faceing");
        MaxStackSize = par1NBTTagCompound.getInteger("MaxStackSizes");
    }

    /**
     * Writes a tile entity to NBT.
     */
@Override
    public void writeToNBT(NBTTagCompound par1NBTTagCompound)
    {
        super.writeToNBT(par1NBTTagCompound);
        

        
        NBTTagList var5 = new NBTTagList();
        for (int var6 = 0; var6 < this.ID.length; ++var6)
        {
            if (this.ID[var6] != null)
            {
                NBTTagCompound var7 = new NBTTagCompound();
                var7.setByte("Slot2", (byte)var6);
                this.ID[var6].writeToNBT(var7);
                var5.appendTag(var7);
            }
        }
        par1NBTTagCompound.setTag("Items2", var5);
        
        NBTTagList var2 = new NBTTagList();
        for (int var3 = 0; var3 < this.chest.length; ++var3)
        {
            if (this.chest[var3] != null)
            {
                NBTTagCompound var4 = new NBTTagCompound();
                var4.setByte("Slot", (byte)var3);
                this.chest[var3].writeToNBT(var4);
                var2.appendTag(var4);
            }
        }
        par1NBTTagCompound.setTag("Items", var2);
        
        for(int i = 0;i<this.storedItemStackSize.length;i++)
        {
        	par1NBTTagCompound.setInteger("StoredItems"+i, this.storedItemStackSize[i]);
        }
        par1NBTTagCompound.setInteger("faceing", facing);
        par1NBTTagCompound.setInteger("MaxStackSizes", MaxStackSize);
    }

public void closeChest() 
{
}


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

    @Override
public Packet getDescriptionPacket() 
    {
    	NBTTagCompound var1 = new NBTTagCompound();
    	super.writeToNBT(var1);
    	var1.setInteger("faceing", facing);
        for(int i = 0;i<this.storedItemStackSize.length;i++)
        {
        	var1.setInteger("StoredItems"+i, this.storedItemStackSize[i]);
        }
    	return new Packet132TileEntityData(this.xCoord, this.yCoord, this.zCoord, 1, var1);
}

@Override
public void onDataPacket(INetworkManager net, Packet132TileEntityData pkt) 
{
	this.readFromNBT(pkt.customParam1);
}

//Eloraams code (1.2.5)
public void updateBlock()
    {
        int var1 = this.worldObj.getBlockMetadata(this.xCoord, this.yCoord, this.zCoord);
        this.worldObj.markBlockForRenderUpdate(this.xCoord, this.yCoord, this.zCoord);
        markBlockDirty(this.worldObj, this.xCoord, this.yCoord, this.zCoord);
    }

    public void markBlockDirty(World var0, int var1, int var2, int var3)
    {
        if (var0.blockExists(var1, var2, var3))
        {
            var0.getChunkFromBlockCoords(var1, var3).setChunkModified();
        }
    }


@Override
public void updateEntity()
{
	super.updateEntity();
	updateBlock();
	addItems();
	eatItems();
	showItems();
	if(update)
	{
		update = false;
		this.onInventoryChanged();
	}

}

   
//This function is the problem
public void showItems()
{


	for(int i = 0;i<sizes;i++)
	{
		if(ID[i] != null)
		{
			chest[i+(sizes*2)] = new ItemStack(ID[i].itemID, 1, ID[i].getItemDamage());
			update = true;
		}
		else
		{
			chest[i+(sizes*2)] = null;
			update = true;
		}
	}
}


public void eatItems()
{
	for(int i = 0; i<sizes;i++)
	{
		if(storedItemStackSize[i] < MaxStackSize)
		{
			ItemStack current = ID[i];
			if(chest[i] != null)
			{
				if(current != null && chest[i].itemID == current.itemID && chest[i].getItemDamage() == current.getItemDamage())
				{
					if(storedItemStackSize[i] + 1 <= MaxStackSize)
					{
						storedItemStackSize[i]+=1;
						chest[i].stackSize--;
						update = true;
						if(chest[i].stackSize <= 0)
						{
							chest[i] = null;
							update = true;
						}
					}
				}
				else if(current == null)
				{
					ID[i] = new ItemStack(chest[i].getItem(), 1, chest[i].getItemDamage());
					storedItemStackSize[i]+=1;
					chest[i].stackSize--;
					update = true;
					if(chest[i].stackSize <= 0)
					{
						chest[i] = null;
						update = true;
					}
				}
			}
		}
	}
}


public void addItems()
{
	for(int i = 0; i<sizes;i++)
	{
		ItemStack current = ID[i];
		if(current != null)
		{
			if(this.storedItemStackSize[i] > 0)
			{
				if(chest[i+sizes] != null && chest[i+sizes].itemID == current.itemID && chest[i+sizes].getItemDamage() == current.getItemDamage())
				{
					if(chest[i+sizes].stackSize + 1 <= 64 && chest[i+sizes].stackSize + 1 <= chest[i+sizes].getMaxStackSize())
					{
						chest[i+sizes].stackSize++;
						this.storedItemStackSize[i]-=1;
						update = true;
						if(this.storedItemStackSize[i] <= 0)
						{
							ID[i] = null;
							update = true;
						}
					}
				}
				else if(chest[i+sizes] == null)
				{
					chest[i+sizes] = new ItemStack(current.itemID, 1, current.getItemDamage());
					this.storedItemStackSize[i]-=1;
					update = true;
					if(this.storedItemStackSize[i] <= 0)
					{
						ID[i] = null;
						update = true;
					}
				}
			}
		}
	}
}
                
                //This function is will called by my packethandler
public void addStorage(int storage)
{
	int between = 64;

	between *= storage;
	between = between / 2;
	int secand = between / sizes;
	this.MaxStackSize += secand;

}
    
    

}


 

Here an extra video what showes the problem.

 

 

 

i hope you can help me.

 

Speiger.

Link to comment
Share on other sites

Well I see what you mean in the video, not sure exactly what's causing your problem, but what I can tell you is what I know about containers.

 

You do not need packets to sync items from client to server, whatever is placed inside a slot that's inside a container actually gets sync via the container class you have to create for your block.

 

So for instance on your block class file you would have a function called onBlockActivated and inside there you call your gui

you need to setup a guihandler that would switch between server and client and handle the packets for you. Now you most likely got all of this, but the syncing of items in the container takes place via the server side container class.

 

Secondly on your code you have public ItemStack[] chest; and public ItemStack[] ID = new ItemStack[9];

you then set your chest to a sizex3 and I have no idea what that size it suppose that depends on some condition.

 

Now you only still only have 1 container class assuming you are using a guihandler that is used for this and my guess is somewhere in there your container server side class file does not know what to do with all your slots, because it might not be mapped correctly or updated correctly. That woudl explain why once you close your gui and reopen it the gui doesn't display your item, so check inside the server side container file you created for this Tile Entity you will find your answer there.

 

 

Link to comment
Share on other sites

Ghost anything is almost always due to a mismatch between server and client.

When you log on again the server tells the client what it's inventor contains.

 

I'm guessing that you are giving the player the item on the Client side and noth on server/both :P

If you guys dont get it.. then well ya.. try harder...

Link to comment
Share on other sites

Ok my block activate function which has client/server packet inside is only for extending the storage. (MaxStackSize).

That is what my packet handler does.

 

The sizes*3 is the is only the thing what my chest.

I made the same system as ironchest.

The size of the chest has always 3 or you can / 3.

But thats not the problem.

 

Now to the ID thing. The ID stores the id of the item which is iniside of the inifinet extende able storage.

Thats it.

 

Now Mazetars comments:

 

I use an extra slot for the items. And i do block the slot so you can not click on it.

Thats why i could not get items out of my inventory as i opened the big version of the

Transdimensional tiny chest^^"

 

So what could be the problem^^?

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.



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I'm developing a dimension, but it's kinda resource intensive so some times during player teleporting it lags behind making the player phase down into the void, so im trying to implement some kind of pregeneration to force the game loading a small set of chunks in the are the player will teleport to. Some of the things i've tried like using ServerLevel and ServerChunkCache methods like getChunk() dont actually trigger chunk generation if the chunk isn't already on persistent storage (already generated) or placing tickets, but that doesn't work either. Ideally i should be able to check when the task has ended too. I've peeked around some pregen engines, but they're too complex for my current understanding of the system of which I have just a basic understanding (how ServerLevel ,ServerChunkCache  and ChunkMap work) of. Any tips or other classes I should be looking into to understand how to do this correctly?
    • https://mclo.gs/4UC49Ao
    • Way back in the Forge 1.17 days, work started for adding JPMS (Java Platform Module Support) to ModLauncher and ForgeModLoader. This has been used internally by Forge and some libraries for a while now, but mods (those with mods.toml specifically) have not been able to take advantage of it. As of Forge 1.21.1 and 1.21.3, this is now possible!   What is JPMS and what does it mean for modders? JPMS is the Java Platform Module System, introduced in Java 9. It allows you to define modules, which are collections of packages and resources that can be exported or hidden from other modules. This allows for much more fine-tuned control over visibility, cleaner syntax for service declarations and support for sealed types across packages. For example, you might have a mod with a module called `com.example.mod` that exports `com.example.mod.api` and `com.example.mod.impl` to other mods, but hides `com.example.mod.internal` from them. This would allow you to have a clean API for other mods to use, while keeping your internal implementation details hidden from IDE hints, helping prevent accidental usage of internals that might break without prior notice. This is particularly useful if you'd like to use public records with module-private constructors or partially module-private record components, as you can create a sealed interface that only your record implements, having the interface be exported and the record hidden. It's also nice for declaring and using services, as you'll get compile-time errors from the Java compiler for typos and the like, rather than deferring to runtime errors. In more advanced cases, you can also have public methods that are only accessible to specific other modules -- handy if you want internal interactions between multiple of your own mods.   How do I bypass it? We understand there may be drama in implementing a system that prevents mods from accessing each other's internals when necessary (like when a mod is abandoned or you need to fix a compat issue) -- after all, we are already modding a game that doesn't have explicit support for Java mods yet. We have already thought of this and are offering APIs from day one to selectively bypass module restrictions. Let me be clear: Forge mods are not required to use JPMS. If you don't want to use it, you don't have to. The default behaviour is to have fully open, fully exported automatic modules. In Java, you can use the `Add-Opens` and `Add-Exports` manifest attributes to selectively bypass module restrictions of other mods at launch time, and we've added explicit support for these when loading your Forge mods. At compile-time, you can use existing solutions such as the extra-java-module-info Gradle plugin to deal with non-modular dependencies and add extra opens and exports to other modules. Here's an example on how to make the internal package `com.example.examplemod.internal` open to your mod in your build.gradle: tasks.named('jar', Jar) { manifest { attributes([ 'Add-Opens' : 'com.example.examplemod/com.example.examplemod.internal' 'Specification-Title' : mod_id, 'Specification-Vendor' : mod_authors // (...) ]) } } With the above in your mod's jar manifest, you can now reflectively access the classes inside that internal package. Multiple entries are separated with a space, as per Java's official spec. You can also use Add-Exports to directly call without reflection, however you'd need to use the Gradle plugin mentioned earlier to be able to compile. The syntax for Add-Exports is the same as Add-Opens, and instructions for the compile-time step with the Gradle plugin are detailed later in this post. Remember to prefer the opens and exports keywords inside module-info.java for sources you control. The Add-Opens/Add-Exports attributes are only intended for forcing open other mods.   What else is new with module support? Previously, the runtime module name was always forced to the first mod ID in your `mods.toml` file and all packages were forced fully open and exported. Module names are now distinguished from mod IDs, meaning the module name in your module-info.java can be different from the mod ID in your `mods.toml`. This allows you to have a more descriptive module name that doesn't have to be the same as your mod ID, however we strongly recommend including your mod ID as part of your module name to aid troubleshooting. The `Automatic-Module-Name` manifest attribute is now also honoured, allowing you to specify a module name for your mod without needing to create a `module-info.java` file. This is particularly useful for mods that don't care about JPMS features but want to have a more descriptive module name and easier integration with other mods that do use JPMS.   How do I use it? The first step is to create a `module-info.java` file in your mod's source directory. This file should be in the same package as your main mod class, and should look something like this: open module com.example.examplemod { requires net.minecraftforge.eventbus; requires net.minecraftforge.fmlcore; requires net.minecraftforge.forge; requires net.minecraftforge.javafmlmod; requires net.minecraftforge.mergetool.api; requires org.slf4j; requires logging; } For now, we're leaving the whole module open to reflection, which is a good starting point. When we know we want to close something off, we can remove the open modifier from the module and open or export individual packages instead. Remember that you need to be open to Forge (module name net.minecraftforge.forge), otherwise it can't call your mod's constructor. Next is fixing modules in Gradle. While Forge and Java support modules properly, Gradle does not put automatic modules on the module path by default, meaning that the logging module (from com.mojang:logging) is not found. To fix this, add the Gradle plugin and add a compile-time module definition for that Mojang library: plugins { // (...) id 'org.gradlex.extra-java-module-info' version "1.9" } // (...) extraJavaModuleInfo { failOnMissingModuleInfo = false automaticModule("com.mojang:logging", "logging") } The automatic module override specified in your build.gradle should match the runtime one to avoid errors. You can do the same for any library or mod dependency that is missing either a module-info or explicit Automatic-Module-Name, however be aware that you may need to update your mod once said library adds one. That's all you need to get started with module support in your mods. You can learn more about modules and how to use them at dev.java.
    • Faire la mise à jour grâce à ce lien m'a aider personnellement, merci à @Paint_Ninja. https://www.amd.com/en/support 
    • When I came across the 'Exit Code: I got a 1 error in my Minecraft mods, so I decided to figure out what was wrong. First, I took a look at the logs. In the mods folder (usually where you'd find logs or crash reports), I found the latest.log file or the corresponding crash report. I read it through carefully, looking for any lines with errors or warnings. Then I checked the Minecraft Forge support site, where you can often find info on what causes errors and how to fix them. I then disabled half of my mods and tried running the game. If the error disappeared, it meant that the problem was with the disabled mod. I repeated this several times to find the problem mod.
  • Topics

×
×
  • Create New...

Important Information

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