use of net.mcft.copy.betterstorage.network.packet.PacketBackpackTeleport in project BetterStorage by copygirl.
the class EntityFrienderman method onLivingUpdate.
@Override
public void onLivingUpdate() {
if (worldObj.isRemote) {
super.onLivingUpdate();
return;
}
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);
// 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);
WorldUtils.get(worldObj, x, y, z, TileEntityBackpack.class).stack = new ItemStack(BetterStorageItems.itemEnderBackpack);
double px = x + 0.5;
double py = y + 0.5;
double pz = z + 0.5;
BetterStorage.networkChannel.sendToAllAround(new PacketBackpackTeleport(px, py, pz, x, y, z), worldObj, px, py, pz, 256);
worldObj.playSoundEffect(px, py, pz, "mob.endermen.portal", 1.0F, 1.0F);
}
}
use of net.mcft.copy.betterstorage.network.packet.PacketBackpackTeleport in project BetterStorage by copygirl.
the class TileEnderBackpack method teleportRandomly.
public static boolean teleportRandomly(World world, double sourceX, double sourceY, double sourceZ, boolean canFloat, ItemStack stack) {
int x = (int) sourceX + RandomUtils.getInt(-12, 12 + 1);
int y = (int) sourceY + RandomUtils.getInt(-8, 8 + 1);
int z = (int) sourceZ + RandomUtils.getInt(-12, 12 + 1);
y = Math.max(1, Math.min(world.getHeight() - 1, y));
if (!world.blockExists(x, y, z))
return false;
Block block = world.getBlock(x, y, z);
if (!block.isReplaceable(world, x, y, z))
return false;
if (!canFloat && !world.isSideSolid(x, y - 1, z, ForgeDirection.UP))
return false;
BetterStorage.networkChannel.sendToAllAround(new PacketBackpackTeleport(sourceX, sourceY, sourceZ, x, y, z), world, sourceX + 0.5, sourceY + 0.5, sourceZ + 0.5, 256);
world.playSoundEffect(sourceX + 0.5, sourceY + 0.5, sourceZ + 0.5, "mob.endermen.portal", 1.0F, 1.0F);
world.playSoundEffect(x + 0.5, y + 0.5, z + 0.5, "mob.endermen.portal", 1.0F, 1.0F);
world.setBlock(x, y, z, ((ItemBackpack) stack.getItem()).getBlockType(), RandomUtils.getInt(2, 6), 3);
TileEntityBackpack newBackpack = WorldUtils.get(world, x, y, z, TileEntityBackpack.class);
newBackpack.stack = stack;
return true;
}
Aggregations