146 lines
14 KiB
Java
146 lines
14 KiB
Java
/*
|
|
* Decompiled with CFR 0.152.
|
|
*
|
|
* Could not load the following classes:
|
|
* com.mojang.brigadier.exceptions.CommandSyntaxException
|
|
* com.mojang.datafixers.DSL
|
|
* com.mojang.datafixers.Typed
|
|
* com.mojang.datafixers.schemas.Schema
|
|
* com.mojang.datafixers.util.Pair
|
|
* com.mojang.logging.LogUtils
|
|
* com.mojang.serialization.Dynamic
|
|
* com.mojang.serialization.DynamicOps
|
|
* org.slf4j.Logger
|
|
*/
|
|
package net.minecraft.util.datafix.fixes;
|
|
|
|
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
|
import com.mojang.datafixers.DSL;
|
|
import com.mojang.datafixers.Typed;
|
|
import com.mojang.datafixers.schemas.Schema;
|
|
import com.mojang.datafixers.util.Pair;
|
|
import com.mojang.logging.LogUtils;
|
|
import com.mojang.serialization.Dynamic;
|
|
import com.mojang.serialization.DynamicOps;
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
import java.util.Optional;
|
|
import net.minecraft.nbt.CompoundTag;
|
|
import net.minecraft.nbt.NbtOps;
|
|
import net.minecraft.nbt.Tag;
|
|
import net.minecraft.nbt.TagParser;
|
|
import net.minecraft.resources.Identifier;
|
|
import net.minecraft.util.datafix.fixes.NamedEntityFix;
|
|
import net.minecraft.util.datafix.fixes.References;
|
|
import org.slf4j.Logger;
|
|
|
|
public class TrialSpawnerConfigInRegistryFix
|
|
extends NamedEntityFix {
|
|
private static final Logger LOGGER = LogUtils.getLogger();
|
|
|
|
public TrialSpawnerConfigInRegistryFix(Schema outputSchema) {
|
|
super(outputSchema, false, "TrialSpawnerConfigInRegistryFix", References.BLOCK_ENTITY, "minecraft:trial_spawner");
|
|
}
|
|
|
|
public Dynamic<?> fixTag(Dynamic<Tag> input) {
|
|
Optional normalConfig = input.get("normal_config").result();
|
|
if (normalConfig.isEmpty()) {
|
|
return input;
|
|
}
|
|
Optional ominousConfig = input.get("ominous_config").result();
|
|
if (ominousConfig.isEmpty()) {
|
|
return input;
|
|
}
|
|
Identifier registryLocation = VanillaTrialChambers.CONFIGS_TO_KEY.get(Pair.of((Object)((Dynamic)normalConfig.get()), (Object)((Dynamic)ominousConfig.get())));
|
|
if (registryLocation == null) {
|
|
return input;
|
|
}
|
|
return input.set("normal_config", input.createString(registryLocation.withSuffix("/normal").toString())).set("ominous_config", input.createString(registryLocation.withSuffix("/ominous").toString()));
|
|
}
|
|
|
|
@Override
|
|
protected Typed<?> fix(Typed<?> entity) {
|
|
return entity.update(DSL.remainderFinder(), input -> {
|
|
DynamicOps inputType = input.getOps();
|
|
Dynamic<?> result = this.fixTag((Dynamic<Tag>)input.convert((DynamicOps)NbtOps.INSTANCE));
|
|
return result.convert(inputType);
|
|
});
|
|
}
|
|
|
|
private static final class VanillaTrialChambers {
|
|
public static final Map<Pair<Dynamic<Tag>, Dynamic<Tag>>, Identifier> CONFIGS_TO_KEY = new HashMap<Pair<Dynamic<Tag>, Dynamic<Tag>>, Identifier>();
|
|
|
|
private VanillaTrialChambers() {
|
|
}
|
|
|
|
private static void register(Identifier location, String normalNbt, String ominousNbt) {
|
|
try {
|
|
CompoundTag normalTag = VanillaTrialChambers.parse(normalNbt);
|
|
CompoundTag ominousTag = VanillaTrialChambers.parse(ominousNbt);
|
|
CompoundTag ominousMergedTag = normalTag.copy().merge(ominousTag);
|
|
CompoundTag ominousMergedTagDefaultsOmitted = VanillaTrialChambers.removeDefaults(ominousMergedTag.copy());
|
|
Dynamic<Tag> dynamicNormal = VanillaTrialChambers.asDynamic(normalTag);
|
|
CONFIGS_TO_KEY.put((Pair<Dynamic<Tag>, Dynamic<Tag>>)Pair.of(dynamicNormal, VanillaTrialChambers.asDynamic(ominousTag)), location);
|
|
CONFIGS_TO_KEY.put((Pair<Dynamic<Tag>, Dynamic<Tag>>)Pair.of(dynamicNormal, VanillaTrialChambers.asDynamic(ominousMergedTag)), location);
|
|
CONFIGS_TO_KEY.put((Pair<Dynamic<Tag>, Dynamic<Tag>>)Pair.of(dynamicNormal, VanillaTrialChambers.asDynamic(ominousMergedTagDefaultsOmitted)), location);
|
|
}
|
|
catch (RuntimeException e) {
|
|
throw new IllegalStateException("Failed to parse NBT for " + String.valueOf(location), e);
|
|
}
|
|
}
|
|
|
|
private static Dynamic<Tag> asDynamic(CompoundTag normalTag) {
|
|
return new Dynamic((DynamicOps)NbtOps.INSTANCE, (Object)normalTag);
|
|
}
|
|
|
|
private static CompoundTag parse(String nbt) {
|
|
try {
|
|
return TagParser.parseCompoundFully(nbt);
|
|
}
|
|
catch (CommandSyntaxException e) {
|
|
throw new IllegalArgumentException("Failed to parse Trial Spawner NBT config: " + nbt, e);
|
|
}
|
|
}
|
|
|
|
private static CompoundTag removeDefaults(CompoundTag tag) {
|
|
if (tag.getIntOr("spawn_range", 0) == 4) {
|
|
tag.remove("spawn_range");
|
|
}
|
|
if (tag.getFloatOr("total_mobs", 0.0f) == 6.0f) {
|
|
tag.remove("total_mobs");
|
|
}
|
|
if (tag.getFloatOr("simultaneous_mobs", 0.0f) == 2.0f) {
|
|
tag.remove("simultaneous_mobs");
|
|
}
|
|
if (tag.getFloatOr("total_mobs_added_per_player", 0.0f) == 2.0f) {
|
|
tag.remove("total_mobs_added_per_player");
|
|
}
|
|
if (tag.getFloatOr("simultaneous_mobs_added_per_player", 0.0f) == 1.0f) {
|
|
tag.remove("simultaneous_mobs_added_per_player");
|
|
}
|
|
if (tag.getIntOr("ticks_between_spawn", 0) == 40) {
|
|
tag.remove("ticks_between_spawn");
|
|
}
|
|
return tag;
|
|
}
|
|
|
|
static {
|
|
VanillaTrialChambers.register(Identifier.withDefaultNamespace("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}");
|
|
VanillaTrialChambers.register(Identifier.withDefaultNamespace("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}]}");
|
|
VanillaTrialChambers.register(Identifier.withDefaultNamespace("trial_chamber/melee/spider"), "{simultaneous_mobs: 3.0f, simultaneous_mobs_added_per_player: 0.5f, spawn_potentials: [{data: {entity: {id: \"minecraft:spider\"}}, 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}],simultaneous_mobs: 4.0f, total_mobs: 12.0f}");
|
|
VanillaTrialChambers.register(Identifier.withDefaultNamespace("trial_chamber/melee/zombie"), "{simultaneous_mobs: 3.0f, simultaneous_mobs_added_per_player: 0.5f, spawn_potentials: [{data: {entity: {id: \"minecraft:zombie\"}}, 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:zombie\"}, equipment: {loot_table: \"minecraft:equipment/trial_chamber_melee\", slot_drop_chances: 0.0f}}, weight: 1}]}");
|
|
VanillaTrialChambers.register(Identifier.withDefaultNamespace("trial_chamber/ranged/poison_skeleton"), "{simultaneous_mobs: 3.0f, simultaneous_mobs_added_per_player: 0.5f, spawn_potentials: [{data: {entity: {id: \"minecraft:bogged\"}}, 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:bogged\"}, equipment: {loot_table: \"minecraft:equipment/trial_chamber_ranged\", slot_drop_chances: 0.0f}}, weight: 1}]}");
|
|
VanillaTrialChambers.register(Identifier.withDefaultNamespace("trial_chamber/ranged/skeleton"), "{simultaneous_mobs: 3.0f, simultaneous_mobs_added_per_player: 0.5f, spawn_potentials: [{data: {entity: {id: \"minecraft:skeleton\"}}, 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:skeleton\"}, equipment: {loot_table: \"minecraft:equipment/trial_chamber_ranged\", slot_drop_chances: 0.0f}}, weight: 1}]}");
|
|
VanillaTrialChambers.register(Identifier.withDefaultNamespace("trial_chamber/ranged/stray"), "{simultaneous_mobs: 3.0f, simultaneous_mobs_added_per_player: 0.5f, spawn_potentials: [{data: {entity: {id: \"minecraft:stray\"}}, 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:stray\"}, equipment: {loot_table: \"minecraft:equipment/trial_chamber_ranged\", slot_drop_chances: 0.0f}}, weight: 1}]}");
|
|
VanillaTrialChambers.register(Identifier.withDefaultNamespace("trial_chamber/slow_ranged/poison_skeleton"), "{simultaneous_mobs: 4.0f, simultaneous_mobs_added_per_player: 2.0f, spawn_potentials: [{data: {entity: {id: \"minecraft:bogged\"}}, weight: 1}], ticks_between_spawn: 160}", "{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:bogged\"}, equipment: {loot_table: \"minecraft:equipment/trial_chamber_ranged\", slot_drop_chances: 0.0f}}, weight: 1}]}");
|
|
VanillaTrialChambers.register(Identifier.withDefaultNamespace("trial_chamber/slow_ranged/skeleton"), "{simultaneous_mobs: 4.0f, simultaneous_mobs_added_per_player: 2.0f, spawn_potentials: [{data: {entity: {id: \"minecraft:skeleton\"}}, weight: 1}], ticks_between_spawn: 160}", "{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:skeleton\"}, equipment: {loot_table: \"minecraft:equipment/trial_chamber_ranged\", slot_drop_chances: 0.0f}}, weight: 1}]}");
|
|
VanillaTrialChambers.register(Identifier.withDefaultNamespace("trial_chamber/slow_ranged/stray"), "{simultaneous_mobs: 4.0f, simultaneous_mobs_added_per_player: 2.0f, spawn_potentials: [{data: {entity: {id: \"minecraft:stray\"}}, weight: 1}], ticks_between_spawn: 160}", "{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:stray\"}, equipment: {loot_table: \"minecraft:equipment/trial_chamber_ranged\", slot_drop_chances: 0.0f}}, weight: 1}]}");
|
|
VanillaTrialChambers.register(Identifier.withDefaultNamespace("trial_chamber/small_melee/baby_zombie"), "{simultaneous_mobs: 2.0f, simultaneous_mobs_added_per_player: 0.5f, spawn_potentials: [{data: {entity: {IsBaby: 1b, id: \"minecraft:zombie\"}}, 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: {IsBaby: 1b, id: \"minecraft:zombie\"}, equipment: {loot_table: \"minecraft:equipment/trial_chamber_melee\", slot_drop_chances: 0.0f}}, weight: 1}]}");
|
|
VanillaTrialChambers.register(Identifier.withDefaultNamespace("trial_chamber/small_melee/cave_spider"), "{simultaneous_mobs: 3.0f, simultaneous_mobs_added_per_player: 0.5f, spawn_potentials: [{data: {entity: {id: \"minecraft:cave_spider\"}}, 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}], simultaneous_mobs: 4.0f, total_mobs: 12.0f}");
|
|
VanillaTrialChambers.register(Identifier.withDefaultNamespace("trial_chamber/small_melee/silverfish"), "{simultaneous_mobs: 3.0f, simultaneous_mobs_added_per_player: 0.5f, spawn_potentials: [{data: {entity: {id: \"minecraft:silverfish\"}}, 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}], simultaneous_mobs: 4.0f, total_mobs: 12.0f}");
|
|
VanillaTrialChambers.register(Identifier.withDefaultNamespace("trial_chamber/small_melee/slime"), "{simultaneous_mobs: 3.0f, simultaneous_mobs_added_per_player: 0.5f, spawn_potentials: [{data: {entity: {Size: 1, id: \"minecraft:slime\"}}, weight: 3}, {data: {entity: {Size: 2, id: \"minecraft:slime\"}}, 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}], simultaneous_mobs: 4.0f, total_mobs: 12.0f}");
|
|
}
|
|
}
|
|
}
|
|
|