Jump to content

[Solved]Help With TileEntity Render Not updating only in offhand


Recommended Posts

Posted (edited)

Fixed the server was sending the wrong blockstate packets when the main hand failed to place the block thus resetting any additional tile entity data thrown. Evil Notch Lib snasphot 65 fixes this

I am replacing the method of ItemBlock class successfully with correct output as this is what gets replaced tested with decompile the bytes I returned and deobfuscated.

That being said here is the code it works just fine in the main hand but, when you have the offhand it no longer works. The code should all be the same with the exception of my custom forge events which I don't implement. I don't have any if statements for the hand.

Issue: renders horse for 1 tick then goes back to being a pig. The tile entity readFromNBT() specifically states that it is horse at the time. If go out and come back it renders the horse right

Expected Result: it stay as horse spawner.

 

Steps to reproduce:
/give @p mob_spawner 1 0 {BlockEntityTag:{SpawnData:{id:horse},Delay:10000 }}
you can printline and observe it did in fact readFromNBT() but, for some reason next tick it decides to go pig. If you printlined you noticed it fired once on both client and server like normal yet no updates. Something is resetting my mob spawner to pig from horse.
 

    public static boolean setTileEntityNBT(World worldIn, @Nullable EntityPlayer player, BlockPos pos, ItemStack stackIn)
    {
    	NBTTagCompound stack = stackIn.getSubCompound("BlockEntityTag");
    	return setTileNBT(worldIn,player,pos,stackIn,stack,true);
    }
    public static boolean setTileNBT(World worldIn, @Nullable EntityPlayer player, BlockPos pos, ItemStack stackIn,NBTTagCompound stack,boolean blockData)
    {
        if (stack != null)
        {
        	stack = stack.copy();//prevents this from being modified on the itemstack's nbt when firing the pre event
            TileEntity tileentity = worldIn.getTileEntity(pos);
            if (tileentity != null)
            {
            	 TileStackSyncEvent.Permissions permissions = new TileStackSyncEvent.Permissions(stackIn,pos,tileentity,player,worldIn,blockData);
            	 MinecraftForge.EVENT_BUS.post(permissions);
                 //allow mods to override the tile entity ops only as well as player can use command
            	 if (permissions.opsOnly && !permissions.canUseCommand)
                 {
                     return false;
                 }

                 NBTTagCompound tileData = tileentity.writeToNBT(new NBTTagCompound());
                 NBTTagCompound copyTile = tileData.copy();
                 
                 TileStackSyncEvent.Pre mergeEvent = new TileStackSyncEvent.Pre(stackIn,pos,tileentity,player,worldIn,blockData,tileData,stack);
                 MinecraftForge.EVENT_BUS.post(mergeEvent);
                 tileData = mergeEvent.tileData;
                 stack = mergeEvent.nbt;
                 
                 tileData.merge(stack);
                 tileData.setInteger("x", pos.getX());
                 tileData.setInteger("y", pos.getY());
                 tileData.setInteger("z", pos.getZ());

                 if (!tileData.equals(copyTile))
                 {
                    tileentity.readFromNBT(tileData);
                    tileentity.markDirty();
                    IBlockState state = worldIn.getBlockState(pos);
                    worldIn.notifyBlockUpdate(pos, state.getBlock().getDefaultState(), state, 3);
                    if(tileentity instanceof TileEntityMobSpawner && !stack.hasKey("SpawnPotentials"))
                    {
                    	TileEntityMobSpawner spawner = (TileEntityMobSpawner)tileentity;
                    	if(worldIn.isRemote)
                       	 System.out.println("readingFromNBT:" + (spawner.getSpawnerBaseLogic().getCachedEntity().getClass().getName()) );
                    	List list = (List) ReflectionUtil.getObject(spawner.getSpawnerBaseLogic(), MobSpawnerBaseLogic.class, FieldAcess.potentialSpawns);
                     	list.clear();
                    }
                    TileStackSyncEvent.Post event = new TileStackSyncEvent.Post(stackIn,pos,tileentity,player,worldIn,blockData);
                    MinecraftForge.EVENT_BUS.post(event);
                    if(worldIn.isRemote)
                    	SPacketUpdateTileEntity.toIgnore.add(pos);
                    return true;
                 }
            }
         }
         
        return false;
    }


I tested this using a spawner. Now my code says to ignore the next readFromNBT() packet on the client side because it already read it from nbt once. My question to you is why is it still pig in only the offhand?

Packet Method re-written:
 

    /**
     * Passes this Packet on to the NetHandler for processing.
     */
    public void processPacket(INetHandlerPlayClient handler)
    {
    	if(this.toIgnore.contains(this.blockPos))
    	{
    		//System.out.println("Ignoring packet for tile:" + this.blockPos);
    		this.toIgnore.remove(this.blockPos);
    		return;
    	}
        handler.handleUpdateTileEntity(this);
    }



If necessary to prove no other asm is causing this I am willing to setup a new workspace

Edited by jredfox
Posted
6 hours ago, jredfox said:

so does anybody know why mc thinks that it's resetting the tile entity to a pig right after it renders properly for a tick?

Have u tried the debugger? Is the spawned data synced between client & server?

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

Have u tried the debugger? Is the spawned data synced between client & server?

the code fires on both sides client and server since I don't stop it. I copied it from 1.8 and then modified it slightly and added the ability for events to fire which just by itself does 1.8 code. Spawners can now render random entities onInitialSpawn() during the spawner to ignore the next readFromNBT() sent by the server after the initial client one. On the main hand it works on the offhand it does not. if 1.8 code had onInitialSpawn() twice it would flash two different entity models usually for horses as an example.

I also confirmed the result is successful during the readFromNBT(),setTileNBT() and the useItem() fired twice so what am I missing here? 

Could you give me some idea of some classes that could have something else to do with post placement? I need more debugging but, I would assume A: it's not rendering updating or B: there is something resetting the mob spawner immediately after my placement

A quickfix would be to let the models flash twice or simply don't render until the server gets data. But, this would be an issue with other things like signs rendering wrong and flashing text and mods would look way worse imagine AE2 placement between red and blue or something.

Edited by jredfox
Posted (edited)
7 hours ago, Cadiboo said:

Have u tried the debugger? Is the spawned data synced between client & server?

So after 2 hours of solid debugging again at a random chance I think I found the answer but, no solution. If the tileentity is placed from the offhand something is replacing it with another tile entity as if it had gotten deleted.
 

	System.out.println(ItemBlock.lastTile == Minecraft.getMinecraft().world.getTileEntity(ItemBlock.lastTile.getPos()));

Output:
false

that means the memory location isn't the same as the tile entity last placed. What do I do why is this happening what is happening post placement logic only happening when you place it in the offhand that is causing this? I also tested in the main hand the same thing occurred there were two tile entities at the same pos the only difference being is one is pig.

What packets that are sent from the server send tile entities because it's sending the wrong data somehow?

For the actual issue of why it's sending a pig spawner as the 2d tile entity in the same block is unkown to me.

Edited by jredfox
Posted

so what is the difference between client and server sync when you use the offhand. I debugged another 8 hours looked at 30+ more classes and can't figure out why it's rendering a pig. My best guess is something is setting the block state wrong or tile entity if and only if it's your offhand.

please help.

Posted
12 hours ago, jredfox said:

so what is the difference between client and server sync when you use the offhand. I debugged another 8 hours looked at 30+ more classes and can't figure out why it's rendering a pig. My best guess is something is setting the block state wrong or tile entity if and only if it's your offhand.

please help.

I assume your working backwards? Setting a breakpoint when it’s rendering a pig then following it back?

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
2 hours ago, Cadiboo said:

I assume your working backwards? Setting a breakpoint when it’s rendering a pig then following it back?

I eventually figured out there is a third tile entity setting into the client world only if the player places it using the offhand. It could be related to these packets always being sent twice
 

        	this.player.connection.sendPacket(new SPacketBlockChange(worldserver, blockpos));
        	this.player.connection.sendPacket(new SPacketBlockChange(worldserver, blockpos.offset(enumfacing)));

 

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



×
×
  • Create New...

Important Information

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