Work on the ItemStack adapter. Added missing firework flight power. Updated format description document.

This commit is contained in:
Olof Larsson 2013-01-15 07:49:14 +01:00
parent 6b8baafa37
commit d2d5d802dd
4 changed files with 111 additions and 8 deletions

View File

@ -26,6 +26,18 @@
}
...
]
StoredEnchantments:
[
{
id: int
lvl: int
}
{
id: int
lvl: int
}
...
]
title: str
author: str
pages: [str]
@ -41,6 +53,23 @@
}
...
]
Explosion:
{
Flicker: bool
Trail: bool
Colors: [int]
FadeColors: [int]
Type: byte
}
Fireworks:
{
Flight: byte
Explosions:
[
*Explosion*
...
]
}
}
}
@ -62,6 +91,11 @@
id: lvl
...
}
stored-enchants:
{
id: lvl
...
}
repair-cost: int
title: str
author: str
@ -84,6 +118,28 @@
}
...
]
firework-effect:
{
flicker: bool
trail: bool
colors:
[
*color*
...
]
fade-colors:
[
*color*
...
]
type: "BALL", "BALL_LARGE", "STAR", "BURST" or "CREEPER"
}
firework-effects:
[
*firework-effect*
...
]
power: int
}
}
@ -103,6 +159,12 @@
id: lvl
...
}
stored-enchants:
{
id: lvl
id: lvl
...
}
repaircost: int
title: str
author: str
@ -120,4 +182,18 @@
}
...
]
firework-effect:
{
flicker: bool
trail: bool
colors: [int ...]
fade-colors: [int ...]
type: str/enum
}
firework-effects:
[
*firework-effect*
...
]
firework-flight: int
}

View File

@ -70,11 +70,13 @@ public class ItemStackAdapterV2 implements JsonDeserializer<ItemStack>, JsonSeri
public static final String SKULL_OWNER = "skull";
// TODO rename to potion-effects?
public static final String POTION_EFFECTS = "effects";
// We renamed "effects" to "potion-effects".
public static final String POTION_EFFECTS_OLD = "effects";
public static final String POTION_EFFECTS = "potion-effects";
public static final String FIREWORK_EFFECT = "firework-effect";
public static final String FIREWORK_EFFECTS = "firework-effects";
public static final String FIREWORK_FLIGHT = "firework-flight";
public static final String STORED_ENCHANTS = "stored-enchants";
@ -85,6 +87,7 @@ public class ItemStackAdapterV2 implements JsonDeserializer<ItemStack>, JsonSeri
public static final int DEFAULT_ID;
public static final int DEFAULT_COUNT;
public static final int DEFAULT_DAMAGE;
public static final int DEFAULT_FIREWORK_POWER = 1;
static
{
@ -504,6 +507,7 @@ public class ItemStackAdapterV2 implements JsonDeserializer<ItemStack>, JsonSeri
else
{
JsonElement element = json.get(POTION_EFFECTS);
if (element == null) element = json.get(POTION_EFFECTS_OLD);
if (element == null) return;
meta.clearCustomEffects();
@ -557,6 +561,12 @@ public class ItemStackAdapterV2 implements JsonDeserializer<ItemStack>, JsonSeri
// -------------------------------------------- //
public static void transferFireworkMeta(FireworkMeta meta, JsonObject json, boolean meta2json)
{
transferFireworkMetaEffects(meta, json, meta2json);
transferFireworkMetaPower(meta, json, meta2json);
}
public static void transferFireworkMetaEffects(FireworkMeta meta, JsonObject json, boolean meta2json)
{
if (meta2json)
{
@ -572,6 +582,20 @@ public class ItemStackAdapterV2 implements JsonDeserializer<ItemStack>, JsonSeri
}
}
public static void transferFireworkMetaPower(FireworkMeta meta, JsonObject json, boolean meta2json)
{
if (meta2json)
{
json.addProperty(FIREWORK_FLIGHT, meta.getPower());
}
else
{
JsonElement element = json.get(FIREWORK_FLIGHT);
if (element == null) return;
meta.setPower(element.getAsInt());
}
}
// -------------------------------------------- //
// SPECIFIC META: ENCHANTMENT STORAGE
// -------------------------------------------- //

View File

@ -50,9 +50,12 @@ public class HelpCommand extends MCommand
return this.commandChain.get(this.commandChain.size()-1).p();
}
private static HelpCommand instance = new HelpCommand();
public static HelpCommand getInstance()
{
return instance;
}
// -------------------------------------------- //
// INSTANCE
// -------------------------------------------- //
private static HelpCommand i = new HelpCommand();
public static HelpCommand getInstance() { return i; }
public static HelpCommand get() { return i; }
}