Jump to content

Recommended Posts

Posted

So I am currently working on a block that when placed drops a mid-evil style gate. Eventually it will be able to raise and lower, but currently I simply have the animation working for lowering the gate. I have an integer value called "position" that keeps track of where the gate should be, going from 0 to 16, (0 being not showing 16 being fully down). This all works amazingly well when the gate is first placed, but if I log of the world and then reload it, the blocks suddenly aren't showing. The hit box is still there, but nothing is being rendered. To try and figure this out I added this to the block -

 

@Override
public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9) {
TileEntityGate tile = (TileEntityGate)par1World.getBlockTileEntity(par2, par3, par4);
par5EntityPlayer.addChatMessage("Postion: " + tile.getPosition());

return true;
}

 

With this I found out that this (along with other functions in minecraft) is running twice each time, I have no idea why, but when I right click the block the first time the world is loaded it says, (I waited for the gate to be fully down before right clicking it)

 

"Position: 16"

"Position: 16"

 

Then I closed out of the world, reloaded it and right clicked on one of the gate blocks again. This time I got,

 

"Position: 0"

"Position: 16".

 

Out of curiosity, I then added a breakpoint in the render tile entity for the gate to check the value of "position" there.

When I checked that, it always registers it as 0 (the second time I load the world).

 

I don't know why this function is running twice, I've seen it before on other things and it can be really annoying, but I can tell that even though the second time it says "16" that isn't being passed to the render.

 

So with that very long introduction (very sorry about that, wanted to make sure my issue is understood) is out of the way. My questions are,

 

1. Any idea why position isn't coming up accurately after I reload a world

2. Why some functions are running multiple times and should I worry about it.

 

Oh and just so everyone knows, I have saved position with writeToNBT(), but I'm not 100% sure I'm doing it right, so it is below -

 

@Override
    public void readFromNBT(NBTTagCompound par1NBTTagCompound) {
        super.readFromNBT(par1NBTTagCompound);
        position = par1NBTTagCompound.getInteger("Position");
        extraPosition = par1NBTTagCompound.getInteger("ExtraPosition");
        turnGate = par1NBTTagCompound.getBoolean("TurnGate");
    }
    
    @Override
    public void writeToNBT(NBTTagCompound par1NBTTagCompound) {
        super.writeToNBT(par1NBTTagCompound);
        par1NBTTagCompound.setInteger("Position", position);
        par1NBTTagCompound.setInteger("ExtraPosition", extraPosition);
        par1NBTTagCompound.setBoolean("TurnGate", turnGate);
    }

Posted

you need to implement and override the extra client-side data methods such as:

 

/**
* whenever this TE is freshly sent to a client or marked for update in the world this entire packet will be sent to all tracking player
*/
@Override
public Packet getDescriptionPacket()
  {
  NBTTagCompound tileTag = new NBTTagCompound();
  this.writeToNBT(tileTag);
  return new Packet132TileEntityData(this.xCoord, this.yCoord, this.zCoord, 0, tileTag);
  }

/**
* Called when you receive a TileEntityData packet for the location this
* TileEntity is currently in. On the client, the NetworkManager will always
* be the remote server. On the server, it will be whomever is responsible for 
* sending the packet.
* 
* @param net The NetworkManager the packet originated from 
* @param pkt The data packet
*/
@Override
public void onDataPacket(INetworkManager net, Packet132TileEntityData pkt)
  {
  this.readFromNBT(pkt.customParam1);
  }

 

 

 

Ohh..and gates...check out my mod at ancientwarfare.wikispaces.com  -- I've had both wooden and iron drop-type gates for quite a while.  (might be willing to point you towards some source if you'de like)

Posted

you need to implement and override the extra client-side data methods such as:

 

/**
* whenever this TE is freshly sent to a client or marked for update in the world this entire packet will be sent to all tracking player
*/
@Override
public Packet getDescriptionPacket()
  {
  NBTTagCompound tileTag = new NBTTagCompound();
  this.writeToNBT(tileTag);
  return new Packet132TileEntityData(this.xCoord, this.yCoord, this.zCoord, 0, tileTag);
  }

/**
* Called when you receive a TileEntityData packet for the location this
* TileEntity is currently in. On the client, the NetworkManager will always
* be the remote server. On the server, it will be whomever is responsible for 
* sending the packet.
* 
* @param net The NetworkManager the packet originated from 
* @param pkt The data packet
*/
@Override
public void onDataPacket(INetworkManager net, Packet132TileEntityData pkt)
  {
  this.readFromNBT(pkt.customParam1);
  }

 

 

 

Ohh..and gates...check out my mod at ancientwarfare.wikispaces.com  -- I've had both wooden and iron drop-type gates for quite a while.  (might be willing to point you towards some source if you'de like)

 

Thank you so much sir/mam. I will go look into fixing that right now :-). And I'm hoping to do a lot more then just gates for this mod, but I didn't want to talk about to much of it over the internet. I managed to finish up my gate yesterday and I'm working on the mechanics to raise on lower it, but I'll definitely go check out yours. And if ya don't mind letting me read your source code, that would be amazing, might help me with some of the issues I'd like to change/fix on my gate!

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.