I just realised CosmicDan mentioned the damageDropped method before, I apologise for the duplicate post.
How are you managing to combine the base bed metadata (facing, occupied state, head/foot flag) and the colour metadata? Don't you need all 16 values to store the colour?
If you can't use metadata, you may need to treat each colour of bed as a separate block instead of metadata values of the same block.
The code in this Gist is a rough example of how I'd handle this. Each colour of bed is a separate Block instance, but there's a single Item instance that uses its metadata to store the colour of the bed it should place.
Rollback Post to RevisionRollBack
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
I define my colors this way, so It's not really metadata, bu almost... (It's the same way logs, and leaves do)
public static final String[] color = new String[] {"black", "blue", "brown", "cyan", "gray", "green", "light_blue", "lime", "magenta", "orange", "pink", "purple", "red", "silver", "white", "yellow"};
If you want to see the code, here it is
If you want to see the other codes, the Item bed is here
And the Registries are in this folder
EDIT: As you may have seen the color String is in the BlockColoredBed.java class itself... I'm trying to use metadata as I don't want to have one class for each color, but one class for all of them
Rollback Post to RevisionRollBack
I am most likely inactive on this account! If you want to contact me, here's my Twitter @PandawanMT.
Why are you using a different order of colours in your Block and Item? Wouldn't it be simpler if both the Block and Item used the same order? (e.g. 0 = black, 1 = red, etc.) I moved the colour name array into the References class in my example so you don't have to duplicate the colours across several classes.
I don't think there's any way to have all 16 colours be metadata values of the same Block instance if you're also using the metadata to store the bed information (facing, occupied state, head/foot flag).
With my solution you still only have a single class for all colours of the bed, but each colour is a separate instance of that class.
Rollback Post to RevisionRollBack
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
Ok, I guess I'm going to use your way... Thanks, I'll try
EDIT: I got a question, would you register both of them in the GameRegistry ?
EDIT2:
I registered the item, but when I try to register the block, I get this error:
The method registerBlock(Block, String) in the type GameRegistry is not applicable for the arguments (Block[], String)
I used this to register:
GameRegistry.registerBlock(coloredBeds, "coloredBeds");
Ok, I guess I'm going to use your way... Thanks, I'll try
EDIT: I got a question, would you register both of them in the GameRegistry ?
EDIT2:
I registered the item, but when I try to register the block, I get this error:
The method registerBlock(Block, String) in the type GameRegistry is not applicable for the arguments (Block[], String)
I used this to register:
GameRegistry.registerBlock(coloredBeds, "coloredBeds");
You need to register each individual Block in the array, you can't just register the whole array at once.
Why do you have a block array? I thought your bed was only one class?
If he's using my solution, each colour is a separate BlockColoredBed instance.
Rollback Post to RevisionRollBack
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
Whoops, remove the brackts [] lol. We're just appending the variable (the current number in the for loop) to the string, the brackets are for referring to array indexes. So it effectively functions like this...
Yeah, I got it, I know how to use arrays and those kind of loops, but I couldn't understand why were you adding the [ i ], but you are actually adding the i, so the number...
EDIT:
I get this crash report
net.minecraft.util.ReportedException: Ticking memory connection
at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:198) ~[NetworkSystem.class:?]
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:726) ~[MinecraftServer.class:?]
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:614) ~[MinecraftServer.class:?]
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118) ~[IntegratedServer.class:?]
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:485) [MinecraftServer.class:?]
at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:752) [MinecraftServer$2.class:?]
Caused by: java.lang.NullPointerException
at com.millstone.blocks.ItemColoredBed.onItemUse(ItemColoredBed.java:85) ~[ItemColoredBed.class:?]
at net.minecraftforge.common.ForgeHooks.onPlaceItemIntoWorld(ForgeHooks.java:456) ~[ForgeHooks.class:?]
at net.minecraft.item.ItemStack.tryPlaceItemIntoWorld(ItemStack.java:142) ~[ItemStack.class:?]
at net.minecraft.server.management.ItemInWorldManager.activateBlockOrUseItem(ItemInWorldManager.java:422) ~[ItemInWorldManager.class:?]
at net.minecraft.network.NetHandlerPlayServer.processPlayerBlockPlacement(NetHandlerPlayServer.java:593) ~[NetHandlerPlayServer.class:?]
at net.minecraft.network.play.client.C08PacketPlayerBlockPlacement.processPacket(C08PacketPlayerBlockPlacement.java:74) ~[C08PacketPlayerBlockPlacement.class:?]
at net.minecraft.network.play.client.C08PacketPlayerBlockPlacement.processPacket(C08PacketPlayerBlockPlacement.java:122) ~[C08PacketPlayerBlockPlacement.class:?]
at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:241) ~[NetworkManager.class:?]
at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:182) ~[NetworkSystem.class:?]
... 5 more
[07:27:51] [Server thread/ERROR]: This crash report has been saved to: /Users/migueltenant/Desktop/forge/forge/eclipse/./crash-reports/crash-2014-12-02_07.27.51-server.txt
[07:27:51] [Server thread/INFO]: Stopping server
[07:27:51] [Server thread/INFO]: Saving players
[07:27:51] [Client thread/INFO] [STDOUT]: [net.minecraft.client.Minecraft:displayCrashReport:388]: ---- Minecraft Crash Report ----
// This doesn't make any sense!
Time: 02/12/14 07:27
Description: Ticking memory connection
java.lang.NullPointerException: Ticking memory connection
at com.millstone.blocks.ItemColoredBed.onItemUse(ItemColoredBed.java:85)
at net.minecraftforge.common.ForgeHooks.onPlaceItemIntoWorld(ForgeHooks.java:456)
at net.minecraft.item.ItemStack.tryPlaceItemIntoWorld(ItemStack.java:142)
at net.minecraft.server.management.ItemInWorldManager.activateBlockOrUseItem(ItemInWorldManager.java:422)
at net.minecraft.network.NetHandlerPlayServer.processPlayerBlockPlacement(NetHandlerPlayServer.java:593)
at net.minecraft.network.play.client.C08PacketPlayerBlockPlacement.processPacket(C08PacketPlayerBlockPlacement.java:74)
at net.minecraft.network.play.client.C08PacketPlayerBlockPlacement.processPacket(C08PacketPlayerBlockPlacement.java:122)
at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:241)
at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:182)
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:726)
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:614)
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:485)
at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:752)
A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------
-- Head --
Stacktrace:
at com.millstone.blocks.ItemColoredBed.onItemUse(ItemColoredBed.java:85)
at net.minecraftforge.common.ForgeHooks.onPlaceItemIntoWorld(ForgeHooks.java:456)
at net.minecraft.item.ItemStack.tryPlaceItemIntoWorld(ItemStack.java:142)
at net.minecraft.server.management.ItemInWorldManager.activateBlockOrUseItem(ItemInWorldManager.java:422)
at net.minecraft.network.NetHandlerPlayServer.processPlayerBlockPlacement(NetHandlerPlayServer.java:593)
at net.minecraft.network.play.client.C08PacketPlayerBlockPlacement.processPacket(C08PacketPlayerBlockPlacement.java:74)
at net.minecraft.network.play.client.C08PacketPlayerBlockPlacement.processPacket(C08PacketPlayerBlockPlacement.java:122)
at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:241)
Could you set a breakpoint on the line that's throwing the exception and tell me what the values of colorIndex and BlockRegistry.coloredBeds are at that point?
Rollback Post to RevisionRollBack
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
Well you should have the code as it's yours (the Gist one)...
For the throwing exception, do you mean some part of the crash report ?
Your copy seems to be slightly different to mine, since line 85 of my ItemColoredBed is the opening brace of an if statement. Could you post your copy of it? I'll try to see what's going wrong.
The exception causing the crash is being thrown on line 85 of ItemColoredBed, which is where I wanted you to put the breakpoint so that you could inspect the values of the variables involved and see why the crash is happening.
Rollback Post to RevisionRollBack
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
The new code in my original Gist seems to work. It shows 16 coloured bed blocks in the creative tab and allows them to placed in the world, but I don't have any textures to test them with.
I think the problem that caused the crash was that the ItemColoredBed.bedIcons array was null when the getIconFromDamage method was trying to access it, so I moved the initialisation of the array to the constructor.
Rollback Post to RevisionRollBack
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
If the size of the array is static and not dynamic (i.e. it's bedIcons[15] - or whatever number - and not bedIcons[x]) then it's correct convention to initialise the array when you define the class field, rather than in the constructor. It should also be final too, if this is the case.
If the size of the array is static and not dynamic (i.e. it's bedIcons[15] - or whatever number - and not bedIcons[x]) then it's correct convention to initialise the array when you define the class field, rather than in the constructor. It should also be final too, if this is the case.
That makes sense. I've made that change and uploaded it to the Gist.
Rollback Post to RevisionRollBack
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
I am most likely inactive on this account! If you want to contact me, here's my Twitter @PandawanMT.
Check out my website!
So close to releasing my new map! Gonna beta test it next week... Probably coming out in two weeks! Follow My Twitter for more info!
How are you managing to combine the base bed metadata (facing, occupied state, head/foot flag) and the colour metadata? Don't you need all 16 values to store the colour?
If you can't use metadata, you may need to treat each colour of bed as a separate block instead of metadata values of the same block.
The code in this Gist is a rough example of how I'd handle this. Each colour of bed is a separate Block instance, but there's a single Item instance that uses its metadata to store the colour of the bed it should place.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
public static final String[] color = new String[] {"black", "blue", "brown", "cyan", "gray", "green", "light_blue", "lime", "magenta", "orange", "pink", "purple", "red", "silver", "white", "yellow"};
If you want to see the code, here it is
If you want to see the other codes, the Item bed is here
And the Registries are in this folder
EDIT: As you may have seen the color String is in the BlockColoredBed.java class itself... I'm trying to use metadata as I don't want to have one class for each color, but one class for all of them
I am most likely inactive on this account! If you want to contact me, here's my Twitter @PandawanMT.
Check out my website!
So close to releasing my new map! Gonna beta test it next week... Probably coming out in two weeks! Follow My Twitter for more info!
I don't think there's any way to have all 16 colours be metadata values of the same Block instance if you're also using the metadata to store the bed information (facing, occupied state, head/foot flag).
With my solution you still only have a single class for all colours of the bed, but each colour is a separate instance of that class.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
EDIT: I got a question, would you register both of them in the GameRegistry ?
EDIT2:
I registered the item, but when I try to register the block, I get this error:
The method registerBlock(Block, String) in the type GameRegistry is not applicable for the arguments (Block[], String)
I used this to register:
GameRegistry.registerBlock(coloredBeds, "coloredBeds");
I am most likely inactive on this account! If you want to contact me, here's my Twitter @PandawanMT.
Check out my website!
So close to releasing my new map! Gonna beta test it next week... Probably coming out in two weeks! Follow My Twitter for more info!
Why do you have a block array? I thought your bed was only one class?
But having the color <> metadata mapping in the same order for item and block will definitely help lol.
You need to register each individual Block in the array, you can't just register the whole array at once.
If he's using my solution, each colour is a separate BlockColoredBed instance.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
for (int i = 0; i < coloredBeds.size(); i++) {
GameRegistry.registerBlock(coloredBeds[i], "coloredBed" + [i]);
}
Syntax error on token "+", Expression expected after this token
I am most likely inactive on this account! If you want to contact me, here's my Twitter @PandawanMT.
Check out my website!
So close to releasing my new map! Gonna beta test it next week... Probably coming out in two weeks! Follow My Twitter for more info!
...without having to type each registration manually. Make sense?
EDIT:
I get this crash report
The OnItemUse line in the ItemColoredBed is
BlockColoredBed coloredBed = (BlockColoredBed)BlockRegistry.coloredBeds[colorIndex];
which is in this function:
I am most likely inactive on this account! If you want to contact me, here's my Twitter @PandawanMT.
Check out my website!
So close to releasing my new map! Gonna beta test it next week... Probably coming out in two weeks! Follow My Twitter for more info!
I think that CosmicDan is right, the
tries to return colorIndex, but it doesn't know which one... So it returns null
(Well that's what I think)
Other thing I forgot to mention is that this crash report appears when I try to place the bed (with the item)
EDIT: I checked, I think so, because the color index is stated as this:
and I think there is no item damage stated in this item...
I am most likely inactive on this account! If you want to contact me, here's my Twitter @PandawanMT.
Check out my website!
So close to releasing my new map! Gonna beta test it next week... Probably coming out in two weeks! Follow My Twitter for more info!
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
For the throwing exception, do you mean some part of the crash report ?
I am most likely inactive on this account! If you want to contact me, here's my Twitter @PandawanMT.
Check out my website!
So close to releasing my new map! Gonna beta test it next week... Probably coming out in two weeks! Follow My Twitter for more info!
Your copy seems to be slightly different to mine, since line 85 of my ItemColoredBed is the opening brace of an if statement. Could you post your copy of it? I'll try to see what's going wrong.
The exception causing the crash is being thrown on line 85 of ItemColoredBed, which is where I wanted you to put the breakpoint so that you could inspect the values of the variables involved and see why the crash is happening.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
I am most likely inactive on this account! If you want to contact me, here's my Twitter @PandawanMT.
Check out my website!
So close to releasing my new map! Gonna beta test it next week... Probably coming out in two weeks! Follow My Twitter for more info!
I think the problem that caused the crash was that the ItemColoredBed.bedIcons array was null when the getIconFromDamage method was trying to access it, so I moved the initialisation of the array to the constructor.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
That makes sense. I've made that change and uploaded it to the Gist.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.