use of mcjty.lib.varia.GlobalCoordinate in project RFTools by McJty.
the class BlockProtectorEventHandlers method onDetonate.
@SubscribeEvent
public static void onDetonate(ExplosionEvent.Detonate event) {
Explosion explosion = event.getExplosion();
Vec3d explosionVector = explosion.getPosition();
Collection<GlobalCoordinate> protectors = BlockProtectors.getProtectors(event.getWorld(), (int) explosionVector.x, (int) explosionVector.y, (int) explosionVector.z);
if (protectors.isEmpty()) {
return;
}
List<BlockPos> affectedBlocks = event.getAffectedBlocks();
List<BlockPos> toremove = new ArrayList<>();
int rf = 0;
for (GlobalCoordinate protector : protectors) {
BlockPos pos = protector.getCoordinate();
TileEntity te = event.getWorld().getTileEntity(pos);
if (te instanceof BlockProtectorTileEntity) {
BlockProtectorTileEntity blockProtectorTileEntity = (BlockProtectorTileEntity) te;
for (BlockPos block : affectedBlocks) {
BlockPos relative = blockProtectorTileEntity.absoluteToRelative(block);
boolean b = blockProtectorTileEntity.isProtected(relative);
if (b) {
Vec3d blockVector = new Vec3d(block);
double distanceTo = explosionVector.distanceTo(blockVector);
int rfneeded = blockProtectorTileEntity.attemptExplosionProtection((float) (distanceTo / explosion.size), explosion.size);
if (rfneeded > 0) {
toremove.add(block);
rf += rfneeded;
} else {
blockProtectorTileEntity.removeProtection(relative);
}
}
}
}
}
affectedBlocks.removeAll(toremove);
}
use of mcjty.lib.varia.GlobalCoordinate in project RFTools by McJty.
the class BlockProtectorEventHandlers method onLivingDestroyBlock.
@SubscribeEvent
public static void onLivingDestroyBlock(LivingDestroyBlockEvent event) {
int x = event.getPos().getX();
int y = event.getPos().getY();
int z = event.getPos().getZ();
World world = event.getEntity().getEntityWorld();
Collection<GlobalCoordinate> protectors = BlockProtectors.getProtectors(world, x, y, z);
if (BlockProtectors.checkHarvestProtection(x, y, z, world, protectors)) {
event.setCanceled(true);
}
}
use of mcjty.lib.varia.GlobalCoordinate in project RFTools by McJty.
the class ForgeEventHandlers method onEntityTeleport.
@SubscribeEvent
public void onEntityTeleport(EnderTeleportEvent event) {
World world = event.getEntity().getEntityWorld();
int id = world.provider.getDimension();
Entity entity = event.getEntity();
BlockPos coordinate = new BlockPos((int) entity.posX, (int) entity.posY, (int) entity.posZ);
if (NoTeleportAreaManager.isTeleportPrevented(entity, new GlobalCoordinate(coordinate, id))) {
event.setCanceled(true);
} else {
coordinate = new BlockPos((int) event.getTargetX(), (int) event.getTargetY(), (int) event.getTargetZ());
if (NoTeleportAreaManager.isTeleportPrevented(entity, new GlobalCoordinate(coordinate, id))) {
event.setCanceled(true);
}
}
}
use of mcjty.lib.varia.GlobalCoordinate in project RFTools by McJty.
the class ForgeEventHandlers method onEntitySpawnEvent.
@SubscribeEvent
public void onEntitySpawnEvent(LivingSpawnEvent.CheckSpawn event) {
World world = event.getWorld();
int id = world.provider.getDimension();
Entity entity = event.getEntity();
if (entity instanceof IMob) {
BlockPos coordinate = new BlockPos((int) entity.posX, (int) entity.posY, (int) entity.posZ);
if (PeacefulAreaManager.isPeaceful(new GlobalCoordinate(coordinate, id))) {
event.setResult(Event.Result.DENY);
}
}
}
use of mcjty.lib.varia.GlobalCoordinate in project RFTools by McJty.
the class PorterTools method returnTargets.
public static void returnTargets(EntityPlayer player) {
ItemStack heldItem = player.getHeldItem(EnumHand.MAIN_HAND);
if (heldItem.isEmpty()) {
return;
}
NBTTagCompound tagCompound = heldItem.getTagCompound();
int target = -1;
int[] targets = new int[AdvancedChargedPorterItem.MAXTARGETS];
String[] names = new String[AdvancedChargedPorterItem.MAXTARGETS];
TeleportDestinations destinations = TeleportDestinations.getDestinations(player.getEntityWorld());
if (tagCompound != null) {
if (tagCompound.hasKey("target")) {
target = tagCompound.getInteger("target");
} else {
target = -1;
}
for (int i = 0; i < AdvancedChargedPorterItem.MAXTARGETS; i++) {
names[i] = "";
if (tagCompound.hasKey("target" + i)) {
targets[i] = tagCompound.getInteger("target" + i);
GlobalCoordinate gc = destinations.getCoordinateForId(targets[i]);
if (gc != null) {
TeleportDestination destination = destinations.getDestination(gc);
if (destination != null) {
names[i] = destination.getName() + " (dimension " + destination.getDimension() + ")";
}
}
} else {
targets[i] = -1;
}
}
} else {
for (int i = 0; i < AdvancedChargedPorterItem.MAXTARGETS; i++) {
targets[i] = -1;
names[i] = "";
}
}
PacketTargetsReady msg = new PacketTargetsReady(target, targets, names);
RFToolsMessages.INSTANCE.sendTo(msg, (EntityPlayerMP) player);
}
Aggregations