Anyway, why not just use one of the 0-15 metadata values as both a state and an indicator of your state?
Unless there's something I don't know, you should be able to just set the metadata of the block to 1 when there's a powered block/entity next to it, then just use that metadata for your changing textures as well.
If you want to use a boatload of textures or states, just save the "extended metadata" using readtonbt and writetonbt.
---Of course this is assuming I know what you all are talking about.
The Meaning of Life, the Universe, and Everything.
Join Date:
10/26/2014
Posts:
205
Minecraft:
TheBoeing767fan
Member Details
I did that initially (except for the NBT bit, I need to do more research on that) however the metadata also controls the rotation of the block. For instance, when the block is facing east, the metadata is say 3. I always believed you can only use the metadata for one thing at a time such as defining a texture, sub-block, or a rotation. Correct me if I'm wrong about this I still have a lot to learn.
I did that initially (except for the NBT bit, I need to do more research on that) however the metadata also controls the rotation of the block. For instance, when the block is facing east, the metadata is say 3. I always believed you can only use the metadata for one thing at a time such as defining a texture, sub-block, or a rotation. Correct me if I'm wrong about this I still have a lot to learn.
Cheers!
Yes, each metadata value can only represent one state. And that state can represent any one combination of sub-states - including texture, rotation and whatever other state you can think of.
Essentially, each combination of data you store inside a tile entity has its own metadata value. It just depends on what you call it (or them). Also, it's not limited to 16 states. It's more like 32,768 states, so if you just want to go off an integer value, you can define your metadata for all your standard states (not powered), then define the same number of metadata for all the powered states. You can use getBlockPowerInput like Ferdz said to do this. Just make sure you save the metadata in your TE class correctly:
public void writeToNBT(NBTTagCompound NBTTC)
{
super.writeToNBT(NBTTC);
NBTTC.setInteger("Data", this.blockMetadata);
}
public void readFromNBT(NBTTagCompound NBTTC)
{
super.readFromNBT(NBTTC);
this.blockMetadata = NBTTC.getInteger("Data");
}
.blockMetadata is build into Mincraft, so there's no variable declaration needed to save metadata. The reason why you need to save it is becuase Minecraft truncates block states down to 4 bits (aka 16 states / bit combinations) when you exit the game unless you save it using what we're all talking about.
Also, keep in mind that whenever you want to get the metadata of your block, don't use world.getBlockMetadata because that is truncated as well. Use the tile entity: world.getTileEntity(i, j, k).blockMetadata;
As far as setting the metadata is concerned, it's still safe to use the same method(s): world.setBlock(i, j, k, block, metadata, 3);
The reason why metadata isn't used like this by some modders is because it's not as elegant and it may require some extra lines of code.
Odd...
Anyway, why not just use one of the 0-15 metadata values as both a state and an indicator of your state?
Unless there's something I don't know, you should be able to just set the metadata of the block to 1 when there's a powered block/entity next to it, then just use that metadata for your changing textures as well.
If you want to use a boatload of textures or states, just save the "extended metadata" using readtonbt and writetonbt.
---Of course this is assuming I know what you all are talking about.
I did that initially (except for the NBT bit, I need to do more research on that) however the metadata also controls the rotation of the block. For instance, when the block is facing east, the metadata is say 3. I always believed you can only use the metadata for one thing at a time such as defining a texture, sub-block, or a rotation. Correct me if I'm wrong about this I still have a lot to learn.
Cheers!
CPU Cooler: Corsair H100i 77.0 CFM Liquid CPU Cooler
Motherboard: Asus Maximus V Extreme
Memory: G.Skill Ripjaws Z Series 32GB @1866 MHz
Storage: Samsung 840 EVO 250GB
Storage: Samsung 840 EVO 250GB
Storage: Samsung 840 EVO 500GB
Video Card: Asus GeForce GTX 780 3GB
Case: Corsair Obsidian Series 800D ATX Full Tower Case
Power Supply: Corsair AX1200i
Sound Card: Creative Labs Sound Blaster Zx 24-bit 192 KHz Sound Card
Wireless Network Adapter: Netgear WNDA4100-100NAS 802.11a/b/g/n USB 2.0 Wi-Fi Adapter
Mouse: Corsair Vengeance M95 Wired Laser Mouse
Keyboard: Corsair Gaming K95 RGB Cherry MX Brown Fully Mechanical Gaming Keyboard
Might as well use getBlockPowerInput to be honest; preemptive optimization is the nature of many errors.
Check out my mod, Placeable Items!
If my comment helped you or you just like me, hit the green arrow down there!
Sorry, can you please post your updated Block, TileEntity and Renderer classes?
It would be easier because you removed some errors.
sorry for my bad english I'm Italian
Here are all three
https://gist.github.com/anonymous/4d71c1663d9cf4876e3e
CPU Cooler: Corsair H100i 77.0 CFM Liquid CPU Cooler
Motherboard: Asus Maximus V Extreme
Memory: G.Skill Ripjaws Z Series 32GB @1866 MHz
Storage: Samsung 840 EVO 250GB
Storage: Samsung 840 EVO 250GB
Storage: Samsung 840 EVO 500GB
Video Card: Asus GeForce GTX 780 3GB
Case: Corsair Obsidian Series 800D ATX Full Tower Case
Power Supply: Corsair AX1200i
Sound Card: Creative Labs Sound Blaster Zx 24-bit 192 KHz Sound Card
Wireless Network Adapter: Netgear WNDA4100-100NAS 802.11a/b/g/n USB 2.0 Wi-Fi Adapter
Mouse: Corsair Vengeance M95 Wired Laser Mouse
Keyboard: Corsair Gaming K95 RGB Cherry MX Brown Fully Mechanical Gaming Keyboard
Yes, each metadata value can only represent one state. And that state can represent any one combination of sub-states - including texture, rotation and whatever other state you can think of.
Essentially, each combination of data you store inside a tile entity has its own metadata value. It just depends on what you call it (or them). Also, it's not limited to 16 states. It's more like 32,768 states, so if you just want to go off an integer value, you can define your metadata for all your standard states (not powered), then define the same number of metadata for all the powered states. You can use getBlockPowerInput like Ferdz said to do this. Just make sure you save the metadata in your TE class correctly:
.blockMetadata is build into Mincraft, so there's no variable declaration needed to save metadata. The reason why you need to save it is becuase Minecraft truncates block states down to 4 bits (aka 16 states / bit combinations) when you exit the game unless you save it using what we're all talking about.
Also, keep in mind that whenever you want to get the metadata of your block, don't use world.getBlockMetadata because that is truncated as well. Use the tile entity: world.getTileEntity(i, j, k).blockMetadata;
As far as setting the metadata is concerned, it's still safe to use the same method(s): world.setBlock(i, j, k, block, metadata, 3);
The reason why metadata isn't used like this by some modders is because it's not as elegant and it may require some extra lines of code.
Alright, after a ton of experimenting I finally got it to work by using metadata's.
Here are all the relevant classes for reference in case someone needs it in the future.
https://gist.github.com/anonymous/2eb440d9580144e5aed4
Thanks for everyone's help.
Cheers!!
CPU Cooler: Corsair H100i 77.0 CFM Liquid CPU Cooler
Motherboard: Asus Maximus V Extreme
Memory: G.Skill Ripjaws Z Series 32GB @1866 MHz
Storage: Samsung 840 EVO 250GB
Storage: Samsung 840 EVO 250GB
Storage: Samsung 840 EVO 500GB
Video Card: Asus GeForce GTX 780 3GB
Case: Corsair Obsidian Series 800D ATX Full Tower Case
Power Supply: Corsair AX1200i
Sound Card: Creative Labs Sound Blaster Zx 24-bit 192 KHz Sound Card
Wireless Network Adapter: Netgear WNDA4100-100NAS 802.11a/b/g/n USB 2.0 Wi-Fi Adapter
Mouse: Corsair Vengeance M95 Wired Laser Mouse
Keyboard: Corsair Gaming K95 RGB Cherry MX Brown Fully Mechanical Gaming Keyboard