Hello.
I need to make configuration as Json.
Here is an example:
Blocks: {
"Cobblestone": {
"Block" = "minecraft: cobblestone",
"Meta" = 0,
"Count" = 1
}
"Stone": {
"Block" = "minecraft: stone",
"Meta" = 0,
"Count" = 1
}
...
}
These can be added to their blocks, and certain actions will occur to them - this I had done. The block which is in the configuration will be limited to use. For example, the unit "Cobblestone" can be put only once.
How to realize this? Tell me please. Now there is a normal configuration, but it is not quite convenient.
You could use the regular Config file and read in certain entries as JSON format, or you can just open a new File and read it however you want. Here you go, first search result for "Java read JSON file".
Maps are Object -> Object. In this case, String -> BlockInformation. In the example, "Cobblestone" is mapped to a "minecraft:cobblestone" BlockInformation. map.get("Cobblestone") will return the BlockInformation mapped to "Cobblestone". Use map.get("Cobblestone").blockObject to get the actual block from it.
If this still doesn't work, try implementing your own equals() and hashCode()
Hello.
I need to make configuration as Json.
Here is an example:
Blocks: {
"Cobblestone": {
"Block" = "minecraft: cobblestone",
"Meta" = 0,
"Count" = 1
}
"Stone": {
"Block" = "minecraft: stone",
"Meta" = 0,
"Count" = 1
}
...
}
These can be added to their blocks, and certain actions will occur to them - this I had done. The block which is in the configuration will be limited to use. For example, the unit "Cobblestone" can be put only once.
How to realize this? Tell me please. Now there is a normal configuration, but it is not quite convenient.
You could use the regular Config file and read in certain entries as JSON format, or you can just open a new File and read it however you want. Here you go, first search result for "Java read JSON file".
It looks like you want a map.This should do the trick.
Thanks. I run this code and.
1.Somehow here it requires a cast to (Block):
2. File Empty.
Config.java:
But file Empty.
If i paste text from your "Example.json" in my ".json" file and run Minecraft - My file is empty:
EDIT#1: If the file does not have the client crash. After a beautiful, create an empty file.json.
EDIT#2: Crash If the file does not have: http://pastebin.com/W0BECG9v
Oh, this is 1.7.10. Change
this.blockObject = Block.blockRegistry.getObject(new ResourceLocation(block));
to
this.blockObject = Block.getBlockFromName(block);
If you don't actually need the Block object (or would rather get it manually later), you can just remove that field.
We need this field. as I this unit will need to hang limitation.
how about the fact that if the file is not found, the client crash?
how to get taken elements??
I can not get a block from the HashMap. How to get the unit and its data?
If you display the fact that we thought we get this:
how to extract here? tried method get (), but it returns null.
Maps are Object -> Object. In this case, String -> BlockInformation. In the example, "Cobblestone" is mapped to a "minecraft:cobblestone" BlockInformation. map.get("Cobblestone") will return the BlockInformation mapped to "Cobblestone". Use map.get("Cobblestone").blockObject to get the actual block from it.
If this still doesn't work, try implementing your own equals() and hashCode()