Skip to content

Commit

Permalink
Avoid crashing if a block's drops are in an ImmutableList. Replacing …
Browse files Browse the repository at this point in the history
…drops will not be possible for those blocks, and I consider them to break the "design contract" for that method.
  • Loading branch information
gigaherz committed Aug 24, 2016
1 parent eda20f7 commit 36a8f4b
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 51 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ repositories {

apply plugin: 'net.minecraftforge.gradle.forge'

version = "1.6.5"
version = "1.6.6"
group= "gigaherz.survivalist" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "Survivalist-1.10.2"

Expand Down
123 changes: 73 additions & 50 deletions src/main/java/gigaherz/survivalist/rocks/RocksEventHandling.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package gigaherz.survivalist.rocks;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import gigaherz.survivalist.ConfigManager;
import gigaherz.survivalist.Survivalist;
Expand All @@ -25,75 +26,97 @@ public static void register()
@SubscribeEvent
public void onHarvestBlock(BlockEvent.HarvestDropsEvent ev)
{
if (!ev.isSilkTouching())
if (ev.isSilkTouching())
return;

List<ItemStack> drops = ev.getDrops();
if (drops instanceof ImmutableList)
{
List<ItemStack> newDrops = Lists.newArrayList();
Survivalist.logger.warn("WARNING: Some mod is returning an ImmutableList from HarvestBlocks, replacing drops will NOT be possible.");
return;
}

boolean anyChanged = false;
List<ItemStack> newDrops = Lists.newArrayList();

for (ItemStack drop : ev.getDrops())
for (ItemStack drop : drops)
{
if (drop.getItem() == Item.getItemFromBlock(Blocks.COBBLESTONE) && ConfigManager.instance.replaceStoneDrops)
{
if (drop.getItem() == Item.getItemFromBlock(Blocks.COBBLESTONE) && ConfigManager.instance.replaceStoneDrops)
newDrops.add(new ItemStack(Survivalist.rock, 4));
anyChanged = true;
}
else if (drop.getItem() == Item.getItemFromBlock(Blocks.STONE) && ConfigManager.instance.replaceStoneDrops)
{
switch (drop.getMetadata())
{
newDrops.add(new ItemStack(Survivalist.rock, 4));
case 0:
newDrops.add(new ItemStack(Survivalist.rock, 4, 0));
anyChanged = true;
break;
case 5:
newDrops.add(new ItemStack(Survivalist.rock, 4, 1));
anyChanged = true;
break;
case 3:
newDrops.add(new ItemStack(Survivalist.rock, 4, 2));
anyChanged = true;
break;
case 1:
newDrops.add(new ItemStack(Survivalist.rock, 4, 3));
anyChanged = true;
break;
default:
newDrops.add(drop);
}
else if (drop.getItem() == Item.getItemFromBlock(Blocks.STONE) && ConfigManager.instance.replaceStoneDrops)
}
else if (drop.getItem() == Item.getItemFromBlock(Blocks.IRON_ORE) && ConfigManager.instance.replaceIronOreDrops)
{
newDrops.add(new ItemStack(Survivalist.rock_ore, 2 + Math.round(2 * rnd.nextFloat()), 0));
anyChanged = true;
}
else if (drop.getItem() == Item.getItemFromBlock(Blocks.GOLD_ORE) && ConfigManager.instance.replaceGoldOreDrops)
{
newDrops.add(new ItemStack(Survivalist.rock_ore, 2 + Math.round(2 * rnd.nextFloat()), 1));
anyChanged = true;
}
else if (ConfigManager.instance.replaceModOreDrops)
{
if (Survivalist.hasOreName(drop, "oreCopper"))
{
switch (drop.getMetadata())
{
case 0:
newDrops.add(new ItemStack(Survivalist.rock, 4, 0));
break;
case 5:
newDrops.add(new ItemStack(Survivalist.rock, 4, 1));
break;
case 3:
newDrops.add(new ItemStack(Survivalist.rock, 4, 2));
break;
case 1:
newDrops.add(new ItemStack(Survivalist.rock, 4, 3));
break;
default:
newDrops.add(drop);
}
newDrops.add(new ItemStack(Survivalist.rock_ore, 2 + Math.round(2 * rnd.nextFloat()), 2));
anyChanged = true;
}
else if (drop.getItem() == Item.getItemFromBlock(Blocks.IRON_ORE) && ConfigManager.instance.replaceIronOreDrops)
else if (Survivalist.hasOreName(drop, "oreTin"))
{
newDrops.add(new ItemStack(Survivalist.rock_ore, 2 + Math.round(2 * rnd.nextFloat()), 0));
newDrops.add(new ItemStack(Survivalist.rock_ore, 2 + Math.round(2 * rnd.nextFloat()), 3));
anyChanged = true;
}
else if (drop.getItem() == Item.getItemFromBlock(Blocks.GOLD_ORE) && ConfigManager.instance.replaceGoldOreDrops)
else if (Survivalist.hasOreName(drop, "oreLead"))
{
newDrops.add(new ItemStack(Survivalist.rock_ore, 2 + Math.round(2 * rnd.nextFloat()), 1));
newDrops.add(new ItemStack(Survivalist.rock_ore, 2 + Math.round(2 * rnd.nextFloat()), 4));
anyChanged = true;
}
else if (ConfigManager.instance.replaceModOreDrops)
else if (Survivalist.hasOreName(drop, "oreSilver"))
{
if (Survivalist.hasOreName(drop, "oreCopper"))
{
newDrops.add(new ItemStack(Survivalist.rock_ore, 2 + Math.round(2 * rnd.nextFloat()), 2));
}
else if (Survivalist.hasOreName(drop, "oreTin"))
{
newDrops.add(new ItemStack(Survivalist.rock_ore, 2 + Math.round(2 * rnd.nextFloat()), 3));
}
else if (Survivalist.hasOreName(drop, "oreLead"))
{
newDrops.add(new ItemStack(Survivalist.rock_ore, 2 + Math.round(2 * rnd.nextFloat()), 4));
}
else if (Survivalist.hasOreName(drop, "oreSilver"))
{
newDrops.add(new ItemStack(Survivalist.rock_ore, 2 + Math.round(2 * rnd.nextFloat()), 5));
}
else
{
newDrops.add(drop);
}
newDrops.add(new ItemStack(Survivalist.rock_ore, 2 + Math.round(2 * rnd.nextFloat()), 5));
anyChanged = true;
}
else
{
newDrops.add(drop);
}
}
else
{
newDrops.add(drop);
}
}

ev.getDrops().clear();
ev.getDrops().addAll(newDrops);
if (anyChanged)
{
drops.clear();
drops.addAll(newDrops);
}
}
}

0 comments on commit 36a8f4b

Please sign in to comment.