9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-21 16:09:26 +00:00

添加1.21.11新的item model选项swap_animation_scale

This commit is contained in:
XiaoMoMi
2025-12-09 17:22:35 +08:00
parent 3d82874862
commit bc7d887d5c
4 changed files with 96 additions and 8 deletions

View File

@@ -787,7 +787,8 @@ public abstract class AbstractItemManager<I> extends AbstractModelGenerator impl
map.put(customModelData, new ModernItemModel( map.put(customModelData, new ModernItemModel(
modernModel, modernModel,
ResourceConfigUtils.getAsBoolean(section.getOrDefault("oversized-in-gui", true), "oversized-in-gui"), ResourceConfigUtils.getAsBoolean(section.getOrDefault("oversized-in-gui", true), "oversized-in-gui"),
ResourceConfigUtils.getAsBoolean(section.getOrDefault("hand-animation-on-swap", true), "hand-animation-on-swap") ResourceConfigUtils.getAsBoolean(section.getOrDefault("hand-animation-on-swap", true), "hand-animation-on-swap"),
ResourceConfigUtils.getAsFloat(section.getOrDefault("swap-animation-scale", 1f), "swap-animation-scale")
)); ));
} }
// 添加旧版 overrides // 添加旧版 overrides
@@ -805,7 +806,8 @@ public abstract class AbstractItemManager<I> extends AbstractModelGenerator impl
AbstractItemManager.this.modernItemModels1_21_4.put(itemModel, new ModernItemModel( AbstractItemManager.this.modernItemModels1_21_4.put(itemModel, new ModernItemModel(
modernModel, modernModel,
ResourceConfigUtils.getAsBoolean(section.getOrDefault("oversized-in-gui", true), "oversized-in-gui"), ResourceConfigUtils.getAsBoolean(section.getOrDefault("oversized-in-gui", true), "oversized-in-gui"),
ResourceConfigUtils.getAsBoolean(section.getOrDefault("hand-animation-on-swap", true), "hand-animation-on-swap") ResourceConfigUtils.getAsBoolean(section.getOrDefault("hand-animation-on-swap", true), "hand-animation-on-swap"),
ResourceConfigUtils.getAsFloat(section.getOrDefault("swap-animation-scale", 1f), "swap-animation-scale")
)); ));
} }
if (needsItemModelCompatibility() && needsLegacyCompatibility() && hasLegacyModel) { if (needsItemModelCompatibility() && needsLegacyCompatibility() && hasLegacyModel) {
@@ -819,7 +821,8 @@ public abstract class AbstractItemManager<I> extends AbstractModelGenerator impl
AbstractItemManager.this.modernItemModels1_21_4.put(id, new ModernItemModel( AbstractItemManager.this.modernItemModels1_21_4.put(id, new ModernItemModel(
modernModel, modernModel,
ResourceConfigUtils.getAsBoolean(section.getOrDefault("oversized-in-gui", true), "oversized-in-gui"), ResourceConfigUtils.getAsBoolean(section.getOrDefault("oversized-in-gui", true), "oversized-in-gui"),
ResourceConfigUtils.getAsBoolean(section.getOrDefault("hand-animation-on-swap", true), "hand-animation-on-swap") ResourceConfigUtils.getAsBoolean(section.getOrDefault("hand-animation-on-swap", true), "hand-animation-on-swap"),
ResourceConfigUtils.getAsFloat(section.getOrDefault("swap-animation-scale", 1f), "swap-animation-scale")
)); ));
} }
} }

View File

@@ -2545,6 +2545,7 @@ public abstract class AbstractPackManager implements PackManager {
boolean handAnimationOnSwap = originalItemModel.handAnimationOnSwap(); boolean handAnimationOnSwap = originalItemModel.handAnimationOnSwap();
boolean oversizedInGui = originalItemModel.oversizedInGui(); boolean oversizedInGui = originalItemModel.oversizedInGui();
float swapAnimationScale = originalItemModel.swapAnimationScale();
Map<Float, ItemModel> entries = new TreeMap<>(); Map<Float, ItemModel> entries = new TreeMap<>();
for (Map.Entry<Integer, ModernItemModel> modelWithDataEntry : entry.getValue().entrySet()) { for (Map.Entry<Integer, ModernItemModel> modelWithDataEntry : entry.getValue().entrySet()) {
@@ -2565,7 +2566,7 @@ public abstract class AbstractPackManager implements PackManager {
entries entries
); );
ModernItemModel newItemModel = new ModernItemModel(rangeDispatch, handAnimationOnSwap, oversizedInGui); ModernItemModel newItemModel = new ModernItemModel(rangeDispatch, handAnimationOnSwap, oversizedInGui, swapAnimationScale);
try { try {
Files.createDirectories(overridedItemPath.getParent()); Files.createDirectories(overridedItemPath.getParent());
} catch (IOException e) { } catch (IOException e) {

View File

@@ -2,7 +2,9 @@ package net.momirealms.craftengine.core.pack.model;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import net.momirealms.craftengine.core.pack.revision.Revision; import net.momirealms.craftengine.core.pack.revision.Revision;
import net.momirealms.craftengine.core.util.GsonHelper;
import net.momirealms.craftengine.core.util.MinecraftVersion; import net.momirealms.craftengine.core.util.MinecraftVersion;
import net.momirealms.craftengine.core.util.MinecraftVersions;
import java.util.List; import java.util.List;
@@ -10,30 +12,36 @@ public class ModernItemModel {
private final ItemModel itemModel; private final ItemModel itemModel;
private final boolean oversizedInGui; private final boolean oversizedInGui;
private final boolean handAnimationOnSwap; private final boolean handAnimationOnSwap;
private final float swapAnimationScale;
public ModernItemModel(ItemModel itemModel, boolean handAnimationOnSwap, boolean oversizedInGui) { public ModernItemModel(ItemModel itemModel, boolean handAnimationOnSwap, boolean oversizedInGui, float swapAnimationScale) {
this.handAnimationOnSwap = handAnimationOnSwap; this.handAnimationOnSwap = handAnimationOnSwap;
this.itemModel = itemModel; this.itemModel = itemModel;
this.oversizedInGui = oversizedInGui; this.oversizedInGui = oversizedInGui;
this.swapAnimationScale = swapAnimationScale;
} }
public static ModernItemModel fromJson(JsonObject json) { public static ModernItemModel fromJson(JsonObject json) {
ItemModel model = ItemModels.fromJson(json.getAsJsonObject("model")); ItemModel model = ItemModels.fromJson(json.getAsJsonObject("model"));
return new ModernItemModel( return new ModernItemModel(
model, model,
!json.has("hand_animation_on_swap") || json.get("hand_animation_on_swap").getAsBoolean(), GsonHelper.getAsBoolean(json.get("hand_animation_on_swap"), true),
json.has("oversized_in_gui") && json.get("oversized_in_gui").getAsBoolean() GsonHelper.getAsBoolean(json.get("oversized_in_gui"), false),
GsonHelper.getAsFloat(json.get("swap_animation_scale"), 1.0f)
); );
} }
public JsonObject toJson(MinecraftVersion version) { public JsonObject toJson(MinecraftVersion version) {
JsonObject json = new JsonObject(); JsonObject json = new JsonObject();
if (this.oversizedInGui) { if (this.oversizedInGui && version.isAtOrAbove(MinecraftVersions.V1_21_6)) {
json.addProperty("oversized_in_gui", true); json.addProperty("oversized_in_gui", true);
} }
if (!this.handAnimationOnSwap) { if (!this.handAnimationOnSwap) {
json.addProperty("hand_animation_on_swap", false); json.addProperty("hand_animation_on_swap", false);
} }
if (this.swapAnimationScale != 1.0f && version.isAtOrAbove(MinecraftVersions.V1_21_11)) {
json.addProperty("swap_animation_scale", this.swapAnimationScale);
}
json.add("model", this.itemModel.apply(version)); json.add("model", this.itemModel.apply(version));
return json; return json;
} }
@@ -53,4 +61,8 @@ public class ModernItemModel {
public boolean oversizedInGui() { public boolean oversizedInGui() {
return oversizedInGui; return oversizedInGui;
} }
public float swapAnimationScale() {
return swapAnimationScale;
}
} }

View File

@@ -122,4 +122,76 @@ public final class GsonHelper {
return ja; return ja;
} }
} }
public static float getAsFloat(JsonElement json, float defaultValue) {
if (json == null || json.isJsonNull()) return defaultValue;
try {
return json.getAsFloat();
} catch (Exception e) {
return defaultValue;
}
}
public static double getAsDouble(JsonElement json, double defaultValue) {
if (json == null || json.isJsonNull()) return defaultValue;
try {
return json.getAsDouble();
} catch (Exception e) {
return defaultValue;
}
}
public static int getAsInt(JsonElement json, int defaultValue) {
if (json == null || json.isJsonNull()) return defaultValue;
try {
return json.getAsInt();
} catch (Exception e) {
return defaultValue;
}
}
public static long getAsLong(JsonElement json, long defaultValue) {
if (json == null || json.isJsonNull()) return defaultValue;
try {
return json.getAsLong();
} catch (Exception e) {
return defaultValue;
}
}
public static short getAsShort(JsonElement json, short defaultValue) {
if (json == null || json.isJsonNull()) return defaultValue;
try {
return json.getAsShort();
} catch (Exception e) {
return defaultValue;
}
}
public static byte getAsByte(JsonElement json, byte defaultValue) {
if (json == null || json.isJsonNull()) return defaultValue;
try {
return json.getAsByte();
} catch (Exception e) {
return defaultValue;
}
}
public static boolean getAsBoolean(JsonElement json, boolean defaultValue) {
if (json == null || json.isJsonNull()) return defaultValue;
try {
return json.getAsBoolean();
} catch (Exception e) {
return defaultValue;
}
}
public static String getAsString(JsonElement json, String defaultValue) {
if (json == null || json.isJsonNull()) return defaultValue;
try {
return json.getAsString();
} catch (Exception e) {
return defaultValue;
}
}
} }