From 67285a0cd1f717f2242fbd2765473d282ff4636c Mon Sep 17 00:00:00 2001 From: Kyle Koder Date: Mon, 3 Jun 2019 10:15:06 -0700 Subject: [PATCH 01/12] Almost done adding item drop customization for spawned mobs...I think. --- .../spawnercontrol/SpawnerEventHandler.java | 52 +++++++++++++++++++ .../spawnercontrol/config/SpawnerConfig.java | 18 +++++-- 2 files changed, 67 insertions(+), 3 deletions(-) diff --git a/src/main/java/ladysnake/spawnercontrol/SpawnerEventHandler.java b/src/main/java/ladysnake/spawnercontrol/SpawnerEventHandler.java index 8c0285f..4d43810 100644 --- a/src/main/java/ladysnake/spawnercontrol/SpawnerEventHandler.java +++ b/src/main/java/ladysnake/spawnercontrol/SpawnerEventHandler.java @@ -11,6 +11,8 @@ import net.minecraft.block.BlockMobSpawner; import net.minecraft.entity.EntityList; import net.minecraft.entity.EntityLiving; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.monster.IMob; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; @@ -28,6 +30,7 @@ import net.minecraft.world.WorldServer; import net.minecraftforge.event.AttachCapabilitiesEvent; import net.minecraftforge.event.entity.living.LivingDeathEvent; +import net.minecraftforge.event.entity.living.LivingDropsEvent; import net.minecraftforge.event.entity.living.LivingExperienceDropEvent; import net.minecraftforge.event.entity.living.LivingSpawnEvent; import net.minecraftforge.event.world.BlockEvent; @@ -37,6 +40,7 @@ import net.minecraftforge.fml.common.eventhandler.EventPriority; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.gameevent.TickEvent; +import net.minecraftforge.fml.common.registry.ForgeRegistries; import net.minecraftforge.fml.relauncher.Side; import java.util.*; @@ -211,6 +215,54 @@ public static void onLivingExperienceDrop(LivingExperienceDropEvent event) { } } + @SubscribeEvent + public static void onLivingItemDrop(LivingDropsEvent event) { + EntityLivingBase livingBase = event.getEntityLiving(); + SpawnerConfig cfg = SpawnerUtil.getConfig(livingBase.getEntityData().getTag(NBT_TAG_SPAWNER_POS)); + if (cfg != null) { + try { + ResourceLocation rl = EntityList.getKey(event.getEntity()); + if (rl != null) { + SpawnerConfig.MobLoot.MobLootEntry entry = cfg.mobLoot.lootEntries.get(rl); + List drops = event.getDrops(); + if (entry.removeAllItems) { + drops.clear(); + } + else { + for (EntityItem drop : drops.toArray(new EntityItem[0])) { + ItemStack stack = drop.getItem(); + for (String s : entry.removedItems) { + String[] split = s.split(":"); + if (stack.getUnlocalizedName().equals(split[0] + ":" + split[1]) + && (split.length < 3 || stack.getMetadata() == Integer.parseInt(split[2]))) { + drops.remove(drop); + } + } + } + } + World world = livingBase.world; + double x = livingBase.posX, y = livingBase.posY, z = livingBase.posZ; + for (String s : entry.addedItems) + { + String[] split = s.split(":"); + if (split.length < 5 || world.rand.nextInt(Integer.parseInt(split[4])) == 0) { + ResourceLocation itemRL = new ResourceLocation(split[0], split[1]); + Item item = ForgeRegistries.ITEMS.getValue(itemRL); + if (item == null) + { + //Try/catch handles this if null + item = Item.getItemFromBlock(ForgeRegistries.BLOCKS.getValue(itemRL)); + } + drops.add(new EntityItem(world, x, y, z, new ItemStack(item, split.length < 3 ? 1 : Integer.parseInt(split[2]), split.length < 4 ? 0 : Integer.parseInt(split[3])))); + } + } + } + } catch (Exception e) { + SpawnerControl.LOGGER.error("Error while handling spawned item drops", e); + } + } + } + /** * Changes the amount of experience dropped by a spawner when broken. * Drops from the mod's spawner are also handled here diff --git a/src/main/java/ladysnake/spawnercontrol/config/SpawnerConfig.java b/src/main/java/ladysnake/spawnercontrol/config/SpawnerConfig.java index 7cb4d5f..4cfa0e2 100644 --- a/src/main/java/ladysnake/spawnercontrol/config/SpawnerConfig.java +++ b/src/main/java/ladysnake/spawnercontrol/config/SpawnerConfig.java @@ -51,7 +51,7 @@ public static class SpawnConditions { public static class MobLoot { - public MobLootEntry defaultValues = new MobLootEntry(1, 0); + public MobLootEntry defaultValues = new MobLootEntry(1, 0, false, new String[0], new String[0]); @Config.Comment({"Individual xp drop multiplier configuration for mobs spawned by this spawner type", "Format: 'modid:entity:xpMultiplier(:flatXp)' (flatXp is optional)"}) public String[] xpMultipliers = new String[0]; @@ -65,7 +65,7 @@ public static class MobLoot { try { float xpMultiplier = Float.parseFloat(split[2]); int flatXpIncrease = split.length > 3 ? Integer.parseInt(split[3]) : defaultValues.flatXpIncrease; - return new MobLootEntry(xpMultiplier, flatXpIncrease); + return new MobLootEntry(xpMultiplier, flatXpIncrease, false, new String[0], new String[0]); } catch (NumberFormatException e) { SpawnerControl.LOGGER.warn("Bad mob spawner loot config option : {}", s); } @@ -76,9 +76,13 @@ public static class MobLoot { public static class MobLootEntry { - public MobLootEntry(float defaultXpMultiplier, int flatXpIncrease) { + public MobLootEntry(float defaultXpMultiplier, int flatXpIncrease, boolean removeAllItems, String[] removedItems, String[] addedItems) { this.xpMultiplier = defaultXpMultiplier; this.flatXpIncrease = flatXpIncrease; + + this.removeAllItems = removeAllItems; + this.removedItems = removedItems; + this.addedItems = addedItems; } @Config.Comment("xp drop multiplier for mobs spawned by this spawner type") @@ -87,6 +91,14 @@ public MobLootEntry(float defaultXpMultiplier, int flatXpIncrease) { @Config.Comment("Flat xp modifier that will be added to mobs spawned by this spawner type") public int flatXpIncrease; + @Config.Comment({"Remove all existing item drops from the mobs spawned by this spawner", "'Added Items' are added afterwards"}) + public boolean removeAllItems; + + @Config.Comment({"Which items to remove from the drops of the mobs spawned", "Format: 'modid:item(:meta)' (meta is optional)", "If 'Remove All Items' is true, this does nothing"}) + public String[] removedItems; + + @Config.Comment({"Which items to add to the drops of the mobs spawned", "Format: 'modid:item(:count(:meta(:chance)))' (count, meta and chance are optional)"}) + public String[] addedItems; } } } From cd0e938bb967917b4128e89af488f6bff6f67787 Mon Sep 17 00:00:00 2001 From: Kyle Koder Date: Mon, 3 Jun 2019 14:00:21 -0700 Subject: [PATCH 02/12] Done adding spawner-specific, mob-specific item drop settings...in theory. Needs testing. --- .../spawnercontrol/config/SpawnerConfig.java | 48 +++++++++++++++++-- 1 file changed, 44 insertions(+), 4 deletions(-) diff --git a/src/main/java/ladysnake/spawnercontrol/config/SpawnerConfig.java b/src/main/java/ladysnake/spawnercontrol/config/SpawnerConfig.java index 4cfa0e2..34d747a 100644 --- a/src/main/java/ladysnake/spawnercontrol/config/SpawnerConfig.java +++ b/src/main/java/ladysnake/spawnercontrol/config/SpawnerConfig.java @@ -7,6 +7,9 @@ import net.minecraft.util.ResourceLocation; import net.minecraftforge.common.config.Config; +import java.util.Arrays; +import java.util.List; + public class SpawnerConfig { @Config.Comment("Regroups config options aiming to alter mob spawners spawning conditions") @@ -56,22 +59,59 @@ public static class MobLoot { @Config.Comment({"Individual xp drop multiplier configuration for mobs spawned by this spawner type", "Format: 'modid:entity:xpMultiplier(:flatXp)' (flatXp is optional)"}) public String[] xpMultipliers = new String[0]; + @Config.Comment({"Individual item drop removal configuration for mobs spawned by this spawner type", "Format: 'modid:entity(,modid:item(:meta))(,modid:item(:meta))...'", "Anything in parenthesis is optional, and you can enter as many items as you want", "If don't enter any items, all item drops are removed from the mob"}) + public String[] itemDropRemovals = new String[0]; + + @Config.Comment({"Individual item drop addition configuration for mobs spawned by this spawner type", "Format: 'modid:entity,modid:item(:count(:meta(:chance)))(,modid:item(:count(:meta(:chance))))...'", "Anything in parenthesis is optional, and you can enter as many items as you want", "Eg: minecraft:skeleton,minecraft:dye:100:15:0.5,minecraft:bone:1:1:1"}) + public String[] itemDropAdditions = new String[0]; + @Config.Ignore public LoadingCache lootEntries = CacheBuilder.newBuilder().build(CacheLoader.from(rl -> { if (rl == null) return defaultValues; + float xpMultiplier = defaultValues.xpMultiplier; + int flatXpIncrease = defaultValues.flatXpIncrease; + boolean removeAllItems = defaultValues.removeAllItems; + List removedItems = Arrays.asList(defaultValues.removedItems); + List addedItems = Arrays.asList(defaultValues.addedItems); for (String s : xpMultipliers) { String[] split = s.split(":"); if (split[0].equals(rl.getResourcePath()) && split[1].equals(rl.getResourceDomain())) { try { - float xpMultiplier = Float.parseFloat(split[2]); - int flatXpIncrease = split.length > 3 ? Integer.parseInt(split[3]) : defaultValues.flatXpIncrease; - return new MobLootEntry(xpMultiplier, flatXpIncrease, false, new String[0], new String[0]); + xpMultiplier = Float.parseFloat(split[2]); + flatXpIncrease = split.length > 3 ? Integer.parseInt(split[3]) : defaultValues.flatXpIncrease; } catch (NumberFormatException e) { SpawnerControl.LOGGER.warn("Bad mob spawner loot config option : {}", s); } + break; + } + } + for (String s : itemDropRemovals) { + String[] split = s.split(","); + String[] mobSplit = split[0].split(":"); + if (mobSplit[0].equals(rl.getResourcePath()) && mobSplit[1].equals(rl.getResourceDomain())) { + try { + removedItems = Arrays.asList(split); + removedItems.remove(0); + removeAllItems = removedItems.size() == 0; + } catch (Exception e) { + SpawnerControl.LOGGER.warn("Bad mob spawner loot config option : {}", s); + } + break; + } + } + for (String s : itemDropAdditions) { + String[] split = s.split(":"); + if (split[0].equals(rl.getResourcePath()) && split[1].equals(rl.getResourceDomain())) { + try { + addedItems = Arrays.asList(split); + addedItems.remove(0); + } catch (Exception e) { + SpawnerControl.LOGGER.warn("Bad mob spawner loot config option : {}", s); + } + break; } } - return defaultValues; + return new MobLootEntry(xpMultiplier, flatXpIncrease, removeAllItems, removedItems.toArray(new String[0]), addedItems.toArray(new String[0])); })); public static class MobLootEntry { From e6a024c06650ea70e378df36b99dcd8d00b42f4f Mon Sep 17 00:00:00 2001 From: Kyle Koder Date: Mon, 3 Jun 2019 14:05:58 -0700 Subject: [PATCH 03/12] Changed one of the new config comments --- .../java/ladysnake/spawnercontrol/config/SpawnerConfig.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ladysnake/spawnercontrol/config/SpawnerConfig.java b/src/main/java/ladysnake/spawnercontrol/config/SpawnerConfig.java index 34d747a..ffe939e 100644 --- a/src/main/java/ladysnake/spawnercontrol/config/SpawnerConfig.java +++ b/src/main/java/ladysnake/spawnercontrol/config/SpawnerConfig.java @@ -59,7 +59,7 @@ public static class MobLoot { @Config.Comment({"Individual xp drop multiplier configuration for mobs spawned by this spawner type", "Format: 'modid:entity:xpMultiplier(:flatXp)' (flatXp is optional)"}) public String[] xpMultipliers = new String[0]; - @Config.Comment({"Individual item drop removal configuration for mobs spawned by this spawner type", "Format: 'modid:entity(,modid:item(:meta))(,modid:item(:meta))...'", "Anything in parenthesis is optional, and you can enter as many items as you want", "If don't enter any items, all item drops are removed from the mob"}) + @Config.Comment({"Individual item drop removal configuration for mobs spawned by this spawner type", "Format: 'modid:entity(,modid:item(:meta))(,modid:item(:meta))...'", "Anything in parenthesis is optional, and you can enter as many items as you want", "If don't enter any items, all item drops are removed from the mob (itemDropAdditions are added afterwards)"}) public String[] itemDropRemovals = new String[0]; @Config.Comment({"Individual item drop addition configuration for mobs spawned by this spawner type", "Format: 'modid:entity,modid:item(:count(:meta(:chance)))(,modid:item(:count(:meta(:chance))))...'", "Anything in parenthesis is optional, and you can enter as many items as you want", "Eg: minecraft:skeleton,minecraft:dye:100:15:0.5,minecraft:bone:1:1:1"}) From 256793af34522a83ba3b500ebab3bba1c5ff228b Mon Sep 17 00:00:00 2001 From: Kyle Koder Date: Mon, 3 Jun 2019 14:18:36 -0700 Subject: [PATCH 04/12] Fixed incorrect item drop chance equation --- src/main/java/ladysnake/spawnercontrol/SpawnerEventHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ladysnake/spawnercontrol/SpawnerEventHandler.java b/src/main/java/ladysnake/spawnercontrol/SpawnerEventHandler.java index 4d43810..bd4a8c3 100644 --- a/src/main/java/ladysnake/spawnercontrol/SpawnerEventHandler.java +++ b/src/main/java/ladysnake/spawnercontrol/SpawnerEventHandler.java @@ -245,7 +245,7 @@ public static void onLivingItemDrop(LivingDropsEvent event) { for (String s : entry.addedItems) { String[] split = s.split(":"); - if (split.length < 5 || world.rand.nextInt(Integer.parseInt(split[4])) == 0) { + if (split.length < 5 || world.rand.nextFloat() < Double.parseDouble(split[4])) { ResourceLocation itemRL = new ResourceLocation(split[0], split[1]); Item item = ForgeRegistries.ITEMS.getValue(itemRL); if (item == null) From f55b07facc6d03169944c19833800efe861ea39b Mon Sep 17 00:00:00 2001 From: Kyle Koder Date: Mon, 3 Jun 2019 15:18:24 -0700 Subject: [PATCH 05/12] Changed item drop event priority to LOWEST to improve compat --- src/main/java/ladysnake/spawnercontrol/SpawnerEventHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ladysnake/spawnercontrol/SpawnerEventHandler.java b/src/main/java/ladysnake/spawnercontrol/SpawnerEventHandler.java index bd4a8c3..1c283a3 100644 --- a/src/main/java/ladysnake/spawnercontrol/SpawnerEventHandler.java +++ b/src/main/java/ladysnake/spawnercontrol/SpawnerEventHandler.java @@ -215,7 +215,7 @@ public static void onLivingExperienceDrop(LivingExperienceDropEvent event) { } } - @SubscribeEvent + @SubscribeEvent(priority = EventPriority.LOWEST) public static void onLivingItemDrop(LivingDropsEvent event) { EntityLivingBase livingBase = event.getEntityLiving(); SpawnerConfig cfg = SpawnerUtil.getConfig(livingBase.getEntityData().getTag(NBT_TAG_SPAWNER_POS)); From 959fa7f79e0f8e6c9247be72c7d8e903e05a7d22 Mon Sep 17 00:00:00 2001 From: Kyle Koder Date: Fri, 7 Jun 2019 07:33:53 -0700 Subject: [PATCH 06/12] Fixed unmatched coding style (2 occurrences) --- .../java/ladysnake/spawnercontrol/SpawnerEventHandler.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/main/java/ladysnake/spawnercontrol/SpawnerEventHandler.java b/src/main/java/ladysnake/spawnercontrol/SpawnerEventHandler.java index 1c283a3..7fbdd46 100644 --- a/src/main/java/ladysnake/spawnercontrol/SpawnerEventHandler.java +++ b/src/main/java/ladysnake/spawnercontrol/SpawnerEventHandler.java @@ -227,8 +227,7 @@ public static void onLivingItemDrop(LivingDropsEvent event) { List drops = event.getDrops(); if (entry.removeAllItems) { drops.clear(); - } - else { + } else { for (EntityItem drop : drops.toArray(new EntityItem[0])) { ItemStack stack = drop.getItem(); for (String s : entry.removedItems) { @@ -248,8 +247,7 @@ public static void onLivingItemDrop(LivingDropsEvent event) { if (split.length < 5 || world.rand.nextFloat() < Double.parseDouble(split[4])) { ResourceLocation itemRL = new ResourceLocation(split[0], split[1]); Item item = ForgeRegistries.ITEMS.getValue(itemRL); - if (item == null) - { + if (item == null) { //Try/catch handles this if null item = Item.getItemFromBlock(ForgeRegistries.BLOCKS.getValue(itemRL)); } From a1484b8e893c16e7de8b7ac471208327cf0890bc Mon Sep 17 00:00:00 2001 From: Kyle Koder Date: Fri, 7 Jun 2019 07:39:30 -0700 Subject: [PATCH 07/12] Fixed mismatched comparisons --- .../java/ladysnake/spawnercontrol/SpawnerEventHandler.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/ladysnake/spawnercontrol/SpawnerEventHandler.java b/src/main/java/ladysnake/spawnercontrol/SpawnerEventHandler.java index 7fbdd46..991147a 100644 --- a/src/main/java/ladysnake/spawnercontrol/SpawnerEventHandler.java +++ b/src/main/java/ladysnake/spawnercontrol/SpawnerEventHandler.java @@ -244,7 +244,7 @@ public static void onLivingItemDrop(LivingDropsEvent event) { for (String s : entry.addedItems) { String[] split = s.split(":"); - if (split.length < 5 || world.rand.nextFloat() < Double.parseDouble(split[4])) { + if (split.length < 5 || world.rand.nextDouble() < Double.parseDouble(split[4])) { ResourceLocation itemRL = new ResourceLocation(split[0], split[1]); Item item = ForgeRegistries.ITEMS.getValue(itemRL); if (item == null) { @@ -306,7 +306,7 @@ else if (block instanceof BlockMobSpawner && MSCConfig.alterVanillaSpawner) int count = split.length >= 3 ? Integer.parseInt(split[2]) : 1; int meta = split.length >= 4 ? Integer.parseInt(split[3]) : 0; // default chance is 1 - if (split.length < 5 || event.getWorld().rand.nextFloat() < Double.parseDouble(split[4])) + if (split.length < 5 || event.getWorld().rand.nextDouble() < Double.parseDouble(split[4])) drops.add(new ItemStack(item, count, meta)); } } catch (NumberFormatException ignored) { From c4883100eaef0cca283203ee29b183cdaa5ac1a7 Mon Sep 17 00:00:00 2001 From: Kyle Koder Date: Fri, 7 Jun 2019 07:46:04 -0700 Subject: [PATCH 08/12] Added explicit check for failure --- .../java/ladysnake/spawnercontrol/SpawnerEventHandler.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/ladysnake/spawnercontrol/SpawnerEventHandler.java b/src/main/java/ladysnake/spawnercontrol/SpawnerEventHandler.java index 991147a..cdab8b2 100644 --- a/src/main/java/ladysnake/spawnercontrol/SpawnerEventHandler.java +++ b/src/main/java/ladysnake/spawnercontrol/SpawnerEventHandler.java @@ -14,6 +14,7 @@ import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.monster.IMob; +import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTBase; @@ -251,7 +252,11 @@ public static void onLivingItemDrop(LivingDropsEvent event) { //Try/catch handles this if null item = Item.getItemFromBlock(ForgeRegistries.BLOCKS.getValue(itemRL)); } - drops.add(new EntityItem(world, x, y, z, new ItemStack(item, split.length < 3 ? 1 : Integer.parseInt(split[2]), split.length < 4 ? 0 : Integer.parseInt(split[3])))); + if (item != Items.AIR) { + drops.add(new EntityItem(world, x, y, z, new ItemStack(item, split.length < 3 ? 1 : Integer.parseInt(split[2]), split.length < 4 ? 0 : Integer.parseInt(split[3])))); + } else { + SpawnerControl.LOGGER.error("Error while handling spawned item drops"); + } } } } From e50c2591d3b81389d82dbbb29ad2653774027fb5 Mon Sep 17 00:00:00 2001 From: Kyle Koder Date: Fri, 7 Jun 2019 07:47:22 -0700 Subject: [PATCH 09/12] Removed no-longer relevant comment (was actually inaccurate to begin with; there was never a NPE being caught here) --- src/main/java/ladysnake/spawnercontrol/SpawnerEventHandler.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/ladysnake/spawnercontrol/SpawnerEventHandler.java b/src/main/java/ladysnake/spawnercontrol/SpawnerEventHandler.java index cdab8b2..4bec19d 100644 --- a/src/main/java/ladysnake/spawnercontrol/SpawnerEventHandler.java +++ b/src/main/java/ladysnake/spawnercontrol/SpawnerEventHandler.java @@ -249,7 +249,6 @@ public static void onLivingItemDrop(LivingDropsEvent event) { ResourceLocation itemRL = new ResourceLocation(split[0], split[1]); Item item = ForgeRegistries.ITEMS.getValue(itemRL); if (item == null) { - //Try/catch handles this if null item = Item.getItemFromBlock(ForgeRegistries.BLOCKS.getValue(itemRL)); } if (item != Items.AIR) { From d17f99f12d60a094a81fdaae6340f3068dcf2db1 Mon Sep 17 00:00:00 2001 From: Kyle Koder Date: Fri, 7 Jun 2019 07:52:57 -0700 Subject: [PATCH 10/12] Fixed Exception type in catch --- src/main/java/ladysnake/spawnercontrol/SpawnerEventHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ladysnake/spawnercontrol/SpawnerEventHandler.java b/src/main/java/ladysnake/spawnercontrol/SpawnerEventHandler.java index 4bec19d..cfc4627 100644 --- a/src/main/java/ladysnake/spawnercontrol/SpawnerEventHandler.java +++ b/src/main/java/ladysnake/spawnercontrol/SpawnerEventHandler.java @@ -259,7 +259,7 @@ public static void onLivingItemDrop(LivingDropsEvent event) { } } } - } catch (Exception e) { + } catch (NumberFormatException e) { SpawnerControl.LOGGER.error("Error while handling spawned item drops", e); } } From 68c9ec93ae3f797e8153e36c83a3e0d31f4e7800 Mon Sep 17 00:00:00 2001 From: Kyle Koder Date: Sat, 8 Jun 2019 00:08:28 -0700 Subject: [PATCH 11/12] Added necessary catch for ExecutionException (had forgotten to add it in when making the Exception catch specific) --- src/main/java/ladysnake/spawnercontrol/SpawnerEventHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ladysnake/spawnercontrol/SpawnerEventHandler.java b/src/main/java/ladysnake/spawnercontrol/SpawnerEventHandler.java index cfc4627..329d11c 100644 --- a/src/main/java/ladysnake/spawnercontrol/SpawnerEventHandler.java +++ b/src/main/java/ladysnake/spawnercontrol/SpawnerEventHandler.java @@ -259,7 +259,7 @@ public static void onLivingItemDrop(LivingDropsEvent event) { } } } - } catch (NumberFormatException e) { + } catch (NumberFormatException | ExecutionException e) { SpawnerControl.LOGGER.error("Error while handling spawned item drops", e); } } From a1960f125f5e5be35ee7b3100c24359da4775fe2 Mon Sep 17 00:00:00 2001 From: Kyle Koder Date: Sat, 8 Jun 2019 00:17:08 -0700 Subject: [PATCH 12/12] Added explicit variables for two of the split Strings --- .../java/ladysnake/spawnercontrol/SpawnerEventHandler.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/ladysnake/spawnercontrol/SpawnerEventHandler.java b/src/main/java/ladysnake/spawnercontrol/SpawnerEventHandler.java index 329d11c..6a4778a 100644 --- a/src/main/java/ladysnake/spawnercontrol/SpawnerEventHandler.java +++ b/src/main/java/ladysnake/spawnercontrol/SpawnerEventHandler.java @@ -252,7 +252,9 @@ public static void onLivingItemDrop(LivingDropsEvent event) { item = Item.getItemFromBlock(ForgeRegistries.BLOCKS.getValue(itemRL)); } if (item != Items.AIR) { - drops.add(new EntityItem(world, x, y, z, new ItemStack(item, split.length < 3 ? 1 : Integer.parseInt(split[2]), split.length < 4 ? 0 : Integer.parseInt(split[3])))); + int quantity = split.length < 3 ? 1 : Integer.parseInt(split[2]); + int meta = split.length < 4 ? 0 : Integer.parseInt(split[3]); + drops.add(new EntityItem(world, x, y, z, new ItemStack(item, quantity, meta))); } else { SpawnerControl.LOGGER.error("Error while handling spawned item drops"); }