use of net.minecraft.util.math.BlockPos in project NetherEx by LogicTechCorp.
the class ExplosionSpore method doExplosionA.
@Override
public void doExplosionA() {
if (!world.isRemote) {
Set<BlockPos> set = Sets.newHashSet();
for (int j = 0; j < 16; ++j) {
for (int k = 0; k < 16; ++k) {
for (int l = 0; l < 16; ++l) {
if (j == 0 || j == 15 || k == 0 || k == 15 || l == 0 || l == 15) {
double d0 = (double) ((float) j / 15.0F * 2.0F - 1.0F);
double d1 = (double) ((float) k / 15.0F * 2.0F - 1.0F);
double d2 = (double) ((float) l / 15.0F * 2.0F - 1.0F);
double d3 = Math.sqrt(d0 * d0 + d1 * d1 + d2 * d2);
d0 = d0 / d3;
d1 = d1 / d3;
d2 = d2 / d3;
float f = explosionSize * (0.7F + world.rand.nextFloat() * 0.6F);
double d4 = explosionX;
double d6 = explosionY;
double d8 = explosionZ;
for (float f1 = 0.3F; f > 0.0F; f -= 0.22500001F) {
BlockPos blockpos = new BlockPos(d4, d6, d8);
IBlockState iblockstate = world.getBlockState(blockpos);
if (iblockstate.getMaterial() != Material.AIR) {
float f2 = exploder != null ? exploder.getExplosionResistance(this, world, blockpos, iblockstate) : iblockstate.getBlock().getExplosionResistance(world, blockpos, (Entity) null, this);
f -= (f2 + 0.3F) * 0.3F;
}
if (f > 0.0F && (exploder == null || exploder.verifyExplosion(this, world, blockpos, iblockstate, f))) {
set.add(blockpos);
}
d4 += d0 * 0.30000001192092896D;
d6 += d1 * 0.30000001192092896D;
d8 += d2 * 0.30000001192092896D;
}
}
}
}
}
affectedBlockPositions.addAll(set);
float f3 = explosionSize * 2.0F;
int k1 = MathHelper.floor(explosionX - (double) f3 - 1.0D);
int l1 = MathHelper.floor(explosionX + (double) f3 + 1.0D);
int i2 = MathHelper.floor(explosionY - (double) f3 - 1.0D);
int i1 = MathHelper.floor(explosionY + (double) f3 + 1.0D);
int j2 = MathHelper.floor(explosionZ - (double) f3 - 1.0D);
int j1 = MathHelper.floor(explosionZ + (double) f3 + 1.0D);
List<Entity> list = world.getEntitiesWithinAABBExcludingEntity(exploder, new AxisAlignedBB((double) k1, (double) i2, (double) j2, (double) l1, (double) i1, (double) j1));
ForgeEventFactory.onExplosionDetonate(world, this, list, f3);
Vec3d vec3d = new Vec3d(explosionX, explosionY, explosionZ);
for (Entity entity : list) {
if (!entity.isImmuneToExplosions()) {
double d12 = entity.getDistance(explosionX, explosionY, explosionZ) / (double) f3;
if (d12 <= 1.0D) {
double d5 = entity.posX - explosionX;
double d7 = entity.posY + (double) entity.getEyeHeight() - explosionY;
double d9 = entity.posZ - explosionZ;
double d13 = (double) MathHelper.sqrt(d5 * d5 + d7 * d7 + d9 * d9);
if (d13 != 0.0D) {
d5 = d5 / d13;
d7 = d7 / d13;
d9 = d9 / d13;
double d14 = (double) world.getBlockDensity(vec3d, entity.getEntityBoundingBox());
double d10 = (1.0D - d12) * d14;
if (!(entity instanceof EntitySporeCreeper) && !(entity instanceof EntitySpore)) {
entity.attackEntityFrom(DamageSource.causeExplosionDamage(this), (float) ((int) ((d10 * d10 + d10) / 2.0D * 7.0D * (double) f3 + 1.0D)));
}
if (entity instanceof EntityLivingBase) {
((EntityLivingBase) entity).addPotionEffect(new PotionEffect(NetherExEffects.SPORE, 2400, 0));
}
double d11 = d10;
if (entity instanceof EntityLivingBase) {
d11 = EnchantmentProtection.getBlastDamageReduction((EntityLivingBase) entity, d10);
}
entity.motionX += d5 * d11;
entity.motionY += d7 * d11;
entity.motionZ += d9 * d11;
if (entity instanceof EntityPlayer) {
EntityPlayer entityplayer = (EntityPlayer) entity;
if (!entityplayer.isSpectator() && (!entityplayer.isCreative() || !entityplayer.capabilities.isFlying)) {
playerKnockbackMap.put(entityplayer, new Vec3d(d5 * d10, d7 * d10, d9 * d10));
}
}
}
}
}
}
}
}
use of net.minecraft.util.math.BlockPos in project NetherEx by LogicTechCorp.
the class TeleporterNether method placeInPortal.
@Override
public void placeInPortal(Entity entity, float rotationYaw) {
if (entity instanceof EntityPlayer) {
PortalPositionAndDimension from = null;
try {
from = new PortalPositionAndDimension((BlockPos) FIELD_LAST_PORTAL_POS.get(entity));
} catch (IllegalAccessException e) {
e.printStackTrace();
}
super.placeInPortal(entity, rotationYaw);
PortalPositionAndDimension to = new PortalPositionAndDimension(entity.getPosition());
NBTTagCompound tagCompound = entity.getEntityData().getCompoundTag("TeleportInfo");
NBTTagList tagList = tagCompound.getTagList("ReturnPortals", Constants.NBT.TAG_COMPOUND);
for (int i = tagList.tagCount() - 1; i >= 0; i--) {
NBTTagCompound portalCompound = tagList.getCompoundTagAt(i);
PortalPositionAndDimension testTo = new PortalPositionAndDimension(BlockPos.fromLong(portalCompound.getLong("To")), portalCompound.getInteger("ToDim"));
if (testTo.dimensionId == entity.world.provider.getDimension() && testTo.distanceSq(to) <= 9) {
tagList.removeTag(i);
}
}
NBTTagCompound portalCompound = new NBTTagCompound();
portalCompound.setLong("From", from.toLong());
portalCompound.setInteger("FromDim", from.dimensionId);
portalCompound.setLong("To", to.toLong());
portalCompound.setInteger("ToDim", to.dimensionId);
tagList.appendTag(portalCompound);
tagCompound.setTag("ReturnPortals", tagList);
entity.getEntityData().setTag("TeleportInfo", tagCompound);
} else {
super.placeInPortal(entity, rotationYaw);
}
}
use of net.minecraft.util.math.BlockPos in project NetherEx by LogicTechCorp.
the class TeleporterNetherEx method makePortal.
@Override
public boolean makePortal(Entity entity) {
double d0 = -1.0D;
int j = MathHelper.floor(entity.posX);
int k = MathHelper.floor(entity.posY);
int l = MathHelper.floor(entity.posZ);
int i1 = j;
int j1 = k;
int k1 = l;
int l1 = 0;
int i2 = random.nextInt(4);
BlockPos.MutableBlockPos mutableBlockPos = new BlockPos.MutableBlockPos();
for (int j2 = j - 16; j2 <= j + 16; ++j2) {
double d1 = (double) j2 + 0.5D - entity.posX;
for (int l2 = l - 16; l2 <= l + 16; ++l2) {
double d2 = (double) l2 + 0.5D - entity.posZ;
label146: for (int j3 = world.getActualHeight() - 1; j3 >= 0; --j3) {
if (world.isAirBlock(mutableBlockPos.setPos(j2, j3, l2))) {
while (j3 > 0 && world.isAirBlock(mutableBlockPos.setPos(j2, j3 - 1, l2))) {
--j3;
}
for (int k3 = i2; k3 < i2 + 4; ++k3) {
int l3 = k3 % 2;
int i4 = 1 - l3;
if (k3 % 4 >= 2) {
l3 = -l3;
i4 = -i4;
}
for (int j4 = 0; j4 < 3; ++j4) {
for (int k4 = 0; k4 < 4; ++k4) {
for (int l4 = -1; l4 < 4; ++l4) {
int i5 = j2 + (k4 - 1) * l3 + j4 * i4;
int j5 = j3 + l4;
int k5 = l2 + (k4 - 1) * i4 - j4 * l3;
mutableBlockPos.setPos(i5, j5, k5);
if (l4 < 0 && !world.getBlockState(mutableBlockPos).getMaterial().isSolid() || l4 >= 0 && !world.isAirBlock(mutableBlockPos)) {
continue label146;
}
}
}
}
double d5 = (double) j3 + 0.5D - entity.posY;
double d7 = d1 * d1 + d5 * d5 + d2 * d2;
if (d0 < 0.0D || d7 < d0) {
d0 = d7;
i1 = j2;
j1 = j3;
k1 = l2;
l1 = k3 % 4;
}
}
}
}
}
}
if (d0 < 0.0D) {
for (int l5 = j - 16; l5 <= j + 16; ++l5) {
double d3 = (double) l5 + 0.5D - entity.posX;
for (int j6 = l - 16; j6 <= l + 16; ++j6) {
double d4 = (double) j6 + 0.5D - entity.posZ;
label567: for (int i7 = world.getActualHeight() - 1; i7 >= 0; --i7) {
if (world.isAirBlock(mutableBlockPos.setPos(l5, i7, j6))) {
while (i7 > 0 && world.isAirBlock(mutableBlockPos.setPos(l5, i7 - 1, j6))) {
--i7;
}
for (int k7 = i2; k7 < i2 + 2; ++k7) {
int j8 = k7 % 2;
int j9 = 1 - j8;
for (int j10 = 0; j10 < 4; ++j10) {
for (int j11 = -1; j11 < 4; ++j11) {
int j12 = l5 + (j10 - 1) * j8;
int i13 = i7 + j11;
int j13 = j6 + (j10 - 1) * j9;
mutableBlockPos.setPos(j12, i13, j13);
if (j11 < 0 && !world.getBlockState(mutableBlockPos).getMaterial().isSolid() || j11 >= 0 && !world.isAirBlock(mutableBlockPos)) {
continue label567;
}
}
}
double d6 = (double) i7 + 0.5D - entity.posY;
double d8 = d3 * d3 + d6 * d6 + d4 * d4;
if (d0 < 0.0D || d8 < d0) {
d0 = d8;
i1 = l5;
j1 = i7;
k1 = j6;
l1 = k7 % 2;
}
}
}
}
}
}
}
int i6 = i1;
int k2 = j1;
int k6 = k1;
int l6 = l1 % 2;
int i3 = 1 - l6;
if (l1 % 4 >= 2) {
l6 = -l6;
i3 = -i3;
}
if (d0 < 0.0D) {
j1 = MathHelper.clamp(j1, 70, world.getActualHeight() - 10);
k2 = j1;
for (int j7 = -1; j7 <= 1; ++j7) {
for (int l7 = 1; l7 < 3; ++l7) {
for (int k8 = -1; k8 < 3; ++k8) {
int k9 = i6 + (l7 - 1) * l6 + j7 * i3;
int k10 = k2 + k8;
int k11 = k6 + (l7 - 1) * i3 - j7 * l6;
boolean flag = k8 < 0;
world.setBlockState(new BlockPos(k9, k10, k11), flag ? Blocks.OBSIDIAN.getDefaultState() : Blocks.AIR.getDefaultState());
}
}
}
}
IBlockState state = NetherExBlocks.BLOCK_PORTAL_NETHER.getDefaultState().withProperty(BlockNetherPortal.AXIS, l6 == 0 ? EnumFacing.Axis.X : EnumFacing.Axis.Z);
for (int i8 = 0; i8 < 4; ++i8) {
for (int l8 = 0; l8 < 4; ++l8) {
for (int l9 = -1; l9 < 4; ++l9) {
int l10 = i6 + (l8 - 1) * l6;
int l11 = k2 + l9;
int k12 = k6 + (l8 - 1) * i3;
boolean flag1 = l8 == 0 || l8 == 3 || l9 == -1 || l9 == 3;
world.setBlockState(new BlockPos(l10, l11, k12), flag1 ? Blocks.OBSIDIAN.getDefaultState() : state, 2);
}
}
for (int i9 = 0; i9 < 4; ++i9) {
for (int i10 = -1; i10 < 4; ++i10) {
int i11 = i6 + (i9 - 1) * l6;
int i12 = k2 + i10;
int l12 = k6 + (i9 - 1) * i3;
BlockPos blockpos = new BlockPos(i11, i12, l12);
world.notifyNeighborsOfStateChange(blockpos, world.getBlockState(blockpos).getBlock(), false);
}
}
}
return true;
}
use of net.minecraft.util.math.BlockPos in project NetherEx by LogicTechCorp.
the class PigtificateVillage method updateVillageRadiusAndCenter.
private void updateVillageRadiusAndCenter() {
int i = villageFenceGateInfoList.size();
if (i == 0) {
center = BlockPos.ORIGIN;
villageRadius = 0;
} else {
center = new BlockPos(centerHelper.getX() / i, centerHelper.getY() / i, centerHelper.getZ() / i);
int j = 0;
for (VillageFenceGateInfo fenceGateInfo : villageFenceGateInfoList) {
j = Math.max(fenceGateInfo.getDistanceToFenceGateBlockSq(center), j);
}
villageRadius = Math.max(32, (int) Math.sqrt((double) j) + 1);
}
}
use of net.minecraft.util.math.BlockPos in project NetherEx by LogicTechCorp.
the class PigtificateVillage method getFenceGateInfo.
public VillageFenceGateInfo getFenceGateInfo(BlockPos pos) {
VillageFenceGateInfo fenceGateInfo = null;
int i = Integer.MAX_VALUE;
for (VillageFenceGateInfo fenceGateInfo1 : villageFenceGateInfoList) {
int j = fenceGateInfo1.getDistanceToFenceGateBlockSq(pos);
if (j > 256) {
j = j * 1000;
} else {
j = fenceGateInfo1.getFenceGateOpeningRestrictionCounter();
}
if (j < i) {
BlockPos blockpos = fenceGateInfo1.getFenceGateBlockPos();
EnumFacing enumfacing = fenceGateInfo1.getInsideDirection();
if (world.getBlockState(blockpos.offset(enumfacing, 1)).getBlock().blocksMovement(world, blockpos.offset(enumfacing, 1)) && world.getBlockState(blockpos.offset(enumfacing, -1)).getBlock().blocksMovement(world, blockpos.offset(enumfacing, -1)) && world.getBlockState(blockpos.up().offset(enumfacing, 1)).getBlock().blocksMovement(world, blockpos.up().offset(enumfacing, 1)) && world.getBlockState(blockpos.up().offset(enumfacing, -1)).getBlock().blocksMovement(world, blockpos.up().offset(enumfacing, -1))) {
fenceGateInfo = fenceGateInfo1;
i = j;
}
}
}
return fenceGateInfo;
}
Aggregations