From aa5b9d12ea35f6020d3f1d8117b6b4684740fc59 Mon Sep 17 00:00:00 2001 From: David Quintana Date: Sun, 12 Apr 2020 21:27:11 +0200 Subject: [PATCH] Add "type" field to global loot modifier jsons. (#6554) * Add "type" field to global loot modifier jsons and fix tests. To avoid binary breaking, "type" defaults to be the same as the filename. * Fix license headers. --- .../common/data/IOptionalTagEntry.java | 19 +++++++++++ .../common/extensions/IForgeTagBuilder.java | 19 +++++++++++ .../loot/GlobalLootModifierSerializer.java | 19 +++++++++++ .../common/loot/IGlobalLootModifier.java | 19 +++++++++++ .../common/loot/LootModifier.java | 19 +++++++++++ .../common/loot/LootModifierManager.java | 32 +++++++++++++++++-- .../loot/GlobalLootModifiersTest.java | 19 +++++++++++ .../loot_modifiers/silk_touch_bamboo.json | 4 +-- .../loot_modifiers/smelting.json | 4 +-- .../loot_modifiers/wheat_harvest.json | 2 +- 10 files changed, 149 insertions(+), 7 deletions(-) diff --git a/src/main/java/net/minecraftforge/common/data/IOptionalTagEntry.java b/src/main/java/net/minecraftforge/common/data/IOptionalTagEntry.java index 30ec98993e..1cb4edaf72 100644 --- a/src/main/java/net/minecraftforge/common/data/IOptionalTagEntry.java +++ b/src/main/java/net/minecraftforge/common/data/IOptionalTagEntry.java @@ -1,3 +1,22 @@ +/* + * Minecraft Forge + * Copyright (c) 2016-2019. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation version 2.1 + * of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + package net.minecraftforge.common.data; import net.minecraft.tags.Tag.ITagEntry; diff --git a/src/main/java/net/minecraftforge/common/extensions/IForgeTagBuilder.java b/src/main/java/net/minecraftforge/common/extensions/IForgeTagBuilder.java index 5a481d92f5..b8c977f592 100644 --- a/src/main/java/net/minecraftforge/common/extensions/IForgeTagBuilder.java +++ b/src/main/java/net/minecraftforge/common/extensions/IForgeTagBuilder.java @@ -1,3 +1,22 @@ +/* + * Minecraft Forge + * Copyright (c) 2016-2019. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation version 2.1 + * of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + package net.minecraftforge.common.extensions; import java.util.Arrays; diff --git a/src/main/java/net/minecraftforge/common/loot/GlobalLootModifierSerializer.java b/src/main/java/net/minecraftforge/common/loot/GlobalLootModifierSerializer.java index 027a8c4f60..aa198ff501 100644 --- a/src/main/java/net/minecraftforge/common/loot/GlobalLootModifierSerializer.java +++ b/src/main/java/net/minecraftforge/common/loot/GlobalLootModifierSerializer.java @@ -1,3 +1,22 @@ +/* + * Minecraft Forge + * Copyright (c) 2016-2019. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation version 2.1 + * of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + package net.minecraftforge.common.loot; import com.google.gson.JsonObject; diff --git a/src/main/java/net/minecraftforge/common/loot/IGlobalLootModifier.java b/src/main/java/net/minecraftforge/common/loot/IGlobalLootModifier.java index e4fe9943cf..17934ce071 100644 --- a/src/main/java/net/minecraftforge/common/loot/IGlobalLootModifier.java +++ b/src/main/java/net/minecraftforge/common/loot/IGlobalLootModifier.java @@ -1,3 +1,22 @@ +/* + * Minecraft Forge + * Copyright (c) 2016-2019. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation version 2.1 + * of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + package net.minecraftforge.common.loot; import java.util.List; diff --git a/src/main/java/net/minecraftforge/common/loot/LootModifier.java b/src/main/java/net/minecraftforge/common/loot/LootModifier.java index 348e9a20b3..51d7af5a38 100644 --- a/src/main/java/net/minecraftforge/common/loot/LootModifier.java +++ b/src/main/java/net/minecraftforge/common/loot/LootModifier.java @@ -1,3 +1,22 @@ +/* + * Minecraft Forge + * Copyright (c) 2016-2019. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation version 2.1 + * of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + package net.minecraftforge.common.loot; import java.util.List; diff --git a/src/main/java/net/minecraftforge/common/loot/LootModifierManager.java b/src/main/java/net/minecraftforge/common/loot/LootModifierManager.java index 3fd8fb8483..fdc618420c 100644 --- a/src/main/java/net/minecraftforge/common/loot/LootModifierManager.java +++ b/src/main/java/net/minecraftforge/common/loot/LootModifierManager.java @@ -1,3 +1,22 @@ +/* + * Minecraft Forge + * Copyright (c) 2016-2019. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation version 2.1 + * of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + package net.minecraftforge.common.loot; import java.io.BufferedReader; @@ -107,8 +126,17 @@ public class LootModifierManager extends JsonReloadListener { } private IGlobalLootModifier deserializeModifier(ResourceLocation location, JsonObject object) { - ILootCondition[] ailootcondition = GSON_INSTANCE.fromJson(object.get("conditions"), ILootCondition[].class); - return ForgeRegistries.LOOT_MODIFIER_SERIALIZERS.getValue(location).read(location, object, ailootcondition); + ILootCondition[] lootConditions = GSON_INSTANCE.fromJson(object.get("conditions"), ILootCondition[].class); + + // For backward compatibility with the initial implementation, fall back to using the location as the type. + // TODO: Remove fallback in 1.16 + ResourceLocation serializer = location; + if (object.has("type")) + { + serializer = new ResourceLocation(JSONUtils.getString(object, "type")); + } + + return ForgeRegistries.LOOT_MODIFIER_SERIALIZERS.getValue(serializer).read(location, object, lootConditions); } public static GlobalLootModifierSerializer getSerializerForName(ResourceLocation resourcelocation) { diff --git a/src/test/java/net/minecraftforge/debug/gameplay/loot/GlobalLootModifiersTest.java b/src/test/java/net/minecraftforge/debug/gameplay/loot/GlobalLootModifiersTest.java index 1eb70c94ab..e124b2a968 100644 --- a/src/test/java/net/minecraftforge/debug/gameplay/loot/GlobalLootModifiersTest.java +++ b/src/test/java/net/minecraftforge/debug/gameplay/loot/GlobalLootModifiersTest.java @@ -1,3 +1,22 @@ +/* + * Minecraft Forge + * Copyright (c) 2016-2019. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation version 2.1 + * of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + package net.minecraftforge.debug.gameplay.loot; import java.util.ArrayList; diff --git a/src/test/resources/data/global_loot_test/loot_modifiers/silk_touch_bamboo.json b/src/test/resources/data/global_loot_test/loot_modifiers/silk_touch_bamboo.json index 3a152a234d..c21599966b 100644 --- a/src/test/resources/data/global_loot_test/loot_modifiers/silk_touch_bamboo.json +++ b/src/test/resources/data/global_loot_test/loot_modifiers/silk_touch_bamboo.json @@ -1,4 +1,5 @@ { + "type": "global_loot_test:silk_touch_bamboo", "conditions": [ { "condition": "minecraft:match_tool", @@ -6,6 +7,5 @@ "item": "minecraft:bamboo" } } - ], - "function": "global_loot_test:silk_touch_bamboo" + ] } \ No newline at end of file diff --git a/src/test/resources/data/global_loot_test/loot_modifiers/smelting.json b/src/test/resources/data/global_loot_test/loot_modifiers/smelting.json index f51dd62f6c..09b17fd901 100644 --- a/src/test/resources/data/global_loot_test/loot_modifiers/smelting.json +++ b/src/test/resources/data/global_loot_test/loot_modifiers/smelting.json @@ -1,4 +1,5 @@ { + "type": "global_loot_test:smelting", "conditions": [ { "condition": "minecraft:match_tool", @@ -13,6 +14,5 @@ ] } } - ], - "function": "global_loot_test:smelting" + ] } \ No newline at end of file diff --git a/src/test/resources/data/global_loot_test/loot_modifiers/wheat_harvest.json b/src/test/resources/data/global_loot_test/loot_modifiers/wheat_harvest.json index be50a6f9e6..4f2491ed2e 100644 --- a/src/test/resources/data/global_loot_test/loot_modifiers/wheat_harvest.json +++ b/src/test/resources/data/global_loot_test/loot_modifiers/wheat_harvest.json @@ -1,4 +1,5 @@ { + "type": "global_loot_test:wheat_harvest", "conditions": [ { "condition": "minecraft:match_tool", @@ -11,7 +12,6 @@ "block":"minecraft:wheat" } ], - "function": "global_loot_test:wheat_seeds_test", "seedItem": "minecraft:wheat_seeds", "numSeeds": 3, "replacement": "minecraft:wheat"