Ok, I know how to get the ID of a block, but say I wanted to add some properties to a block. when that block is placed I want to set one of the properties. How do I get the block as in:
Block aBlock = new BlockTest(x,y,z) or what ever. I know the location it's put, how do I access the block instance?
Do you mean "Block.blocksList[world.getBlockId(x, y, z)]"?
Rollback Post to RevisionRollBack
I had a mod back in Beta 1.8.1, but I quit for a while so it hasn't been updated since then. WTF <-- If you'd like to try and update it, let me know. (It won't be an easy task, I'm sure)
What do you want to add? You have to be more specific.
Usually you add all that stuff here though:
public static final Block BlockvbHay = new BlockvbHay(255,0, hayTop, haySide).setHardness(0.2F).setResistance(0.1F).setBlockName("BlockvbHay");
I keep it all on one line just to keep things tidy. I am not 100% sure but I think you can add those properties inline on the block, too.
Well, I want to do more than what is defined by the basic extend block. I have that set. But in my block class I want to have the block do other things that don't seem to be defined by the Block class.
For instance, when placing the block in game (this is the only what I know how to do this):
But how would I, say, change boolean variable that I created in the myBlock class after it was placed if a specific criteria was met. Usually I would find the instance doing something like this:
MyBlock aBlock = new Myblock(i, j);
but this does not find the block I just placed. And with the world object, I can only get the ID of a block by co-ordinates, or so I understand. Is there a way to get that block instance?
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLiving player)
{
// do stuff
}
I could do that but I can pass no parameters to it. One of the things I was trying to do was to manage my trees on my own. That way I could control the tree size (by age) as well as how much fruit it would bear. Mostly, I was trying to use one wood class and one leaves class to manage several trees, based on the type of seed used to grow it. So when the seed is used, I want to pass it the seed type so I could set the fruit type to start with. I would be carrying this over to my crop list as well. If not, I would have to be adding 2 blocks each for trees to the overal block count. Don't want to do that if I don't have to,
I could do that but I can pass no parameters to it. One of the things I was trying to do was to manage my trees on my own. That way I could control the tree size (by age) as well as how much fruit it would bear. Mostly, I was trying to use one wood class and one leaves class to manage several trees, based on the type of seed used to grow it. So when the seed is used, I want to pass it the seed type so I could set the fruit type to start with. I would be carrying this over to my crop list as well. If not, I would have to be adding 2 blocks each for trees to the overal block count. Don't want to do that if I don't have to,
Use metadata. This is how Wool, Logs, Leaves, Saplings, and Dyes work (there may be more, but I'm too tired to remember them all).
When you set a block, you can set it's metadata as well.
world.setBlockMetadataWithNotify(x, y, z, metadata)
Rollback Post to RevisionRollBack
I had a mod back in Beta 1.8.1, but I quit for a while so it hasn't been updated since then. WTF <-- If you'd like to try and update it, let me know. (It won't be an easy task, I'm sure)
As the guy above said, you use metadata. Blocks are actually (psuedo-)singletons, there is only one instance of Block for the world. Every block of stone you see is a reference back to that same instance of Block (or whatever subclass of it smoothstone is, I don't know offhand).
You have four bits of metadata to play with per block. You can use these to do whatever you want, and it's how Minecraft has things like different leaf textures and furnaces facing different directions.
If that's not enough, you need a TileEntity. TileEntities are one instance per block, like what you're thinking Blocks are, but they're more expensive performance-wise due to that fact. Anything with an inventory (crafting bench, furnace, etc) is a TileEntity. So are pistons, I believe.
e: you could also use Forge, which gives you (I believe) 12 bits of metadata. I haven't used this so I'm not sure how it works.
Great! this is what I am looking for. I am realtively new to java, and most modern programming (been out of coding for a large part of my life), and even then, I didn't go that far.
Any tips on where to start with this? Never played with bits before (knowingly). Each bit is 1 or 0, so I would need to use multiple to set more than 2 states? At least that would give me the type, maybe age too...
Well the game just provides an int type value, but only values 0-15 are meaningful (again, assuming you aren't using forge). If you set 16 or higher I'm not sure what would happen. You may want to read up on bitwise operations if this is new to you. You also may want to look at http://www.minecraftwiki.net/wiki/Data_values which lists what the metadata values do for existing blocks, which may help you understand what to do with them.
Well the game just provides an int type value, but only values 0-15 are meaningful (again, assuming you aren't using forge). If you set 16 or higher I'm not sure what would happen. You may want to read up on bitwise operations if this is new to you. You also may want to look at http://www.minecraftwiki.net/wiki/Data_values which lists what the metadata values do for existing blocks, which may help you understand what to do with them.
Awesome! So they are Hex bits? 0-15. So in theory I can set these values and test them for what ever I need? So I can have a listing of 16 different tree types, and based off of what the bit is set to I can have it bear one of 16 fruit types? Ok, this is starting to move for me. Thanks a lot. This is assuming that I can use the value for what I need (not the game engine making assumptions on values I set).
Just a quick look at the BlockLog code:
public int getBlockTextureFromSideAndMetadata(int i, int j)
{
if(i == 1)
{
return 21;
}
if(i == 0)
{
return 21;
}
if(j == 1)
{
return 116;
}
return j != 2 ? 20 : 117;
}
So I could do the same and check for what type and pass it to the leaves, which in turn can bear the proper fruit on a tick count or some other criteria. In theory?
Awesome! So they are Hex bits? 0-15. So in theory I can set these values and test them for what ever I need? So I can have a listing of 16 different tree types, and based off of what the bit is set to I can have it bear one of 16 fruit types? Ok, this is starting to move for me. Thanks a lot. This is assuming that I can use the value for what I need (not the game engine making assumptions on values I set).
Just a quick look at the BlockLog code:
[snip]
So I could do the same and check for what type and pass it to the leaves, which in turn can bear the proper fruit on a tick count or some other criteria. In theory?
"Hex bits" is kind of a misnomer, hex is just a different way of expressing a number. They do conveniently wind up in the same range as one hex character though, yes.
Minecraft itself will not touch your metadata unless you inherit from a block type that already does make use of it (like say, BlockRail uses it to control track orientation). You're free to do whatever to it whenever. You'll want to keep world.getBlockMetadata() and world.setBlockMetadataWithNotify() in mind if you need to interact with it beyond just being given it as a method argument. So yes, you could on a tick check the metadata of your leaf block and use it to pick what fruit to create :smile.gif:
"Hex bits" is kind of a misnomer, hex is just a different way of expressing a number. They do conveniently wind up in the same range as one hex character though, yes.
Minecraft itself will not touch your metadata unless you inherit from a block type that already does make use of it (like say, BlockRail uses it to control track orientation). You're free to do whatever to it whenever. You'll want to keep world.getBlockMetadata() and world.setBlockMetadataWithNotify() in mind if you need to interact with it beyond just being given it as a method argument. So yes, you could on a tick check the metadata of your leaf block and use it to pick what fruit to create :smile.gif:
This is perfect. Thanks for the detailed help and links. I'm sure I can do what I am hoping now. Thanks again!
This is perfect. Thanks for the detailed help and links. I'm sure I can do what I am hoping now. Thanks again!
In case anyone wanted to see what I was up to, my mod will be able to generate 4 tree types using just 1 block for the log, and 1 block for the leaves. I won't adjust the textures, but I did play with the colors:
All 4 trees (red, orange, purple and yellow) are from the same WorldGenTree, using the same blocks. I check the last 2 bits (& 3) to see what type of tree it will be. My next step is to have it produce (from the leaves) different fruit, though I don't see that as being an issue, since I can do this much already. I'm intending to make a few indistructable blocks for my town in my mod, so saving on blocks (with the current limit) is a good idea.
Also, this idea will carry over to crops, so I can make 1 seed item manage several types of crops. I'm intending for the fruit to work the same way, though this may be a bad idea if I go with some new food recipes...
Also, this idea will carry over to crops, so I can make 1 seed item manage several types of crops. I'm intending for the fruit to work the same way, though this may be a bad idea if I go with some new food recipes...
Uh, why would that be a bad idea? You can craft with metadata/damage values easily. You can't smelt with damage values though; you need to use Forge to get that to work as Minecraft doesn't support it.
Block aBlock = new BlockTest(x,y,z) or what ever. I know the location it's put, how do I access the block instance?
OLD 1.7: http://www.minecraftforum.net/topic/529327-modloader173-adding-custom-mobs-and-more/ ---inLanoche says : USE ECLIPSE
OLD 1.7: http://www.minecraftforum.net/topic/529327-modloader173-adding-custom-mobs-and-more/ ---inLanoche says : USE ECLIPSE
Usually you add all that stuff here though:
I keep it all on one line just to keep things tidy. I am not 100% sure but I think you can add those properties inline on the block, too.
I had a mod back in Beta 1.8.1, but I quit for a while so it hasn't been updated since then.
WTF <-- If you'd like to try and update it, let me know. (It won't be an easy task, I'm sure)
Well, I want to do more than what is defined by the basic extend block. I have that set. But in my block class I want to have the block do other things that don't seem to be defined by the Block class.
For instance, when placing the block in game (this is the only what I know how to do this):
But how would I, say, change boolean variable that I created in the myBlock class after it was placed if a specific criteria was met. Usually I would find the instance doing something like this:
but this does not find the block I just placed. And with the world object, I can only get the ID of a block by co-ordinates, or so I understand. Is there a way to get that block instance?
OLD 1.7: http://www.minecraftforum.net/topic/529327-modloader173-adding-custom-mobs-and-more/ ---inLanoche says : USE ECLIPSE
I could do that but I can pass no parameters to it. One of the things I was trying to do was to manage my trees on my own. That way I could control the tree size (by age) as well as how much fruit it would bear. Mostly, I was trying to use one wood class and one leaves class to manage several trees, based on the type of seed used to grow it. So when the seed is used, I want to pass it the seed type so I could set the fruit type to start with. I would be carrying this over to my crop list as well. If not, I would have to be adding 2 blocks each for trees to the overal block count. Don't want to do that if I don't have to,
OLD 1.7: http://www.minecraftforum.net/topic/529327-modloader173-adding-custom-mobs-and-more/ ---inLanoche says : USE ECLIPSE
Use metadata. This is how Wool, Logs, Leaves, Saplings, and Dyes work (there may be more, but I'm too tired to remember them all).
When you set a block, you can set it's metadata as well.
I had a mod back in Beta 1.8.1, but I quit for a while so it hasn't been updated since then.
WTF <-- If you'd like to try and update it, let me know. (It won't be an easy task, I'm sure)
You have four bits of metadata to play with per block. You can use these to do whatever you want, and it's how Minecraft has things like different leaf textures and furnaces facing different directions.
If that's not enough, you need a TileEntity. TileEntities are one instance per block, like what you're thinking Blocks are, but they're more expensive performance-wise due to that fact. Anything with an inventory (crafting bench, furnace, etc) is a TileEntity. So are pistons, I believe.
e: you could also use Forge, which gives you (I believe) 12 bits of metadata. I haven't used this so I'm not sure how it works.
INFORMATION WANTS TO BE WRONG
Any tips on where to start with this? Never played with bits before (knowingly). Each bit is 1 or 0, so I would need to use multiple to set more than 2 states? At least that would give me the type, maybe age too...
OLD 1.7: http://www.minecraftforum.net/topic/529327-modloader173-adding-custom-mobs-and-more/ ---inLanoche says : USE ECLIPSE
INFORMATION WANTS TO BE WRONG
Awesome! So they are Hex bits? 0-15. So in theory I can set these values and test them for what ever I need? So I can have a listing of 16 different tree types, and based off of what the bit is set to I can have it bear one of 16 fruit types? Ok, this is starting to move for me. Thanks a lot. This is assuming that I can use the value for what I need (not the game engine making assumptions on values I set).
Just a quick look at the BlockLog code:
So I could do the same and check for what type and pass it to the leaves, which in turn can bear the proper fruit on a tick count or some other criteria. In theory?
OLD 1.7: http://www.minecraftforum.net/topic/529327-modloader173-adding-custom-mobs-and-more/ ---inLanoche says : USE ECLIPSE
"Hex bits" is kind of a misnomer, hex is just a different way of expressing a number. They do conveniently wind up in the same range as one hex character though, yes.
Minecraft itself will not touch your metadata unless you inherit from a block type that already does make use of it (like say, BlockRail uses it to control track orientation). You're free to do whatever to it whenever. You'll want to keep world.getBlockMetadata() and world.setBlockMetadataWithNotify() in mind if you need to interact with it beyond just being given it as a method argument. So yes, you could on a tick check the metadata of your leaf block and use it to pick what fruit to create :smile.gif:
INFORMATION WANTS TO BE WRONG
This is perfect. Thanks for the detailed help and links. I'm sure I can do what I am hoping now. Thanks again!
OLD 1.7: http://www.minecraftforum.net/topic/529327-modloader173-adding-custom-mobs-and-more/ ---inLanoche says : USE ECLIPSE
In case anyone wanted to see what I was up to, my mod will be able to generate 4 tree types using just 1 block for the log, and 1 block for the leaves. I won't adjust the textures, but I did play with the colors:
All 4 trees (red, orange, purple and yellow) are from the same WorldGenTree, using the same blocks. I check the last 2 bits (& 3) to see what type of tree it will be. My next step is to have it produce (from the leaves) different fruit, though I don't see that as being an issue, since I can do this much already. I'm intending to make a few indistructable blocks for my town in my mod, so saving on blocks (with the current limit) is a good idea.
Also, this idea will carry over to crops, so I can make 1 seed item manage several types of crops. I'm intending for the fruit to work the same way, though this may be a bad idea if I go with some new food recipes...
OLD 1.7: http://www.minecraftforum.net/topic/529327-modloader173-adding-custom-mobs-and-more/ ---inLanoche says : USE ECLIPSE
Uh, why would that be a bad idea? You can craft with metadata/damage values easily. You can't smelt with damage values though; you need to use Forge to get that to work as Minecraft doesn't support it.
PS those trees actually look pretty cool.
INFORMATION WANTS TO BE WRONG
link: The Dragon Ball Mod Alpha 1.1