9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2026-01-04 15:41:38 +00:00

refactor(bukkit): 实现配置并且优化性能

This commit is contained in:
jhqwqmc
2025-05-10 18:32:07 +08:00
parent 29b0c9c8c5
commit 79244af744
8 changed files with 111 additions and 210 deletions

View File

@@ -0,0 +1,8 @@
package net.momirealms.craftengine.core.entity;
import net.momirealms.craftengine.core.util.Key;
import org.joml.Quaternionf;
import org.joml.Vector3f;
public record CustomTrident(Key customTridentItemId, Byte displayType, Vector3f translation, Quaternionf rotationLefts) {
}

View File

@@ -1,5 +1,6 @@
package net.momirealms.craftengine.core.item;
import net.momirealms.craftengine.core.entity.CustomTrident;
import net.momirealms.craftengine.core.item.modifier.EquippableModifier;
import net.momirealms.craftengine.core.item.modifier.ItemDataModifier;
import net.momirealms.craftengine.core.pack.misc.EquipmentGeneration;
@@ -9,6 +10,8 @@ import net.momirealms.craftengine.core.util.MiscUtils;
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import net.momirealms.craftengine.core.util.VersionHelper;
import org.jetbrains.annotations.Nullable;
import org.joml.Quaternionf;
import org.joml.Vector3f;
import java.util.*;
import java.util.stream.Collectors;
@@ -22,6 +25,7 @@ public class ItemSettings {
List<AnvilRepairItem> anvilRepairItems = List.of();
boolean renameable = true;
boolean canPlaceRelatedVanillaBlock = false;
CustomTrident customTrident;
private ItemSettings() {}
@@ -50,6 +54,7 @@ public class ItemSettings {
newSettings.anvilRepairItems = settings.anvilRepairItems;
newSettings.renameable = settings.renameable;
newSettings.canPlaceRelatedVanillaBlock = settings.canPlaceRelatedVanillaBlock;
newSettings.customTrident = settings.customTrident;
return newSettings;
}
@@ -65,6 +70,10 @@ public class ItemSettings {
return settings;
}
public CustomTrident customTrident() {
return customTrident;
}
public boolean canPlaceRelatedVanillaBlock() {
return canPlaceRelatedVanillaBlock;
}
@@ -109,6 +118,11 @@ public class ItemSettings {
return this;
}
public ItemSettings customTrident(CustomTrident customTrident) {
this.customTrident = customTrident;
return this;
}
public ItemSettings canPlaceRelatedVanillaBlock(boolean canPlaceRelatedVanillaBlock) {
this.canPlaceRelatedVanillaBlock = canPlaceRelatedVanillaBlock;
return this;
@@ -193,6 +207,14 @@ public class ItemSettings {
boolean bool = (boolean) value;
return settings -> settings.canPlaceRelatedVanillaBlock(bool);
}));
registerFactory("custom-trident", (value -> {
Map<String, Object> args = MiscUtils.castToMap(value, false);
Key customTridentItemId = Key.of(args.get("custom-trident-item").toString());
Byte displayType = Byte.valueOf(args.get("display-type").toString());
Vector3f translation = MiscUtils.getAsVector3f(args.get("translation"), "translation");
Quaternionf rotationLefts = MiscUtils.getAsQuaternionf(args.get("rotation-left"), "rotation-left");
return settings -> settings.customTrident(new CustomTrident(customTridentItemId, displayType, translation, rotationLefts));
}));
}
private static void registerFactory(String id, ItemSettings.Modifier.Factory factory) {

View File

@@ -197,4 +197,16 @@ public class MCUtils {
public static float unpackDegrees(byte degrees) {
return (float)(degrees * 360) / 256.0F;
}
public static int clamp(int value, int min, int max) {
return Math.min(Math.max(value, min), max);
}
public static float clamp(float value, float min, float max) {
return value < min ? min : Math.min(value, max);
}
public static double clamp(double value, double min, double max) {
return value < min ? min : Math.min(value, max);
}
}