Skip to content

Commit

Permalink
fix: 1.21.3 tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
mworzala committed Nov 2, 2024
1 parent de98e2d commit 275ac28
Show file tree
Hide file tree
Showing 3 changed files with 552 additions and 611 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
import ca.spottedleaf.dataconverter.minecraft.datatypes.MCTypeRegistry;
import ca.spottedleaf.dataconverter.types.MapType;
import ca.spottedleaf.dataconverter.types.nbt.NBTMapType;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.datafixers.util.Pair;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.TagParser;
import net.kyori.adventure.nbt.CompoundBinaryTag;
import net.kyori.adventure.nbt.TagStringIO;

import java.util.HashMap;
import java.util.Map;

Expand All @@ -17,6 +17,7 @@ public final class V4061 {
private static final int VERSION = MCVersions.V24W34A + 1;

private static final Map<Pair<MapType<String>, MapType<String>>, String> CONVERT_MAP = new HashMap<>();

static {
addConversion("trial_chamber/breeze", "{simultaneous_mobs: 1.0f, simultaneous_mobs_added_per_player: 0.5f, spawn_potentials: [{data: {entity: {id: \"minecraft:breeze\"}}, weight: 1}], ticks_between_spawn: 20, total_mobs: 2.0f, total_mobs_added_per_player: 1.0f}", "{loot_tables_to_eject: [{data: \"minecraft:spawners/ominous/trial_chamber/key\", weight: 3}, {data: \"minecraft:spawners/ominous/trial_chamber/consumables\", weight: 7}], simultaneous_mobs: 2.0f, total_mobs: 4.0f}");
addConversion("trial_chamber/melee/husk", "{simultaneous_mobs: 3.0f, simultaneous_mobs_added_per_player: 0.5f, spawn_potentials: [{data: {entity: {id: \"minecraft:husk\"}}, weight: 1}], ticks_between_spawn: 20}", "{loot_tables_to_eject: [{data: \"minecraft:spawners/ominous/trial_chamber/key\", weight: 3}, {data: \"minecraft:spawners/ominous/trial_chamber/consumables\", weight: 7}], spawn_potentials: [{data: {entity: {id: \"minecraft:husk\"}, equipment: {loot_table: \"minecraft:equipment/trial_chamber_melee\", slot_drop_chances: 0.0f}}, weight: 1}]}");
Expand All @@ -37,48 +38,48 @@ public final class V4061 {
private static void addConversion(final String keyPath, final String normalsNBT, final String ominoussNBT) {
final String fullKey = "minecraft:".concat(keyPath);

final CompoundTag normalNBT = parseNBT(normalsNBT);
final CompoundBinaryTag normalNBT = parseNBT(normalsNBT);
final MapType<String> normalMapType = new NBTMapType(normalNBT);
final CompoundTag ominousNBT = parseNBT(ominoussNBT);
final CompoundBinaryTag ominousNBT = parseNBT(ominoussNBT);

final CompoundTag ominousMerged = normalNBT.copy().merge(ominousNBT);
final CompoundBinaryTag ominousMerged = normalNBT.put(ominousNBT);

CONVERT_MAP.put(Pair.of(normalMapType, new NBTMapType(ominousNBT)), fullKey);
CONVERT_MAP.put(Pair.of(normalMapType, new NBTMapType(ominousMerged)), fullKey);
CONVERT_MAP.put(Pair.of(normalMapType, new NBTMapType(removeDefaults(ominousMerged.copy()))), fullKey);
CONVERT_MAP.put(Pair.of(normalMapType, new NBTMapType(removeDefaults(ominousMerged))), fullKey);
}

private static CompoundTag parseNBT(final String sNBT) {
private static CompoundBinaryTag parseNBT(final String sNBT) {
try {
return TagParser.parseTag(sNBT);
} catch (final CommandSyntaxException ex) {
return TagStringIO.get().asCompound(sNBT);
} catch (final Throwable ex) {
throw new IllegalArgumentException("Failed to parse NBT: " + sNBT, ex);
}
}

private static CompoundTag removeDefaults(final CompoundTag config) {
private static CompoundBinaryTag removeDefaults(CompoundBinaryTag config) {
if (config.getInt("spawn_range") == 4) {
config.remove("spawn_range");
config = config.remove("spawn_range");
}

if (config.getFloat("total_mobs") == 6.0F) {
config.remove("total_mobs");
config = config.remove("total_mobs");
}

if (config.getFloat("simultaneous_mobs") == 2.0F) {
config.remove("simultaneous_mobs");
config = config.remove("simultaneous_mobs");
}

if (config.getFloat("total_mobs_added_per_player") == 2.0F) {
config.remove("total_mobs_added_per_player");
config = config.remove("total_mobs_added_per_player");
}

if (config.getFloat("simultaneous_mobs_added_per_player") == 1.0F) {
config.remove("simultaneous_mobs_added_per_player");
config = config.remove("simultaneous_mobs_added_per_player");
}

if (config.getInt("ticks_between_spawn") == 40) {
config.remove("ticks_between_spawn");
config = config.remove("ticks_between_spawn");
}

return config;
Expand Down Expand Up @@ -108,5 +109,6 @@ public MapType<String> convert(final MapType<String> data, final long sourceVers
});
}

private V4061() {}
private V4061() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
import ca.spottedleaf.dataconverter.minecraft.datatypes.MCTypeRegistry;
import ca.spottedleaf.dataconverter.types.MapType;
import ca.spottedleaf.dataconverter.types.TypeUtil;
import com.google.common.escape.Escaper;
import com.google.common.escape.Escapers;

public final class V4068 {
public static final Escaper ESCAPER = Escapers.builder().addEscape('"', "\\\"").addEscape('\\', "\\\\").build();
// Used to be Escapers.builder().addEscape('"', "\\\"").addEscape('\\', "\\\\").build();
// This probably doesnt quite do the same things as guava, but it should be good enough.
public static String escape(String input) {
if (input == null) return null;
return input.replace("\\", "\\\\").replace("\"", "\\\"");
}

private static final int VERSION = MCVersions.V24W38A + 2;

Expand All @@ -33,7 +36,7 @@ private static void convertLock(final MapType<String> root, final String srcPath
final MapType<String> lockComponents = typeUtil.createEmptyMap();
newLock.setMap("components", lockComponents);

lockComponents.setString("minecraft:custom_name", ESCAPER.escape(lock));
lockComponents.setString("minecraft:custom_name", escape(lock));
}
}

Expand All @@ -60,5 +63,6 @@ public MapType<String> convert(final MapType<String> data, final long sourceVers
});
}

private V4068() {}
private V4068() {
}
}
Loading

0 comments on commit 275ac28

Please sign in to comment.