diff --git a/src/main/java/techreborn/blocks/BlockOre.java b/src/main/java/techreborn/blocks/BlockOre.java index 0b3a84127..b2dd8112b 100644 --- a/src/main/java/techreborn/blocks/BlockOre.java +++ b/src/main/java/techreborn/blocks/BlockOre.java @@ -31,7 +31,6 @@ import net.minecraft.block.state.BlockStateContainer; import net.minecraft.block.state.IBlockState; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.NonNullList; @@ -48,7 +47,6 @@ import reborncore.common.registration.RebornRegistry; import reborncore.common.registration.impl.ConfigRegistry; import reborncore.common.util.ArrayUtils; import reborncore.common.util.OreDrop; -import reborncore.common.util.OreDropSet; import reborncore.common.util.StringUtils; import techreborn.client.TechRebornCreativeTabMisc; import techreborn.events.TRRecipeHandler; @@ -58,7 +56,6 @@ import techreborn.items.ItemGems; import techreborn.lib.ModInfo; import techreborn.world.config.IOreNameProvider; -import java.util.ArrayList; import java.util.List; import java.util.Random; @@ -71,8 +68,30 @@ public class BlockOre extends Block implements IOreNameProvider { "lead", "silver" }; private static final List oreNamesList = Lists.newArrayList(ArrayUtils.arrayToLowercase(ores)); public static final PropertyString VARIANTS = new PropertyString("type", oreNamesList); - @ConfigRegistry(category = "blocks", key = "secondaryDropChance", comment = "Secondary Gem drop chance") - public static double secondaryDropChance = 0.5; + @ConfigRegistry(config = "misc", category = "blocks", key = "rubyMinQuatity", comment = "Minimum quantity of Ruby gems per Ruby ore") + public static int rubyMinQuatity = 1; + @ConfigRegistry(config = "misc", category = "blocks", key = "rubyMaxQuantity", comment = "Maximum quantity of Ruby gems per Ruby ore") + public static int rubyMaxQuantity = 2; + @ConfigRegistry(config = "misc", category = "blocks", key = "sapphireMinQuantity", comment = "Minimum quantity of Sapphire gems per Sapphire ore") + public static int sapphireMinQuantity = 1; + @ConfigRegistry(config = "misc", category = "blocks", key = "sapphireMaxQuantity", comment = "Maximum quantity of Sapphire gems per Sapphire ore") + public static int sapphireMaxQuantity = 2; + @ConfigRegistry(config = "misc", category = "blocks", key = "pyriteMinQuatity", comment = "Minimum quantity of Pyrite dust per Pyrite ore") + public static int pyriteMinQuatity = 1; + @ConfigRegistry(config = "misc", category = "blocks", key = "pyriteMaxQuantity", comment = "Maximum quantity of Pyrite dust per Pyrite ore") + public static int pyriteMaxQuantity = 2; + @ConfigRegistry(config = "misc", category = "blocks", key = "sodaliteMinQuatity", comment = "Minimum quantity of Sodalite dust per Sodalite ore") + public static int sodaliteMinQuatity = 1; + @ConfigRegistry(config = "misc", category = "blocks", key = "sodaliteMaxQuantity", comment = "Maximum quantity of Sodalite dust per Sodalite ore") + public static int sodaliteMaxQuantity = 2; + @ConfigRegistry(config = "misc", category = "blocks", key = "cinnabarMinQuatity", comment = "Minimum quantity of Cinnabar dust per Cinnabar ore") + public static int cinnabarMinQuatity = 1; + @ConfigRegistry(config = "misc", category = "blocks", key = "cinnabarMaxQuantity", comment = "Maximum quantity of Cinnabar dust per Cinnabar ore") + public static int cinnabarMaxQuantity = 2; + @ConfigRegistry(config = "misc", category = "blocks", key = "sphaleriteMinQuatity", comment = "Minimum quantity of Sphalerite dust per Sphalerite ore") + public static int sphaleriteMinQuatity = 1; + @ConfigRegistry(config = "misc", category = "blocks", key = "sphaleriteMaxQuantity", comment = "Maximum quantity of Sphalerite dust per Sphalerite ore") + public static int sphaleriteMaxQuantity = 2; public BlockOre() { super(Material.ROCK); @@ -114,67 +133,41 @@ public class BlockOre extends Block implements IOreNameProvider { } @Override - @Deprecated - public ArrayList getDrops(IBlockAccess world, BlockPos pos, IBlockState state, int fortune) { + public void getDrops(NonNullList drops, IBlockAccess world, BlockPos pos, IBlockState state, int fortune) { String variant = state.getValue(VARIANTS); int meta = getMetaFromState(state); Random random = new Random(); - // Ruby + + // Secondary drop, like peridot from sapphire ore added via event handler. if (variant.equalsIgnoreCase("Ruby")) { - OreDrop ruby = new OreDrop(ItemGems.getGemByName("ruby"), - secondaryDropChance); - OreDrop redGarnet = new OreDrop(ItemGems.getGemByName("red_garnet"), 0.02); - OreDropSet set = new OreDropSet(ruby, redGarnet); - return set.drop(fortune, random); + OreDrop ruby = new OreDrop(ItemGems.getGemByName("ruby", rubyMinQuatity), rubyMaxQuantity); + drops.add(ruby.getDrops(fortune, random)); } - - // Sapphire - if (variant.equalsIgnoreCase("Sapphire")) { - OreDrop sapphire = new OreDrop(ItemGems.getGemByName("sapphire"), - secondaryDropChance); - OreDrop peridot = new OreDrop(ItemGems.getGemByName("peridot"), 0.03); - OreDropSet set = new OreDropSet(sapphire, peridot); - return set.drop(fortune, random); + else if (variant.equalsIgnoreCase("Sapphire")) { + OreDrop sapphire = new OreDrop(ItemGems.getGemByName("sapphire", sapphireMinQuantity), sapphireMaxQuantity); + drops.add(sapphire.getDrops(fortune, random)); } - - // Pyrite - if (variant.equalsIgnoreCase("Pyrite")) { - OreDrop pyriteDust = new OreDrop(ItemDusts.getDustByName("pyrite"), - secondaryDropChance); - OreDropSet set = new OreDropSet(pyriteDust); - return set.drop(fortune, random); + else if (variant.equalsIgnoreCase("Pyrite")) { + OreDrop pyriteDust = new OreDrop(ItemDusts.getDustByName("pyrite", pyriteMinQuatity), pyriteMaxQuantity); + drops.add(pyriteDust.getDrops(fortune, random)); } - - // Sodalite - if (variant.equalsIgnoreCase("Sodalite")) { - OreDrop sodalite = new OreDrop(ItemDusts.getDustByName("sodalite", 6), - secondaryDropChance); - OreDrop aluminum = new OreDrop(ItemDusts.getDustByName("aluminum"), 0.50); - OreDropSet set = new OreDropSet(sodalite, aluminum); - return set.drop(fortune, random); + else if (variant.equalsIgnoreCase("Sodalite")) { + OreDrop sodalite = new OreDrop(ItemDusts.getDustByName("sodalite", sodaliteMinQuatity), sodaliteMaxQuantity); + drops.add(sodalite.getDrops(fortune, random)); } - - // Cinnabar - if (variant.equalsIgnoreCase("Cinnabar")) { - OreDrop cinnabar = new OreDrop(ItemDusts.getDustByName("cinnabar"), - secondaryDropChance); - OreDrop redstone = new OreDrop(new ItemStack(Items.REDSTONE), 0.25); - OreDropSet set = new OreDropSet(cinnabar, redstone); - return set.drop(fortune, random); + else if (variant.equalsIgnoreCase("Cinnabar")) { + OreDrop cinnabar = new OreDrop(ItemDusts.getDustByName("cinnabar", cinnabarMinQuatity), cinnabarMaxQuantity); + drops.add(cinnabar.getDrops(fortune, random)); } - - // Sphalerite 1, 1/8 yellow garnet - if (variant.equalsIgnoreCase("Sphalerite")) { - OreDrop sphalerite = new OreDrop(ItemDusts.getDustByName("sphalerite"), - secondaryDropChance); - OreDrop yellowGarnet = new OreDrop(ItemGems.getGemByName("yellowGarnet"), 0.125); - OreDropSet set = new OreDropSet(sphalerite, yellowGarnet); - return set.drop(fortune, random); + else if (variant.equalsIgnoreCase("Sphalerite")) { + OreDrop sphalerite = new OreDrop(ItemDusts.getDustByName("sphalerite", sphaleriteMinQuatity), sphaleriteMaxQuantity); + drops.add(sphalerite.getDrops(fortune, random)); } - - ArrayList block = new ArrayList<>(); - block.add(new ItemStack(Item.getItemFromBlock(this), 1, meta)); - return block; + else { + drops.add(new ItemStack(Item.getItemFromBlock(this), 1, meta)); + } + + return; } @Override @@ -191,28 +184,10 @@ public class BlockOre extends Block implements IOreNameProvider { } @Override - public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World world, BlockPos pos, - EntityPlayer player) { + public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World world, BlockPos pos, EntityPlayer player) { return new ItemStack(this, 1, getMetaFromState(state)); } - // @Override - // public int damageDropped(IBlockState state) - // { - // int meta = getMetaFromState(state); - // if (meta == 2) - // { - // return 0; - // } else if (meta == 3) - // { - // return 1; - // } else if (meta == 5) - // { - // return 60; - // } - // return meta; - // } - @Override public int damageDropped(IBlockState state) { return getMetaFromState(state); diff --git a/src/main/java/techreborn/events/BlockBreakHandler.java b/src/main/java/techreborn/events/BlockBreakHandler.java index 8a38d36d5..818482e96 100644 --- a/src/main/java/techreborn/events/BlockBreakHandler.java +++ b/src/main/java/techreborn/events/BlockBreakHandler.java @@ -24,7 +24,12 @@ package techreborn.events; +import java.util.List; +import java.util.Random; + import net.minecraft.block.state.IBlockState; +import net.minecraft.init.Items; +import net.minecraft.item.ItemStack; import net.minecraft.util.EnumHand; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; @@ -33,7 +38,9 @@ import net.minecraftforge.event.world.BlockEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import reborncore.common.registration.RebornRegistry; import reborncore.common.registration.impl.ConfigRegistry; +import reborncore.common.util.OreDrop; import techreborn.init.ModItems; +import techreborn.items.ItemDusts; import techreborn.items.ItemGems; import techreborn.lib.ModInfo; import techreborn.utils.OreDictUtils; @@ -41,13 +48,45 @@ import techreborn.utils.OreDictUtils; @RebornRegistry(modID = ModInfo.MOD_ID) public class BlockBreakHandler { - @ConfigRegistry(config = "misc", category = "general", key = "RubyRedGarnetDrops", comment = "Give red garnet drops to any harvested oreRuby") - public static boolean rubyGarnetDrops = true; + @ConfigRegistry(config = "compat", category = "general", key = "secondaryGemDrops", comment = "Drop red and yellow garnets and peridot from any harvested oreRuby, oreSapphire, oreSphalerite. False will also disable drop from TechReborn ores.") + public static boolean secondaryGemDrops = true; + @ConfigRegistry(config = "misc", category = "blocks", key = "redGarnetDropChance", comment = "Chance to get Red Garnet from Ruby Ore") + public static double redGarnetDropChance = 0.125; + @ConfigRegistry(config = "misc", category = "blocks", key = "peridotDropChance", comment = "Chance to get Peridot from Sapphire Ore") + public static double peridotDropChance = 0.125; + @ConfigRegistry(config = "misc", category = "blocks", key = "aluminiumDropChance", comment = "Chance to get Aluminium dust from Sodalite Ore") + public static double aluminiumDropChance = 0.50; + @ConfigRegistry(config = "misc", category = "blocks", key = "redstoneDropChance", comment = "Chance to get Redstone from Cinnabar Ore") + public static double redstoneDropChance = 0.25; + @ConfigRegistry(config = "misc", category = "blocks", key = "yellowGarnetDropChance", comment = "Chance to get Yellow Garnet gem from Sphalerite Ore") + public static double yellowGarnetDropChance = 0.125; @SubscribeEvent public void onBlockHarvest(BlockEvent.HarvestDropsEvent event) { - if (!event.isSilkTouching() && rubyGarnetDrops && OreDictUtils.isOre(event.getState(), "oreRuby")) { - event.getDrops().add(ItemGems.getGemByName("red_garnet").copy()); + if (secondaryGemDrops && !event.isSilkTouching()) { + IBlockState state = event.getState(); + List drops = event.getDrops(); + Random random = new Random(); + if (OreDictUtils.isOre(state, "oreRuby")) { + OreDrop redGarnet = new OreDrop(ItemGems.getGemByName("red_garnet"), redGarnetDropChance, 1); + drops.add(redGarnet.getDrops(event.getFortuneLevel(), random)); + } + else if (OreDictUtils.isOre(state, "oreSapphire")) { + OreDrop peridot = new OreDrop(ItemGems.getGemByName("peridot"), peridotDropChance, 1); + drops.add(peridot.getDrops(event.getFortuneLevel(), random)); + } + else if (OreDictUtils.isOre(state, "oreSodalite")) { + OreDrop aluminium = new OreDrop(ItemDusts.getDustByName("aluminium"), aluminiumDropChance, 1); + drops.add(aluminium.getDrops(event.getFortuneLevel(), random)); + } + else if (OreDictUtils.isOre(state, "oreCinnabar")) { + OreDrop redstone = new OreDrop(new ItemStack(Items.REDSTONE), redstoneDropChance, 1); + drops.add(redstone.getDrops(event.getFortuneLevel(), random)); + } + else if (OreDictUtils.isOre(state, "oreSphalerite")) { + OreDrop yellowGarnet = new OreDrop(ItemGems.getGemByName("yellowGarnet"), yellowGarnetDropChance, 1); + drops.add(yellowGarnet.getDrops(event.getFortuneLevel(), random)); + } } } diff --git a/src/main/java/techreborn/utils/OreDictUtils.java b/src/main/java/techreborn/utils/OreDictUtils.java index 999c52b42..f863473ab 100644 --- a/src/main/java/techreborn/utils/OreDictUtils.java +++ b/src/main/java/techreborn/utils/OreDictUtils.java @@ -106,7 +106,7 @@ public class OreDictUtils { public static boolean isOre( @Nonnull ItemStack stack, String oreName) { - if (!stack.isEmpty() && !stack.isEmpty() && oreName != null) { + if (!stack.isEmpty() && oreName != null) { int id = OreDictionary.getOreID(oreName); int[] ids = OreDictionary.getOreIDs(stack);