Skip to content

Commit

Permalink
Workaround for Bukkit/Minecraft not honouring unity dropchance for eq…
Browse files Browse the repository at this point in the history
…uipment.
  • Loading branch information
totemo committed Oct 1, 2013
1 parent 982dd31 commit 9b7ec3f
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions src/io/github/totemo/doppelganger/Doppelganger.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.inventory.EntityEquipment;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.java.JavaPlugin;
Expand Down Expand Up @@ -166,6 +168,52 @@ public void onBlockPlace(BlockPlaceEvent event)
}
} // onBlockPlace

// --------------------------------------------------------------------------
/**
* Bukkit or vanilla Minecraft doesn't always drop equipment, when the drop
* chance is 1.0 (or more). Try to work around that by moving the equipment
* into the drops. Normally the equipment is not part of the drops. It is
* dropped by some other mechanism.
*
* This handler will process any entity death, but naturally spawned monsters
* probably won't have a (near) 1.0 drop chance for the their equipment, and
* in any case the relocation of the equipment to drops should be benign.
*/
@EventHandler(ignoreCancelled = true)
public void onEntityDeath(EntityDeathEvent event)
{
if (event.getEntity() instanceof Creature)
{

EntityEquipment equipment = event.getEntity().getEquipment();
if (equipment.getHelmetDropChance() > 0.999f)
{
event.getDrops().add(equipment.getHelmet());
equipment.setHelmet(null);
}
if (equipment.getChestplateDropChance() > 0.999f)
{
event.getDrops().add(equipment.getChestplate());
equipment.setChestplate(null);
}
if (equipment.getLeggingsDropChance() > 0.999f)
{
event.getDrops().add(equipment.getLeggings());
equipment.setLeggings(null);
}
if (equipment.getBootsDropChance() > 0.999f)
{
event.getDrops().add(equipment.getBoots());
equipment.setBoots(null);
}
if (equipment.getItemInHandDropChance() > 0.999f)
{
event.getDrops().add(equipment.getItemInHand());
equipment.setItemInHand(null);
}
}
} // onEntityDeath

// --------------------------------------------------------------------------
/**
* Spawn a doppelganger of the specified type and name.
Expand Down

0 comments on commit 9b7ec3f

Please sign in to comment.