Skip to content

Commit

Permalink
Updated block state upgrade schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
RaphiMC committed Nov 3, 2024
1 parent 01fdd73 commit 61aa9fd
Show file tree
Hide file tree
Showing 14 changed files with 560 additions and 1,176 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

public class JsonBlockStateUpgradeSchema extends BlockStateUpgradeSchema {

private static final String NEW_NAME_KEY = "viabedrock:newname_" + UUID.randomUUID();

public JsonBlockStateUpgradeSchema(final JsonObject jsonObject) {
super(jsonObject.get("maxVersionMajor").getAsInt(), jsonObject.get("maxVersionMinor").getAsInt(), jsonObject.get("maxVersionPatch").getAsInt(), jsonObject.get("maxVersionRevision").getAsInt());

Expand All @@ -44,7 +46,6 @@ public JsonBlockStateUpgradeSchema(final JsonObject jsonObject) {
remappedPropertyValuesLookup.put(entry.getKey(), mappings);
}
}

if (jsonObject.has("remappedStates")) {
final JsonObject remappedStates = jsonObject.get("remappedStates").getAsJsonObject();
for (Map.Entry<String, JsonElement> entry : remappedStates.entrySet()) {
Expand Down Expand Up @@ -139,54 +140,67 @@ public JsonBlockStateUpgradeSchema(final JsonObject jsonObject) {
});
}
}
if (jsonObject.has("remappedPropertyValues")) {
final JsonObject remappedPropertyValues = jsonObject.get("remappedPropertyValues").getAsJsonObject();
for (Map.Entry<String, JsonElement> entry : remappedPropertyValues.entrySet()) {
if (jsonObject.has("renamedIds")) {
final JsonObject renamedIds = jsonObject.get("renamedIds").getAsJsonObject();
final Map<String, String> mappings = new HashMap<>();
for (Map.Entry<String, JsonElement> mappingEntry : renamedIds.entrySet()) {
mappings.put(mappingEntry.getKey().toLowerCase(Locale.ROOT), mappingEntry.getValue().getAsString().toLowerCase(Locale.ROOT));
}

this.actions.add(tag -> {
final String name = tag.getStringTag("name").getValue();
if (!mappings.containsKey(name)) return;

tag.putString(NEW_NAME_KEY, mappings.get(name));
});
}
if (jsonObject.has("flattenedProperties")) {
final JsonObject flattenedProperties = jsonObject.get("flattenedProperties").getAsJsonObject();
for (Map.Entry<String, JsonElement> entry : flattenedProperties.entrySet()) {
final String identifier = entry.getKey().toLowerCase(Locale.ROOT);
final Map<String, List<Pair<?, ?>>> mappings = new HashMap<>();
for (Map.Entry<String, JsonElement> mappingEntry : entry.getValue().getAsJsonObject().entrySet()) {
mappings.put(mappingEntry.getKey(), remappedPropertyValuesLookup.get(mappingEntry.getValue().getAsString()));
final JsonObject mappingObject = entry.getValue().getAsJsonObject();
final String prefix = mappingObject.get("prefix").getAsString();
final String flattenedProperty = mappingObject.get("flattenedProperty").getAsString();
final String suffix = mappingObject.get("suffix").getAsString();
final JsonObject flattenedValueRemapsObject = mappingObject.getAsJsonObject("flattenedValueRemaps");
final Map<String, String> flattenedValueRemaps = new HashMap<>();
if (flattenedValueRemapsObject != null) {
for (Map.Entry<String, JsonElement> remap : flattenedValueRemapsObject.entrySet()) {
flattenedValueRemaps.put(remap.getKey(), remap.getValue().getAsString());
}
}

this.actions.add(tag -> {
final String name = tag.getStringTag("name").getValue();
if (!name.equals(identifier)) return;

if (tag.get("states") instanceof CompoundTag states) {
for (Map.Entry<String, List<Pair<?, ?>>> mapping : mappings.entrySet()) {
final Tag property = states.get(mapping.getKey());
if (property == null) continue;
if (!states.contains(flattenedProperty)) return;

final Object value = property.getValue();
for (Pair<?, ?> valueMapping : mapping.getValue()) {
if (valueMapping.key().equals(value)) {
states.put(mapping.getKey(), NbtUtil.createTag(valueMapping.value()));
}
}
}
final String flattenedValue = states.get(flattenedProperty).getValue().toString();
final String flattenedName = prefix + flattenedValueRemaps.getOrDefault(flattenedValue, flattenedValue) + suffix;
tag.putString(NEW_NAME_KEY, flattenedName.toLowerCase(Locale.ROOT));
states.remove(flattenedProperty);
}
});
}
}
if (jsonObject.has("renamedProperties")) {
final JsonObject renamedProperties = jsonObject.get("renamedProperties").getAsJsonObject();
for (Map.Entry<String, JsonElement> entry : renamedProperties.entrySet()) {
if (jsonObject.has("addedProperties")) {
final JsonObject addedProperties = jsonObject.get("addedProperties").getAsJsonObject();
for (Map.Entry<String, JsonElement> entry : addedProperties.entrySet()) {
final String identifier = entry.getKey().toLowerCase(Locale.ROOT);
final Map<String, String> mappings = new HashMap<>();
for (Map.Entry<String, JsonElement> mappingEntry : entry.getValue().getAsJsonObject().entrySet()) {
mappings.put(mappingEntry.getKey(), mappingEntry.getValue().getAsString());
final List<Pair<String, ?>> toAdd = new ArrayList<>();
for (Map.Entry<String, JsonElement> toAddEntry : entry.getValue().getAsJsonObject().entrySet()) {
toAdd.add(new Pair<>(toAddEntry.getKey(), this.getValue(toAddEntry.getValue().getAsJsonObject())));
}

this.actions.add(tag -> {
final String name = tag.getStringTag("name").getValue();
if (!name.equals(identifier)) return;

if (tag.get("states") instanceof CompoundTag states) {
for (Map.Entry<String, String> mapping : mappings.entrySet()) {
final Tag property = states.remove(mapping.getKey());
if (property != null) {
states.put(mapping.getValue(), property);
}
for (Pair<String, ?> property : toAdd) {
states.put(property.key(), NbtUtil.createTag(property.value()));
}
}
});
Expand All @@ -213,41 +227,68 @@ public JsonBlockStateUpgradeSchema(final JsonObject jsonObject) {
});
}
}
if (jsonObject.has("addedProperties")) {
final JsonObject addedProperties = jsonObject.get("addedProperties").getAsJsonObject();
for (Map.Entry<String, JsonElement> entry : addedProperties.entrySet()) {
if (jsonObject.has("remappedPropertyValues")) {
final JsonObject remappedPropertyValues = jsonObject.get("remappedPropertyValues").getAsJsonObject();
for (Map.Entry<String, JsonElement> entry : remappedPropertyValues.entrySet()) {
final String identifier = entry.getKey().toLowerCase(Locale.ROOT);
final List<Pair<String, ?>> toAdd = new ArrayList<>();
for (Map.Entry<String, JsonElement> toAddEntry : entry.getValue().getAsJsonObject().entrySet()) {
toAdd.add(new Pair<>(toAddEntry.getKey(), this.getValue(toAddEntry.getValue().getAsJsonObject())));
final Map<String, List<Pair<?, ?>>> mappings = new HashMap<>();
for (Map.Entry<String, JsonElement> mappingEntry : entry.getValue().getAsJsonObject().entrySet()) {
mappings.put(mappingEntry.getKey(), remappedPropertyValuesLookup.get(mappingEntry.getValue().getAsString()));
}

this.actions.add(tag -> {
final String name = tag.getStringTag("name").getValue();
if (!name.equals(identifier)) return;

if (tag.get("states") instanceof CompoundTag states) {
for (Pair<String, ?> property : toAdd) {
states.put(property.key(), NbtUtil.createTag(property.value()));
for (Map.Entry<String, List<Pair<?, ?>>> mapping : mappings.entrySet()) {
final Tag property = states.get(mapping.getKey());
if (property == null) continue;

final Object value = property.getValue();
for (Pair<?, ?> valueMapping : mapping.getValue()) {
if (valueMapping.key().equals(value)) {
states.put(mapping.getKey(), NbtUtil.createTag(valueMapping.value()));
}
}
}
}
});
}
}
if (jsonObject.has("renamedIds")) {
final JsonObject renamedIds = jsonObject.get("renamedIds").getAsJsonObject();
final Map<String, String> mappings = new HashMap<>();
for (Map.Entry<String, JsonElement> mappingEntry : renamedIds.entrySet()) {
mappings.put(mappingEntry.getKey().toLowerCase(Locale.ROOT), mappingEntry.getValue().getAsString().toLowerCase(Locale.ROOT));
}
if (jsonObject.has("renamedProperties")) {
final JsonObject renamedProperties = jsonObject.get("renamedProperties").getAsJsonObject();
for (Map.Entry<String, JsonElement> entry : renamedProperties.entrySet()) {
final String identifier = entry.getKey().toLowerCase(Locale.ROOT);
final Map<String, String> mappings = new HashMap<>();
for (Map.Entry<String, JsonElement> mappingEntry : entry.getValue().getAsJsonObject().entrySet()) {
mappings.put(mappingEntry.getKey(), mappingEntry.getValue().getAsString());
}

this.actions.add(tag -> {
final String name = tag.getStringTag("name").getValue();
if (!mappings.containsKey(name)) return;
this.actions.add(tag -> {
final String name = tag.getStringTag("name").getValue();
if (!name.equals(identifier)) return;

tag.putString("name", mappings.get(name));
});
if (tag.get("states") instanceof CompoundTag states) {
for (Map.Entry<String, String> mapping : mappings.entrySet()) {
final Tag property = states.remove(mapping.getKey());
if (property != null) {
states.put(mapping.getValue(), property);
}
}
}
});
}
}

// Apply the new name last, because the remappers are expecting the old name
this.actions.add(tag -> {
final String newName = tag.getString(NEW_NAME_KEY, null);
if (newName != null) {
tag.putString("name", newName);
tag.remove(NEW_NAME_KEY);
}
});
}

private Object getValue(final JsonObject obj) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,14 @@
"maxVersionMinor": 19,
"maxVersionPatch": 70,
"maxVersionRevision": 15,
"remappedStates": {
"minecraft:wool": [
{
"oldState": null,
"newFlattenedName": {
"prefix": "minecraft:",
"flattenedProperty": "color",
"suffix": "_wool",
"flattenedValueRemaps": {
"silver": "light_gray"
}
},
"newState": null
"flattenedProperties": {
"minecraft:wool": {
"prefix": "minecraft:",
"flattenedProperty": "color",
"suffix": "_wool",
"flattenedValueRemaps": {
"silver": "light_gray"
}
]
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,21 @@
"maxVersionMinor": 19,
"maxVersionPatch": 80,
"maxVersionRevision": 11,
"remappedStates": {
"minecraft:fence": [
{
"oldState": null,
"newFlattenedName": {
"prefix": "minecraft:",
"flattenedProperty": "wood_type",
"suffix": "_fence"
},
"newState": null
}
],
"minecraft:log": [
{
"oldState": null,
"newFlattenedName": {
"prefix": "minecraft:",
"flattenedProperty": "old_log_type",
"suffix": "_log"
},
"newState": null,
"copiedState": [
"pillar_axis"
]
}
],
"minecraft:log2": [
{
"oldState": null,
"newFlattenedName": {
"prefix": "minecraft:",
"flattenedProperty": "new_log_type",
"suffix": "_log"
},
"newState": null,
"copiedState": [
"pillar_axis"
]
}
]
"flattenedProperties": {
"minecraft:fence": {
"prefix": "minecraft:",
"flattenedProperty": "wood_type",
"suffix": "_fence"
},
"minecraft:log": {
"prefix": "minecraft:",
"flattenedProperty": "old_log_type",
"suffix": "_log"
},
"minecraft:log2": {
"prefix": "minecraft:",
"flattenedProperty": "new_log_type",
"suffix": "_log"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,21 +100,17 @@
}
]
},
"remappedStates": {
"minecraft:carpet": [
{
"oldState": null,
"newFlattenedName": {
"prefix": "minecraft:",
"flattenedProperty": "color",
"suffix": "_carpet",
"flattenedValueRemaps": {
"silver": "light_gray"
}
},
"newState": null
"flattenedProperties": {
"minecraft:carpet": {
"prefix": "minecraft:",
"flattenedProperty": "color",
"suffix": "_carpet",
"flattenedValueRemaps": {
"silver": "light_gray"
}
],
}
},
"remappedStates": {
"minecraft:coral": [
{
"oldState": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,34 +65,22 @@
}
]
},
"remappedStates": {
"minecraft:concrete": [
{
"oldState": null,
"newFlattenedName": {
"prefix": "minecraft:",
"flattenedProperty": "color",
"suffix": "_concrete",
"flattenedValueRemaps": {
"silver": "light_gray"
}
},
"newState": null
"flattenedProperties": {
"minecraft:concrete": {
"prefix": "minecraft:",
"flattenedProperty": "color",
"suffix": "_concrete",
"flattenedValueRemaps": {
"silver": "light_gray"
}
],
"minecraft:shulker_box": [
{
"oldState": null,
"newFlattenedName": {
"prefix": "minecraft:",
"flattenedProperty": "color",
"suffix": "_shulker_box",
"flattenedValueRemaps": {
"silver": "light_gray"
}
},
"newState": null
},
"minecraft:shulker_box": {
"prefix": "minecraft:",
"flattenedProperty": "color",
"suffix": "_shulker_box",
"flattenedValueRemaps": {
"silver": "light_gray"
}
]
}
}
}
Loading

0 comments on commit 61aa9fd

Please sign in to comment.