以下的資料對部份人有用
原資料:TextureEnder的net.minecraft.client.resources.metadata.*
- AnimationMetadataSectionSerializer:
- public AnimationMetadataSection deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
- throws JsonParseException
- {
- List frames = Lists.newArrayList();
- JsonObject object = (JsonObject)json;
- int defaultFrameTime = getInt(object.get("frametime"), "frametime", Integer.valueOf(1), 1, 2147483647);
- if (object.has("frames")) {
- try {
- JsonArray array = object.getAsJsonArray("frames");
- for (int i = 0; i < array.size(); i++) {
- JsonElement element = array.get(i);
- frames.add(getFrame(i, element));
- }
- } catch (ClassCastException ex) {
- throw new JsonParseException("Invalid animation->frames: expected array, was " + object.get("frames"), ex);
- }
- }
- int width = getInt(object.get("width"), "width", Integer.valueOf(-1), 1, 2147483647);
- int height = getInt(object.get("height"), "height", Integer.valueOf(-1), 1, 2147483647);
- return new AnimationMetadataSection(frames, width, height, defaultFrameTime);
- }
- private AnimationFrame getFrame(int index, JsonElement element) {
- if (element.isJsonPrimitive())
- try {
- return new AnimationFrame(element.getAsInt());
- } catch (NumberFormatException ex) {
- throw new JsonParseException("Invalid animation->frames->" + index + ": expected number, was " + element, ex);
- }
- if (element.isJsonObject()) {
- JsonObject object = element.getAsJsonObject();
- int time = getInt(object.get("time"), "frames->" + index + "->time", Integer.valueOf(-1), 1, 2147483647);
- int frame = getInt(object.get("index"), "frames->" + index + "->index", null, 0, 2147483647);
- return new AnimationFrame(frame, time);
- }
- throw new JsonParseException("Invalid animation->frames->" + index + ": unexpected " + element);
- }
- public JsonElement serialize(AnimationMetadataSection src, Type typeOfSrc, JsonSerializationContext context)
- {
- JsonObject result = new JsonObject();
- if (src.getDefaultFrameTime() != 1) result.addProperty("frametime", Integer.valueOf(src.getDefaultFrameTime()));
- if (src.getFrameWidth() != -1) result.addProperty("width", Integer.valueOf(src.getFrameWidth()));
- if (src.getFrameHeight() != -1) result.addProperty("height", Integer.valueOf(src.getFrameHeight()));
- if (src.getFrameCount() > 0) {
- JsonArray frames = new JsonArray();
- for (int i = 0; i < src.getFrameCount(); i++) {
- if (src.hasCustomFrameTime(i)) {
- JsonObject frame = new JsonObject();
- frame.addProperty("index", Integer.valueOf(src.getFrameIndex(i)));
- frame.addProperty("time", Integer.valueOf(src.getFrameTime(i)));
- frames.add(frame);
- } else {
- frames.add(new JsonPrimitive(Integer.valueOf(src.getFrameIndex(i))));
- }
- }
- result.add("frames", frames);
- }
- return result;
- }
- AnimationMetadataSection:
- public AnimationMetadataSection(List<AnimationFrame> frames, int frameWidth, int frameHeight, int defaultFrameTime) {
- this.frames = frames;
- this.frameWidth = frameWidth;
- this.frameHeight = frameHeight;
- this.defaultFrameTime = defaultFrameTime;
- }
- /*....*/
- public boolean hasCustomFrameTime(int frameIndex)
- {
- return !((AnimationFrame)frames.get(frameIndex)).isTimeUnknown();
- }
- public int getFrameIndex(int frameIndex) {
- return ((AnimationFrame)frames.get(frameIndex)).getIndex();
- }
- /*....*/
- FontMetadataSection:
- public FontMetadataSection deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
- throws JsonParseException
- {
- JsonObject object = json.getAsJsonObject();
- float[] widths = new float[256];
- float[] spacings = new float[256];
- float[] lefts = new float[256];
- float defaultWidth = 1.0F;
- float defaultSpacing = 0.0F;
- float defaultLeft = 0.0F;
- if (object.has("characters")) {
- if (!object.get("characters").isJsonObject()) {
- throw new JsonParseException("Invalid font->characters: expected object, was " + object.get("characters"));
- }
- JsonObject characters = object.getAsJsonObject("characters");
- if (characters.has("default")) {
- if (!characters.get("default").isJsonObject()) {
- throw new JsonParseException("Invalid font->characters->default: expected object, was " + characters.get("default"));
- }
- JsonObject def = characters.getAsJsonObject("default");
- defaultWidth = getFloat(def.get("width"), "characters->default->width", Float.valueOf(defaultWidth), 0.0F, 2.147484E+009F);
- defaultSpacing = getFloat(def.get("spacing"), "characters->default->spacing", Float.valueOf(defaultSpacing), 0.0F, 2.147484E+009F);
- defaultLeft = getFloat(def.get("left"), "characters->default->left", Float.valueOf(defaultLeft), 0.0F, 2.147484E+009F);
- }
- for (int i = 0; i < 256; i++) {
- JsonElement element = characters.get(Integer.toString(i));
- float width = defaultWidth;
- float spacing = defaultSpacing;
- float left = defaultLeft;
- if (element != null) {
- if (element.isJsonObject()) {
- JsonObject character = element.getAsJsonObject();
- width = getFloat(character.get("width"), "characters->" + i + "->width", Float.valueOf(width), 0.0F, 2.147484E+009F);
- spacing = getFloat(character.get("spacing"), "characters->" + i + "->spacing", Float.valueOf(spacing), 0.0F, 2.147484E+009F);
- left = getFloat(character.get("left"), "characters->" + i + "->left", Float.valueOf(left), 0.0F, 2.147484E+009F);
- } else {
- throw new JsonParseException("Invalid font->characters->" + i + ": expected object, was " + element);
- }
- }
- widths[i] = width;
- spacings[i] = spacing;
- lefts[i] = left;
- }
- }
- return new FontMetadataSection(widths, lefts, spacings);
- }
- PackMetadataSection :
- public PackMetadataSection deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
- throws JsonParseException
- {
- JsonObject object = json.getAsJsonObject();
- String desc = getString(object.get("description"), "description", null, 1, 2147483647);
- int format = getInt(object.get("pack_format"), "pack_format", null, 1, 2147483647);
- return new PackMetadataSection(desc, format);
- }
- public JsonElement serialize(PackMetadataSection src, Type typeOfSrc, JsonSerializationContext context)
- {
- JsonObject result = new JsonObject();
- result.addProperty("pack_format", Integer.valueOf(src.getPackFormat()));
- result.addProperty("description", src.getDescription());
- return result;
- }
- /*....*/
- TextureMetadataSection:
- public TextureMetadataSection deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
- throws JsonParseException
- {
- JsonObject object = json.getAsJsonObject();
- boolean blur = getBoolean(object.get("blur"), "blur", Boolean.valueOf(false));
- boolean clamp = getBoolean(object.get("clamp"), "clamp", Boolean.valueOf(false));
- return new TextureMetadataSection(blur, clamp);
- }
- /*..下面的額外..*/
- public PackMetadataSection deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
- throws JsonParseException
- {
- JsonObject object = json.getAsJsonObject();
- String desc = getString(object.get("description"), "description", null, 1, 2147483647);
- int format = getInt(object.get("pack_format"), "pack_format", null, 1, 2147483647);
- return new PackMetadataSection(desc, format);
- }
复制代码如上面所說,1.6新的資源包開始支持類似forge包的資源元碼(不是源代碼),不過forge使用的是yaml(可以變成json),而minecraft 1.6新的資源包可是直接用了json(這樣就代表了爲什麽這個jar那麼的原因,因為需要apache提供的JsonParser)
這是整個要改的地方,[皮膚,質材包製造者注意]