Revisions for ⁨Halp loot tables⁩

View the changes made to this paste.

unlisted ⁨4⁩ ⁨files⁩ 2022-01-10 23:44:14 UTC

akm_body_dungeon.json

@@ -0,0 +1,9 @@

+{
+  "conditions": [
+    {
+      "condition": "forge:loot_table_id",
+      "loot_table_id": "minecraft:chests/simple_dungeon"
+    }
+  ],
+  "addition": "moguns:akm_body"
+}
\ No newline at end of file

global_loot_modifiers.json

@@ -0,0 +1,6 @@

+{
+  "replace": false,
+  "entries": [
+    "moguns:akm_body_dungeon"
+  ]
+}
\ No newline at end of file

LootEventBusEvents.java

@@ -0,0 +1,12 @@

[email protected](modid = MoGuns.MOD_ID, bus = Mod.EventBusSubscriber.Bus.FORGE)
+public class LootEventBusEvents {
+
+    @SubscribeEvent
+    public static void registerModifierSerializers(@Nonnull final RegistryEvent.Register<GlobalLootModifierSerializer<?>>
+                                                           event) {
+
+                new AKMBodyStructureAdditionModifier.Serializer().setRegistryName
+                        (new ResourceLocation(MoGuns.MOD_ID,"akm_body_dungeon"));
+
+    }
+}
\ No newline at end of file

AKMBodyStructureAdditionModifier.java

@@ -0,0 +1,36 @@

+public class AKMBodyStructureAdditionModifier extends LootModifier {
+    private final Item addition;
+
+    protected AKMBodyStructureAdditionModifier(ILootCondition[] conditionsIn, Item addition) {
+        super(conditionsIn);
+        this.addition = addition;
+    }
+
+    @Nonnull
+    @Override
+    protected List<ItemStack> doApply(List<ItemStack> generatedLoot, LootContext context) {
+        // generatedLoot is the loot that would be dropped, if we wouldn't add or replace
+        // anything!
+        if(context.getRandom().nextFloat() > 0.15) {
+            generatedLoot.add(new ItemStack(addition, 1));
+        }
+        return generatedLoot;
+    }
+
+    public static class Serializer extends GlobalLootModifierSerializer<AKMBodyStructureAdditionModifier> {
+
+        @Override
+        public AKMBodyStructureAdditionModifier read(ResourceLocation name, JsonObject object, ILootCondition[] conditionsIn) {
+            Item addition = ForgeRegistries.ITEMS.getValue(
+                    new ResourceLocation(JSONUtils.getString(object, "addition")));
+            return new AKMBodyStructureAdditionModifier(conditionsIn, addition);
+        }
+
+        @Override
+        public JsonObject write(AKMBodyStructureAdditionModifier instance) {
+            JsonObject json = makeConditions(instance.conditions);
+            json.addProperty("addition", ForgeRegistries.ITEMS.getKey(instance.addition).toString());
+            return json;
+        }
+    }
+}