Hello, I am currently working on a quite a quite ambitious mod. I won't get into the details but I am dropping metadata blocks when my block is broken.
However I also want to add an NBT Tag in order to provide a feeling of differences in the items you acquire. I am going to be doing that by making each chunk give different results for the NBT.
Say chunk A gives a hard but weak stone. But chunk B gives a stone that's hard strong and has the special attribute of being able to make fire.
Then I noticed I had a problem: I had no idea of how to figure out the chunk my block is in when it is broken without editing base classes.
I would like to ask if you can help me or redirect me to a site I can find code for such a thing. If you know of a more efficient method, feel free to tell me with valid reasons.
Um, how would I g about implementing it into this:
public static final String[] names = new String[] {"first", "second"};
public String getUnlocalizedName(ItemStack par1ItemStack)
{
int i = MathHelper.clamp_int(par1ItemStack.getItemDamage(), 0, 15);
return super.getUnlocalizedName() + "." + names[i];
}
public void onCreated(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) {
if( par1ItemStack.stackTagCompound == null )
par1ItemStack.setTagCompound( new NBTTagCompound( ) );
int h = GetRockFromChunk();
par1ItemStack.stackTagCompound.setInteger( "Hardness: ", h );
}
public int GetRockFromChunk(World world) {
return 0;
}
The portion that returns 0 is supposed to be where I execute my chunk finding and utilizing
I think you want to use the onBlockAdded() method instead of onCreated(), something like this:
public void onBlockAdded(World par1World, int par2, int par3, int par4)
{
** your code**
int h = GetRockFromChunk(par1World, par2, par4);
** your code**
}
And then your method would look like this:
public int GetRockFromChunk(World world, int x, int z) {
Chunk chunk = world.getChunkFromBlockCoords(x, z);
** your code **
return 0;
}
You can use chunk.xPosition and chunk.zPosition to determine exactly which chunk it is.
Small Problem: It's not a block that gets NBT data, it's the item. What I mean is when I break a block an item is created. So onBlockAdded() would be not so helpful. Any suggestions?
/**
* This returns a complete list of items dropped from this block.
*
* @param world The current world
* @param x X Position
* @param y Y Position
* @param z Z Position
* @param metadata Current metadata
* @param fortune Breakers fortune level
* @return A ArrayList containing all items this block drops
*/
public ArrayList<ItemStack> getBlockDropped(World world, int x, int y, int z, int metadata, int fortune)
{
ArrayList<ItemStack> ret = new ArrayList<ItemStack>();
int count = quantityDropped(metadata, fortune, world.rand);
for(int i = 0; i < count; i++)
{
int id = idDropped(metadata, world.rand, fortune);
if (id > 0)
{
ret.add(new ItemStack(id, 1, damageDropped(metadata)));
}
}
return ret;
}
If I understand correctly, you want to check the NBT data, then use that to determine the item that's dropped? Where are you planning on storing the NBT data?
Sorry for the confusion. I was trying to be quick and to the point. I want to break the block, then when the item drops it checks what chunk it is in and runs a process to get stored information corresponding to the chunk it is in and place it in the NBT data of said item. Basically, I want it so that the item has different NBT data based on the chunk it first spawns in. Additionally, if an item is created in a chunk with data not yet stored- aka any chunk that has not had the item spawned into before -a variable is formed randomly with controls being it's biome, surrounding biomes and surrounding chunks.
So basically here are the steps:
GetBlockFromChunk
1. Break block
2. Item created
3. If item already has custom NBT, return
4. NBT is collected from a stored variable based on the item's chunk location
4a. If chunk does not yet have a variable, call GetChunkVar
5. Apply NBT
GetChunkVar
1. Check surrounding Chunks' variables
2. Check current Biome
3. Check surrounding Biomes
4. Create variable for Chunk
5. return
Okay, the chunk variable is something you're creating? I don't know of any way to store custom data within a chunk, unless maybe through creating your own custom Chunk Handler. Never done it myself though, so I can't say if it's possible that way. You could created your own class extension of WorldSavedData, and store your chunk variable there, along with the chunk's coordinates.
Depending on how it's all calculated, you might be able to get away with doing everything within the Item's class.
I'm going to have an array of variables with two identification values. The X and Y of the chunk will match up with the values, thus I'm just using the chunk's location as a guide. They will really be stored elcewhere.
However I also want to add an NBT Tag in order to provide a feeling of differences in the items you acquire. I am going to be doing that by making each chunk give different results for the NBT.
Say chunk A gives a hard but weak stone. But chunk B gives a stone that's hard strong and has the special attribute of being able to make fire.
Then I noticed I had a problem: I had no idea of how to figure out the chunk my block is in when it is broken without editing base classes.
I would like to ask if you can help me or redirect me to a site I can find code for such a thing. If you know of a more efficient method, feel free to tell me with valid reasons.
Thank you for your time.
Kill two stones with one bird whenever possible
Kill two stones with one bird whenever possible
public String getUnlocalizedName(ItemStack par1ItemStack)
{
int i = MathHelper.clamp_int(par1ItemStack.getItemDamage(), 0, 15);
return super.getUnlocalizedName() + "." + names[i];
}
public void onCreated(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) {
if( par1ItemStack.stackTagCompound == null )
par1ItemStack.setTagCompound( new NBTTagCompound( ) );
int h = GetRockFromChunk();
par1ItemStack.stackTagCompound.setInteger( "Hardness: ", h );
}
public int GetRockFromChunk(World world) {
return 0;
}
The portion that returns 0 is supposed to be where I execute my chunk finding and utilizing
Kill two stones with one bird whenever possible
And then your method would look like this:
You can use chunk.xPosition and chunk.zPosition to determine exactly which chunk it is.
Kill two stones with one bird whenever possible
If I understand correctly, you want to check the NBT data, then use that to determine the item that's dropped? Where are you planning on storing the NBT data?
So basically here are the steps:
GetBlockFromChunk
1. Break block
2. Item created
3. If item already has custom NBT, return
4. NBT is collected from a stored variable based on the item's chunk location
4a. If chunk does not yet have a variable, call GetChunkVar
5. Apply NBT
GetChunkVar
1. Check surrounding Chunks' variables
2. Check current Biome
3. Check surrounding Biomes
4. Create variable for Chunk
5. return
Thank you for your time
Kill two stones with one bird whenever possible
Depending on how it's all calculated, you might be able to get away with doing everything within the Item's class.
Kill two stones with one bird whenever possible
Kill two stones with one bird whenever possible