The Meaning of Life, the Universe, and Everything.
Join Date:
11/10/2012
Posts:
46
Minecraft:
Tenyar97
Member Details
Ok, so I've been through all sorts of ideas in my head, for the last..several days, on how to get something like this to work.
What I'm trying to do:
I'm trying to save the name of an Entity that touches a Tile Entity and have it display as a tool-tip on an item.
What I have so far:
So far I have an item(Clipboard) that saves the X/Y/Z/dim ID to itself via nbt and places a tile entity(tracker block) when right clicked. The tracker block itself is working fine; I can have it save the name and print it, that part is alright. The problem arises when I try to add it to the item's tool-tip.
What I (think) I need:
I need an instance of the World the Tracker Block is in. The addInformation method has a player parameter in it, which I could get a world object from. However it wouldn't help me much if the player and Tracker are in different dimensions, which is very possible.
The only thing that I think may do it that I haven't tried yet is something with packets. I'm fairly sure I could do it with them, but honestly have no idea where to start with them.
How I think the addInformation method will look by the end.
@Override
public void addInformation(ItemStack stack, EntityPlayer player, List toolTip, boolean bool)
{
NBTTagCompound nbt = stack.getTagCompound();
if(stack.getTagCompound() != null && stack.getTagCompound().hasKey("Tracker_Set") && nbt.getBoolean("Tracker_Set"))
{
double x = nbt.getDouble("X");
double y = nbt.getDouble("Y");
double z = nbt.getDouble("Z");
int dim = nbt.getInteger("Dim_ID");
TileEntityTracker trackerBlock = (TileEntityTracker) trackerBlocksWorld.getTileEntity((int) x, (int) y, (int) z);
if(trackerBlock.lastEntityToTouch != null)
{
toolTip.add("The last Entity to collide with me was: " + trackerBlock.lastEntityToTouch.getCommandSenderName() + " at: " + "X: " + x + "," + " Y: " + y + " Z: " + z);
}
}
super.addInformation(stack, player, toolTip, bool);
}
Any advice or ideas would be super appreciated! If packets would be the best choice here, some tips on where to get started would be great, rather than just "Go learn packets."
The Meaning of Life, the Universe, and Everything.
Join Date:
11/10/2012
Posts:
46
Minecraft:
Tenyar97
Member Details
DimensionManager was one of the first things I tried..
Trying it again skipping the advanced pieces of grabbing my Tile entity and focusing on fetching the World object still results on returning null.
@Override
public void addInformation(ItemStack stack, EntityPlayer player, List toolTip, boolean bool)
{
WorldServer dimWorld = DimensionManager.getWorld(0);//World for Overworld
if(dimWorld != null)
{
toolTip.add("World: " + dimWorld.provider.getDimensionName());
}
else
{
toolTip.add("World is null!");
}
super.addInformation(stack, player, toolTip, bool);
}
Standing in the Overworld beside my Tile Entity with my item in hand.
Regarding what you said about there being no guarantee the world would return anything..How would the item/Tile Entity communication be affected if the player holds the item in the Overworld and the tile entity is in The Nether? Assuming, of course, the Tile Entity was loaded by means of something like a ChickenChunks Chunk Loader or Railcraft World Anchor?
I tried your code (the one without tile-entity) and it worked. it showed "World: Overworld".
the second part of code doesn't have any problem.
the first can have an error finding the values. try printing out with System.out.println() the values and check that the values (dimension id in particular) are not null or -1 (don't test it in nether because the nether's dimension id is -1 )
Ok, so I've been through all sorts of ideas in my head, for the last..several days, on how to get something like this to work.
What I'm trying to do:
I'm trying to save the name of an Entity that touches a Tile Entity and have it display as a tool-tip on an item.
What I have so far:
So far I have an item(Clipboard) that saves the X/Y/Z/dim ID to itself via nbt and places a tile entity(tracker block) when right clicked. The tracker block itself is working fine; I can have it save the name and print it, that part is alright. The problem arises when I try to add it to the item's tool-tip.
What I (think) I need:
I need an instance of the World the Tracker Block is in. The addInformation method has a player parameter in it, which I could get a world object from. However it wouldn't help me much if the player and Tracker are in different dimensions, which is very possible.
The only thing that I think may do it that I haven't tried yet is something with packets. I'm fairly sure I could do it with them, but honestly have no idea where to start with them.
How I think the addInformation method will look by the end.
Any advice or ideas would be super appreciated! If packets would be the best choice here, some tips on where to get started would be great, rather than just "Go learn packets."
Thank you!
You can use DimensionManager to get world instance from its dimension ID.
Though if the player, item and block aren't in the same world, there is no guarantee the world, and thus the tile entity, are loaded at all.
DimensionManager was one of the first things I tried..
Trying it again skipping the advanced pieces of grabbing my Tile entity and focusing on fetching the World object still results on returning null.
Standing in the Overworld beside my Tile Entity with my item in hand.
Regarding what you said about there being no guarantee the world would return anything..How would the item/Tile Entity communication be affected if the player holds the item in the Overworld and the tile entity is in The Nether? Assuming, of course, the Tile Entity was loaded by means of something like a ChickenChunks Chunk Loader or Railcraft World Anchor?
I tried your code (the one without tile-entity) and it worked. it showed "World: Overworld".
the second part of code doesn't have any problem.
the first can have an error finding the values. try printing out with System.out.println() the values and check that the values (dimension id in particular) are not null or -1 (don't test it in nether because the nether's dimension id is -1 )
sorry for my bad english I'm Italian