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

添加死亡保留/损毁物品选项

This commit is contained in:
XiaoMoMi
2025-12-05 23:16:42 +08:00
parent 35b63b1630
commit 8c744dedf7
5 changed files with 173 additions and 12 deletions

View File

@@ -67,6 +67,9 @@ public abstract class AbstractItemManager<I> extends AbstractModelGenerator impl
// 替代配方材料
protected final Map<Key, List<UniqueKey>> ingredientSubstitutes = new HashMap<>();
protected boolean featureFlag$keepOnDeathChance = false;
protected boolean featureFlag$destroyOnDeathChance = false;
protected AbstractItemManager(CraftEngine plugin) {
super(plugin);
this.itemParser = new ItemParser();
@@ -133,6 +136,7 @@ public abstract class AbstractItemManager<I> extends AbstractModelGenerator impl
@Override
public void unload() {
super.clearModelsToGenerate();
this.clearFeatureFlags();
this.customItemsById.clear();
this.customItemsByPath.clear();
this.cachedCustomItemSuggestions.clear();
@@ -147,6 +151,11 @@ public abstract class AbstractItemManager<I> extends AbstractModelGenerator impl
this.ingredientSubstitutes.clear();
}
private void clearFeatureFlags() {
this.featureFlag$keepOnDeathChance = false;
this.featureFlag$destroyOnDeathChance = false;
}
@Override
public Map<Key, Equipment> equipments() {
return Collections.unmodifiableMap(this.equipments);
@@ -205,12 +214,13 @@ public abstract class AbstractItemManager<I> extends AbstractModelGenerator impl
this.cachedTotemSuggestions.add(Suggestion.suggestion(id.toString()));
}
// tags
Set<Key> tags = customItem.settings().tags();
ItemSettings settings = customItem.settings();
Set<Key> tags = settings.tags();
for (Key tag : tags) {
this.customItemTags.computeIfAbsent(tag, k -> new ArrayList<>()).add(customItem.uniqueId());
}
// ingredient substitutes
List<Key> substitutes = customItem.settings().ingredientSubstitutes();
List<Key> substitutes = settings.ingredientSubstitutes();
if (!substitutes.isEmpty()) {
for (Key key : substitutes) {
if (VANILLA_ITEMS.contains(key)) {
@@ -218,6 +228,12 @@ public abstract class AbstractItemManager<I> extends AbstractModelGenerator impl
}
}
}
if (settings.keepOnDeathChance != 0) {
this.featureFlag$keepOnDeathChance = true;
}
if (settings.destroyOnDeathChance != 0) {
this.featureFlag$destroyOnDeathChance = true;
}
}
return true;
}
@@ -317,6 +333,14 @@ public abstract class AbstractItemManager<I> extends AbstractModelGenerator impl
return VANILLA_ITEMS.contains(item);
}
public boolean featureFlag$keepOnDeathChance() {
return featureFlag$keepOnDeathChance;
}
public boolean featureFlag$destroyOnDeathChance() {
return featureFlag$destroyOnDeathChance;
}
protected abstract CustomItem.Builder<I> createPlatformItemBuilder(UniqueKey id, Key material, Key clientBoundMaterial);
protected abstract void registerArmorTrimPattern(Collection<Key> equipments);

View File

@@ -47,6 +47,8 @@ public class ItemSettings {
Color dyeColor;
@Nullable
Color fireworkColor;
float keepOnDeathChance = 0f;
float destroyOnDeathChance = 0f;
Map<CustomDataType<?>, Object> customData = new IdentityHashMap<>(4);
private ItemSettings() {}
@@ -109,6 +111,8 @@ public class ItemSettings {
newSettings.dyeColor = settings.dyeColor;
newSettings.fireworkColor = settings.fireworkColor;
newSettings.ingredientSubstitutes = settings.ingredientSubstitutes;
newSettings.keepOnDeathChance = settings.keepOnDeathChance;
newSettings.destroyOnDeathChance = settings.destroyOnDeathChance;
newSettings.customData = new IdentityHashMap<>(settings.customData);
return newSettings;
}
@@ -231,6 +235,14 @@ public class ItemSettings {
return this.compostProbability;
}
public float keepOnDeathChance() {
return this.keepOnDeathChance;
}
public float destroyOnDeathChance() {
return this.destroyOnDeathChance;
}
public ItemSettings fireworkColor(Color color) {
this.fireworkColor = color;
return this;
@@ -331,6 +343,16 @@ public class ItemSettings {
return this;
}
public ItemSettings keepOnDeathChance(float keepChance) {
this.keepOnDeathChance = keepChance;
return this;
}
public ItemSettings destroyOnDeathChance(float destroyChance) {
this.destroyOnDeathChance = destroyChance;
return this;
}
@FunctionalInterface
public interface Modifier {
@@ -361,6 +383,14 @@ public class ItemSettings {
boolean bool = ResourceConfigUtils.getAsBoolean(value, "enchantable");
return settings -> settings.canEnchant(bool);
}));
registerFactory("keep-on-death-chance", (value -> {
float chance = ResourceConfigUtils.getAsFloat(value, "keep-on-death-chance");
return settings -> settings.keepOnDeathChance(MiscUtils.clamp(chance, 0, 1));
}));
registerFactory("destroy-on-death-chance", (value -> {
float chance = ResourceConfigUtils.getAsFloat(value, "destroy-on-death-chance");
return settings -> settings.destroyOnDeathChance(MiscUtils.clamp(chance, 0, 1));
}));
registerFactory("renameable", (value -> {
boolean bool = ResourceConfigUtils.getAsBoolean(value, "renameable");
return settings -> settings.renameable(bool);

View File

@@ -31,7 +31,7 @@ public class ComponentsModifier<I> implements ItemDataModifier<I> {
}
public List<Pair<Key, Tag>> components() {
return arguments;
return this.arguments;
}
private Tag parseValue(Object value) {