mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-24 01:19:24 +00:00
添加展示架revision
This commit is contained in:
@@ -60,14 +60,26 @@ public class SelectItemModel implements ItemModel {
|
||||
item.add("model", itemModel.apply(version));
|
||||
Either<JsonElement, List<JsonElement>> either = entry.getKey();
|
||||
if (either.primary().isPresent()) {
|
||||
item.add("when", either.primary().get());
|
||||
JsonElement remap = this.property.remap(either.primary().get(), version);
|
||||
if (remap != null) {
|
||||
item.add("when", remap);
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
List<JsonElement> list = either.fallback().get();
|
||||
JsonArray whens = new JsonArray();
|
||||
for (JsonElement e : list) {
|
||||
whens.add(e);
|
||||
JsonElement remap = this.property.remap(e, version);
|
||||
if (remap != null) {
|
||||
whens.add(remap);
|
||||
}
|
||||
}
|
||||
if (!whens.isEmpty()) {
|
||||
item.add("when", whens);
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
item.add("when", whens);
|
||||
}
|
||||
array.add(item);
|
||||
}
|
||||
@@ -85,6 +97,17 @@ public class SelectItemModel implements ItemModel {
|
||||
@Override
|
||||
public List<Revision> revisions() {
|
||||
List<Revision> versions = new ArrayList<>();
|
||||
for (Map.Entry<Either<JsonElement, List<JsonElement>>, ItemModel> entry : this.whenMap.entrySet()) {
|
||||
Either<JsonElement, List<JsonElement>> when = entry.getKey();
|
||||
if (when.primary().isPresent()) {
|
||||
versions.addAll(this.property.revisions(when.primary().get()));
|
||||
} else {
|
||||
List<JsonElement> list = when.fallback().get();
|
||||
for (JsonElement e : list) {
|
||||
versions.addAll(this.property.revisions(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (this.fallBack != null) {
|
||||
versions.addAll(this.fallBack.revisions());
|
||||
}
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
package net.momirealms.craftengine.core.pack.model.select;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import net.momirealms.craftengine.core.pack.revision.Revision;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import net.momirealms.craftengine.core.util.MinecraftVersion;
|
||||
import net.momirealms.craftengine.core.util.MinecraftVersions;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class DisplayContextSelectProperty implements SelectProperty {
|
||||
public static final DisplayContextSelectProperty INSTANCE = new DisplayContextSelectProperty();
|
||||
public static final SimpleSelectProperty.Factory FACTORY = new SimpleSelectProperty.Factory();
|
||||
public static final SimpleSelectProperty.Reader READER = new SimpleSelectProperty.Reader();
|
||||
|
||||
@Override
|
||||
public Key type() {
|
||||
return SelectProperties.DISPLAY_CONTEXT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(JsonObject jsonObject) {
|
||||
jsonObject.addProperty("property", type().toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Revision> revisions(JsonElement element) {
|
||||
return SelectProperty.super.revisions(element);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable JsonElement remap(JsonElement element, MinecraftVersion version) {
|
||||
if (version.isBelow(MinecraftVersions.V1_21_9) && element instanceof JsonPrimitive primitive && primitive.isString()) {
|
||||
if (primitive.getAsString().equals("on_shelf")) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return element;
|
||||
}
|
||||
|
||||
public static class Factory implements SelectPropertyFactory {
|
||||
@Override
|
||||
public SelectProperty create(Map<String, Object> arguments) {
|
||||
return INSTANCE;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Reader implements SelectPropertyReader {
|
||||
@Override
|
||||
public SelectProperty read(JsonObject json) {
|
||||
return INSTANCE;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -30,8 +30,8 @@ public class SelectProperties {
|
||||
registerReader(CONTEXT_DIMENSION, SimpleSelectProperty.READER);
|
||||
registerFactory(CONTEXT_ENTITY_TYPE, SimpleSelectProperty.FACTORY);
|
||||
registerReader(CONTEXT_ENTITY_TYPE, SimpleSelectProperty.READER);
|
||||
registerFactory(DISPLAY_CONTEXT, SimpleSelectProperty.FACTORY);
|
||||
registerReader(DISPLAY_CONTEXT, SimpleSelectProperty.READER);
|
||||
registerFactory(DISPLAY_CONTEXT, DisplayContextSelectProperty.FACTORY);
|
||||
registerReader(DISPLAY_CONTEXT, DisplayContextSelectProperty.READER);
|
||||
registerFactory(MAIN_HAND, MainHandSelectProperty.FACTORY);
|
||||
registerReader(MAIN_HAND, MainHandSelectProperty.READER);
|
||||
registerFactory(TRIM_MATERIAL, TrimMaterialSelectProperty.FACTORY);
|
||||
|
||||
@@ -1,11 +1,26 @@
|
||||
package net.momirealms.craftengine.core.pack.model.select;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import net.momirealms.craftengine.core.pack.revision.Revision;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import net.momirealms.craftengine.core.util.MinecraftVersion;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public interface SelectProperty extends Consumer<JsonObject> {
|
||||
|
||||
Key type();
|
||||
|
||||
default List<Revision> revisions(JsonElement element) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
default JsonElement remap(JsonElement element, MinecraftVersion version) {
|
||||
return element;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user