int x = (int)Math.floor(posX);
int y = (int)(posY + 0.6);
int z = (int)Math.floor(posZ);
GameRules rules = worldObj.getGameRules();
String ruleBefore = rules.getGameRuleStringValue("mobGriefing");
boolean ruleChanged = false;
boolean hasEnderChest = (func_146080_bZ() == Blocks.ender_chest);
boolean hasBackpack = (getEquipmentInSlot(EquipmentSlot.CHEST) != null);
// Temporarily change the blocks which endermen can carry.
// TODO: Make a pull request to Forge which allows us to do this by overriding a method instead.
IdentityHashMap<Block, Boolean> carriable = ReflectionUtils.get(EntityEnderman.class, null, "carriable", "");
ReflectionUtils.set(EntityEnderman.class, null, "carriable", "", friendermanCarriable);
// Temporarily change mobGriefing gamerule to allow pickup and
// prevent dropping of enderchests regardless of the gamerule.
if (hasEnderChest) {
if (ruleBefore.equalsIgnoreCase("true")) {
rules.setOrCreateGameRule("mobGriefing", "false");
ruleChanged = true;
}
} else if (hasBackpack && worldObj.isAirBlock(x, y, z)) {
if (ruleBefore.equalsIgnoreCase("false")) {
rules.setOrCreateGameRule("mobGriefing", "true");
ruleChanged = true;
}
}
super.onLivingUpdate();
// Reset carriable blocks and gamerule.
ReflectionUtils.set(EntityEnderman.class, null, "carriable", "", carriable);
if (ruleChanged)
rules.setOrCreateGameRule("mobGriefing", ruleBefore);
// If ender chest was picked up, remove ender backpack and place it on the ground.
if (!hasEnderChest && (func_146080_bZ() == Blocks.ender_chest)) {
setCurrentItemOrArmor(3, null);
worldObj.setBlock(x, y, z, BetterStorageTiles.enderBackpack, RandomUtils.getInt(2, 6), 3);