From c2f8bfc5b46dee8037d2033073c7e76df1c483f2 Mon Sep 17 00:00:00 2001 From: WinDanesz <31292708+WinDanesz@users.noreply.github.com> Date: Mon, 3 Jan 2022 14:47:33 +0100 Subject: [PATCH] Added injectMobDrops setting to easily disable mob loot injection for all entities --- .../java/electroblob/wizardry/Settings.java | 9 ++++ .../wizardry/registry/WizardryLoot.java | 42 +++++++++++-------- .../assets/ebwizardry/lang/en_us.lang | 2 + 3 files changed, 36 insertions(+), 17 deletions(-) diff --git a/src/main/java/electroblob/wizardry/Settings.java b/src/main/java/electroblob/wizardry/Settings.java index c1aacb55..6a7bbc39 100644 --- a/src/main/java/electroblob/wizardry/Settings.java +++ b/src/main/java/electroblob/wizardry/Settings.java @@ -198,6 +198,8 @@ public final class Settings { public boolean blindnessTweak = true; /** [Server-only] Whether using bonemeal on grass blocks has a chance to grow crystal flowers. */ public boolean bonemealGrowsCrystalFlowers = true; + /** [Server-only] Whether to enable Wizardry mob loot injection. Allows an easier switch instead of blacklisting all entities. */ + public boolean injectMobDrops = true; /** * [Server-only] List of registry names of entities which summoned creatures are allowed to attack, in addition * to the defaults. @@ -807,6 +809,13 @@ public final class Settings { blindnessTweak = property.getBoolean(); propOrder.add(property.getName()); + property = config.get(TWEAKS_CATEGORY, "injectMobDrops", true, + "Whether to inject Wizardry loot to mobs, based on the loot table 'Mob Loot Table Whitelist' / 'Mob Loot Table Blacklist' settings. If disabled, the lists won't have any effect!"); + property.setLanguageKey("config." + Wizardry.MODID + ".inject_mob_drops"); + Wizardry.proxy.setToNamedBooleanEntry(property); + injectMobDrops = property.getBoolean(); + propOrder.add(property.getName()); + property = config.get(TWEAKS_CATEGORY, "mobLootTableWhitelist", new String[0], "Whitelist for loot tables to inject additional mob drops (as specified in loot_tables/entities/mob_additions.json) into. Wizardry makes a best guess as to which loot tables belong to hostile mobs, but this may not always be correct or appropriate; add loot table locations (not entity IDs) to this list to manually include them."); property.setLanguageKey("config." + Wizardry.MODID + ".mob_loot_table_whitelist"); property.setRequiresMcRestart(true); diff --git a/src/main/java/electroblob/wizardry/registry/WizardryLoot.java b/src/main/java/electroblob/wizardry/registry/WizardryLoot.java index a0df5807..15442715 100644 --- a/src/main/java/electroblob/wizardry/registry/WizardryLoot.java +++ b/src/main/java/electroblob/wizardry/registry/WizardryLoot.java @@ -6,7 +6,11 @@ import electroblob.wizardry.loot.RandomSpell; import electroblob.wizardry.loot.WizardSpell; import net.minecraft.entity.EnumCreatureType; import net.minecraft.util.ResourceLocation; -import net.minecraft.world.storage.loot.*; +import net.minecraft.world.storage.loot.LootEntry; +import net.minecraft.world.storage.loot.LootEntryTable; +import net.minecraft.world.storage.loot.LootPool; +import net.minecraft.world.storage.loot.LootTableList; +import net.minecraft.world.storage.loot.RandomValueRange; import net.minecraft.world.storage.loot.conditions.LootCondition; import net.minecraft.world.storage.loot.functions.LootFunctionManager; import net.minecraftforge.event.LootTableLoadEvent; @@ -90,23 +94,27 @@ public final class WizardryLoot { event.getTable().addPool(getAdditive(Wizardry.MODID + ":chests/jungle_dispenser_additions", Wizardry.MODID + "_additional_dispenser_loot")); } // Mob drops - // Let's hope mods will play nice and store their entity loot tables under 'entities' or 'entity' - // If not, packmakers will have to sort it out themselves using the whitelist/blacklist - if(Arrays.asList(Wizardry.settings.mobLootTableWhitelist).contains(event.getName())){ - event.getTable().addPool(getAdditive(Wizardry.MODID + ":entities/mob_additions", Wizardry.MODID + "_additional_mob_drops")); - - }else if(!Arrays.asList(Wizardry.settings.mobLootTableBlacklist).contains(event.getName()) - && event.getName().getPath().contains("entities") || event.getName().getPath().contains("entity")){ - // Get the filename of the loot table json, for well-behaved mods this will be the entity name - String[] split = event.getName().getPath().split("/"); - String entityName = split[split.length - 1]; - - EntityEntry entry = ForgeRegistries.ENTITIES.getValue(new ResourceLocation(entityName)); - if(entry == null) return; // If this is true it didn't work :( - Class entityClass = entry.getEntityClass(); - - if(EnumCreatureType.MONSTER.getCreatureClass().isAssignableFrom(entityClass)){ + if (Wizardry.settings.injectMobDrops) { + // Let's hope mods will play nice and store their entity loot tables under 'entities' or 'entity' + // If not, packmakers will have to sort it out themselves using the whitelist/blacklist + if (Arrays.asList(Wizardry.settings.mobLootTableWhitelist).contains(event.getName())) { event.getTable().addPool(getAdditive(Wizardry.MODID + ":entities/mob_additions", Wizardry.MODID + "_additional_mob_drops")); + + } else if (!Arrays.asList(Wizardry.settings.mobLootTableBlacklist).contains(event.getName()) + && event.getName().getPath().contains("entities") || event.getName().getPath().contains("entity")) { + // Get the filename of the loot table json, for well-behaved mods this will be the entity name + String[] split = event.getName().getPath().split("/"); + String entityName = split[split.length - 1]; + + EntityEntry entry = ForgeRegistries.ENTITIES.getValue(new ResourceLocation(entityName)); + if (entry == null) { + return; // If this is true it didn't work :( + } + Class entityClass = entry.getEntityClass(); + + if (EnumCreatureType.MONSTER.getCreatureClass().isAssignableFrom(entityClass)) { + event.getTable().addPool(getAdditive(Wizardry.MODID + ":entities/mob_additions", Wizardry.MODID + "_additional_mob_drops")); + } } } // Fishing loot diff --git a/src/main/resources/assets/ebwizardry/lang/en_us.lang b/src/main/resources/assets/ebwizardry/lang/en_us.lang index 7a123df4..7821d9fc 100644 --- a/src/main/resources/assets/ebwizardry/lang/en_us.lang +++ b/src/main/resources/assets/ebwizardry/lang/en_us.lang @@ -1580,6 +1580,8 @@ config.ebwizardry.mob_loot_table_whitelist=Mob Loot Table Whitelist config.ebwizardry.mob_loot_table_whitelist.tooltip=Whitelist for loot tables to inject additional mob drops (as specified in loot_tables/entities/mob_additions.json) into. Wizardry makes a best guess as to which loot tables belong to hostile mobs, but this may not always be correct or appropriate; add loot table locations (not entity IDs) to this list to manually include them. config.ebwizardry.mob_loot_table_blacklist=Mob Loot Table Blacklist config.ebwizardry.mob_loot_table_blacklist.tooltip=Blacklist for loot tables to inject additional mob drops (as specified in loot_tables/entities/mob_additions.json) into. Wizardry makes a best guess as to which loot tables belong to hostile mobs, but this may not always be correct or appropriate; add loot table locations (not entity IDs) to this list to manually exclude them. +config.ebwizardry.inject_mob_drops=Allow Wizardry Mob Loot +config.ebwizardry.inject_mob_drops.tooltip=Whether to inject Wizardry loot to mobs, based on the loot table 'Mob Loot Table Whitelist' / 'Mob Loot Table Blacklist' settings. If disabled, the lists won't have any effect! config.ebwizardry.mob_spawn_dimensions=Mob Spawning Dimensions config.ebwizardry.mob_spawn_dimensions.tooltip=List of ids of dimensions in which wizardry's hostile mobs can spawn. config.ebwizardry.mob_spawn_biome_blacklist=Mob Spawning Biome Blacklist