Skip to content

Commit

Permalink
Fix deserializer reading from the wrong field on AddEntryLootModifier
Browse files Browse the repository at this point in the history
See SlimeKnights/TinkersConstruct#5268

Was fixed on 1.19 as the codec migration ensured matching name on both
For 1.18, fixed by supporting both names for now, prioritize the new name but allow the old name if set. Datagen now uses the new name.
  • Loading branch information
KnightMiner committed Dec 10, 2024
1 parent fc955a3 commit 73c8e84
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/main/java/slimeknights/mantle/loot/AddEntryLootModifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,23 @@
import com.google.gson.JsonObject;
import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.GsonHelper;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.storage.loot.Deserializers;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.level.storage.loot.entries.LootPoolEntryContainer;
import net.minecraft.world.level.storage.loot.Deserializers;
import net.minecraft.world.level.storage.loot.predicates.LootItemCondition;
import net.minecraft.world.level.storage.loot.functions.LootItemFunction;
import net.minecraft.world.level.storage.loot.functions.LootItemFunctions;
import net.minecraft.util.GsonHelper;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.storage.loot.predicates.LootItemCondition;
import net.minecraftforge.common.data.GlobalLootModifierProvider;
import net.minecraftforge.common.loot.GlobalLootModifierSerializer;
import net.minecraftforge.common.loot.LootModifier;
import slimeknights.mantle.Mantle;
import slimeknights.mantle.loot.builder.AbstractLootModifierBuilder;
import slimeknights.mantle.loot.condition.EmptyModifierLootCondition;
import slimeknights.mantle.loot.condition.ILootModifierCondition;

import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.BiFunction;
import java.util.function.Consumer;
Expand Down Expand Up @@ -82,6 +79,8 @@ public AddEntryLootModifier read(ResourceLocation location, JsonObject object, L
// loot modifier conditions
ILootModifierCondition[] modifierConditions;
if (object.has("post_conditions")) {
modifierConditions = GSON.fromJson(GsonHelper.getAsJsonArray(object, "post_conditions"), ILootModifierCondition[].class);
} else if (object.has("modifier_conditions")) {
modifierConditions = GSON.fromJson(GsonHelper.getAsJsonArray(object, "modifier_conditions"), ILootModifierCondition[].class);
} else {
modifierConditions = new ILootModifierCondition[0];
Expand All @@ -101,7 +100,7 @@ public AddEntryLootModifier read(ResourceLocation location, JsonObject object, L
public JsonObject write(AddEntryLootModifier instance) {
JsonObject object = makeConditions(instance.conditions);
if (instance.modifierConditions.length > 0) {
object.add("modifier_conditions", GSON.toJsonTree(instance.modifierConditions, ILootModifierCondition[].class));
object.add("post_conditions", GSON.toJsonTree(instance.modifierConditions, ILootModifierCondition[].class));
}
object.add("entry", GSON.toJsonTree(instance.entry, LootPoolEntryContainer.class));
if (instance.functions.length > 0) {
Expand Down

0 comments on commit 73c8e84

Please sign in to comment.