mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-19 15:09:15 +00:00
添加1.21.11新的item model选项swap_animation_scale
This commit is contained in:
@@ -787,7 +787,8 @@ public abstract class AbstractItemManager<I> extends AbstractModelGenerator impl
|
||||
map.put(customModelData, new ModernItemModel(
|
||||
modernModel,
|
||||
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
|
||||
@@ -805,7 +806,8 @@ public abstract class AbstractItemManager<I> extends AbstractModelGenerator impl
|
||||
AbstractItemManager.this.modernItemModels1_21_4.put(itemModel, new ModernItemModel(
|
||||
modernModel,
|
||||
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) {
|
||||
@@ -819,7 +821,8 @@ public abstract class AbstractItemManager<I> extends AbstractModelGenerator impl
|
||||
AbstractItemManager.this.modernItemModels1_21_4.put(id, new ModernItemModel(
|
||||
modernModel,
|
||||
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")
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2545,6 +2545,7 @@ public abstract class AbstractPackManager implements PackManager {
|
||||
|
||||
boolean handAnimationOnSwap = originalItemModel.handAnimationOnSwap();
|
||||
boolean oversizedInGui = originalItemModel.oversizedInGui();
|
||||
float swapAnimationScale = originalItemModel.swapAnimationScale();
|
||||
|
||||
Map<Float, ItemModel> entries = new TreeMap<>();
|
||||
for (Map.Entry<Integer, ModernItemModel> modelWithDataEntry : entry.getValue().entrySet()) {
|
||||
@@ -2565,7 +2566,7 @@ public abstract class AbstractPackManager implements PackManager {
|
||||
entries
|
||||
);
|
||||
|
||||
ModernItemModel newItemModel = new ModernItemModel(rangeDispatch, handAnimationOnSwap, oversizedInGui);
|
||||
ModernItemModel newItemModel = new ModernItemModel(rangeDispatch, handAnimationOnSwap, oversizedInGui, swapAnimationScale);
|
||||
try {
|
||||
Files.createDirectories(overridedItemPath.getParent());
|
||||
} catch (IOException e) {
|
||||
|
||||
@@ -2,7 +2,9 @@ package net.momirealms.craftengine.core.pack.model;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
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.MinecraftVersions;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -10,30 +12,36 @@ public class ModernItemModel {
|
||||
private final ItemModel itemModel;
|
||||
private final boolean oversizedInGui;
|
||||
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.itemModel = itemModel;
|
||||
this.oversizedInGui = oversizedInGui;
|
||||
this.swapAnimationScale = swapAnimationScale;
|
||||
}
|
||||
|
||||
public static ModernItemModel fromJson(JsonObject json) {
|
||||
ItemModel model = ItemModels.fromJson(json.getAsJsonObject("model"));
|
||||
return new ModernItemModel(
|
||||
model,
|
||||
!json.has("hand_animation_on_swap") || json.get("hand_animation_on_swap").getAsBoolean(),
|
||||
json.has("oversized_in_gui") && json.get("oversized_in_gui").getAsBoolean()
|
||||
GsonHelper.getAsBoolean(json.get("hand_animation_on_swap"), true),
|
||||
GsonHelper.getAsBoolean(json.get("oversized_in_gui"), false),
|
||||
GsonHelper.getAsFloat(json.get("swap_animation_scale"), 1.0f)
|
||||
);
|
||||
}
|
||||
|
||||
public JsonObject toJson(MinecraftVersion version) {
|
||||
JsonObject json = new JsonObject();
|
||||
if (this.oversizedInGui) {
|
||||
if (this.oversizedInGui && version.isAtOrAbove(MinecraftVersions.V1_21_6)) {
|
||||
json.addProperty("oversized_in_gui", true);
|
||||
}
|
||||
if (!this.handAnimationOnSwap) {
|
||||
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));
|
||||
return json;
|
||||
}
|
||||
@@ -53,4 +61,8 @@ public class ModernItemModel {
|
||||
public boolean oversizedInGui() {
|
||||
return oversizedInGui;
|
||||
}
|
||||
|
||||
public float swapAnimationScale() {
|
||||
return swapAnimationScale;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,4 +122,76 @@ public final class GsonHelper {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user