use of ValkyrienWarfareBase.Interaction.ValkyrienWarfareWorldEventListener in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class EventsCommon method onWorldLoad.
/**@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onExplosionDetonateEvent(ExplosionEvent.Detonate event) {
Explosion e = event.getExplosion();
double xx = e.explosionX, yy = e.explosionY, zz = e.explosionZ;
List<BlockPos> affectedPositionsList = new ArrayList<BlockPos>(e.getAffectedBlockPositions());
Map<EntityPlayer, Vec3d> playerKnockbackMap = new HashMap<EntityPlayer, Vec3d>(e.getPlayerKnockbackMap());
Vector center = new Vector(e.explosionX, e.explosionY, e.explosionZ);
World worldIn = e.worldObj;
float radius = e.explosionSize;
AxisAlignedBB toCheck = new AxisAlignedBB(center.X - radius, center.Y - radius, center.Z - radius, center.X + radius, center.Y + radius, center.Z + radius);
List<PhysicsWrapperEntity> shipsNear = ValkyrienWarfareMod.physicsManager.getManagerForWorld(e.worldObj).getNearbyPhysObjects(toCheck);
// e.doExplosionA();
// TODO: Make this compatible and shit!
Field[] fields = getFields(e);
for (PhysicsWrapperEntity ship : shipsNear) {
Vector inLocal = new Vector(center);
RotationMatrices.applyTransform(ship.wrapping.coordTransform.wToLTransform, inLocal);
// inLocal.roundToWhole();
// Explosion expl = new Explosion(ship.worldObj, null, inLocal.X, inLocal.Y, inLocal.Z, radius, false, false);
Explosion expl = e;
if (setExplosionPosition(e, inLocal.X, inLocal.Y, inLocal.Z, fields)) {
double waterRange = .6D;
boolean cancelDueToWater = false;
for (int x = (int) Math.floor(expl.explosionX - waterRange); x <= Math.ceil(expl.explosionX + waterRange); x++) {
for (int y = (int) Math.floor(expl.explosionY - waterRange); y <= Math.ceil(expl.explosionY + waterRange); y++) {
for (int z = (int) Math.floor(expl.explosionZ - waterRange); z <= Math.ceil(expl.explosionZ + waterRange); z++) {
if (!cancelDueToWater) {
IBlockState state = e.worldObj.getBlockState(new BlockPos(x, y, z));
if (state.getBlock() instanceof BlockLiquid) {
cancelDueToWater = true;
}
}
}
}
}
expl.doExplosionA();
double affectedPositions = 0D;
for (Object o : expl.affectedBlockPositions) {
BlockPos pos = (BlockPos) o;
IBlockState state = ship.worldObj.getBlockState(pos);
Block block = state.getBlock();
if (!block.isAir(state, worldIn, (BlockPos) o) || ship.wrapping.explodedPositionsThisTick.contains((BlockPos) o)) {
affectedPositions++;
}
}
if (!cancelDueToWater) {
for (Object o : expl.affectedBlockPositions) {
BlockPos pos = (BlockPos) o;
IBlockState state = ship.worldObj.getBlockState(pos);
Block block = state.getBlock();
if (!block.isAir(state, worldIn, (BlockPos) o) || ship.wrapping.explodedPositionsThisTick.contains((BlockPos) o)) {
if (block.canDropFromExplosion(expl)) {
block.dropBlockAsItemWithChance(ship.worldObj, pos, state, 1.0F / expl.explosionSize, 0);
}
block.onBlockExploded(ship.worldObj, pos, expl);
if (!worldIn.isRemote) {
Vector posVector = new Vector(pos.getX() + .5, pos.getY() + .5, pos.getZ() + .5);
ship.wrapping.coordTransform.fromLocalToGlobal(posVector);
double mass = BlockMass.basicMass.getMassFromState(state, pos, ship.worldObj);
double explosionForce = Math.sqrt(e.explosionSize) * 1000D * mass;
Vector forceVector = new Vector(pos.getX() + .5 - expl.explosionX, pos.getY() + .5 - expl.explosionY, pos.getZ() + .5 - expl.explosionZ);
double vectorDist = forceVector.length();
forceVector.normalize();
forceVector.multiply(explosionForce / vectorDist);
RotationMatrices.doRotationOnly(ship.wrapping.coordTransform.lToWRotation, forceVector);
PhysicsQueuedForce queuedForce = new PhysicsQueuedForce(forceVector, posVector, false, 1);
if (!ship.wrapping.explodedPositionsThisTick.contains(pos)) {
ship.wrapping.explodedPositionsThisTick.add(pos);
}
ship.wrapping.queueForce(queuedForce);
}
}
}
}
}
e.getAffectedBlockPositions().clear();
e.getAffectedBlockPositions().addAll(affectedPositionsList);
e.getPlayerKnockbackMap().clear();
e.getPlayerKnockbackMap().putAll(playerKnockbackMap);
}
}**/
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onWorldLoad(WorldEvent.Load event) {
World world = event.getWorld();
ValkyrienWarfareMod.physicsManager.initWorld(world);
world.addEventListener(new ValkyrienWarfareWorldEventListener(world));
}
Aggregations