use of net.minecraft.entity.item.TNTEntity in project Arclight by IzzelAliz.
the class ExplosionMixin method doExplosionA.
/**
* @author IzzelAliz
* @reason
*/
@Overwrite
public void doExplosionA() {
Set<BlockPos> set = Sets.newHashSet();
int i = 16;
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 = ((float) j / 15.0F * 2.0F - 1.0F);
double d1 = ((float) k / 15.0F * 2.0F - 1.0F);
double d2 = ((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 = this.size * (0.7F + this.world.rand.nextFloat() * 0.6F);
double d4 = this.x;
double d6 = this.y;
double d8 = this.z;
for (float f1 = 0.3F; f > 0.0F; f -= 0.22500001F) {
BlockPos blockpos = new BlockPos(d4, d6, d8);
BlockState blockstate = this.world.getBlockState(blockpos);
IFluidState ifluidstate = this.world.getFluidState(blockpos);
if (!blockstate.isAir(this.world, blockpos) || !ifluidstate.isEmpty()) {
float f2 = Math.max(blockstate.getExplosionResistance(this.world, blockpos, exploder, (Explosion) (Object) this), ifluidstate.getExplosionResistance(this.world, blockpos, exploder, (Explosion) (Object) this));
if (this.exploder != null) {
f2 = this.exploder.getExplosionResistance((Explosion) (Object) this, this.world, blockpos, blockstate, ifluidstate, f2);
}
f -= (f2 + 0.3F) * 0.3F;
}
if (f > 0.0F && (this.exploder == null || this.exploder.canExplosionDestroyBlock((Explosion) (Object) this, this.world, blockpos, blockstate, f))) {
set.add(blockpos);
}
d4 += d0 * (double) 0.3F;
d6 += d1 * (double) 0.3F;
d8 += d2 * (double) 0.3F;
}
}
}
}
}
this.affectedBlockPositions.addAll(set);
float f3 = this.size * 2.0F;
int k1 = MathHelper.floor(this.x - (double) f3 - 1.0D);
int l1 = MathHelper.floor(this.x + (double) f3 + 1.0D);
int i2 = MathHelper.floor(this.y - (double) f3 - 1.0D);
int i1 = MathHelper.floor(this.y + (double) f3 + 1.0D);
int j2 = MathHelper.floor(this.z - (double) f3 - 1.0D);
int j1 = MathHelper.floor(this.z + (double) f3 + 1.0D);
List<Entity> list = this.world.getEntitiesWithinAABBExcludingEntity(this.exploder, new AxisAlignedBB(k1, i2, j2, l1, i1, j1));
net.minecraftforge.event.ForgeEventFactory.onExplosionDetonate(this.world, (Explosion) (Object) this, list, f3);
Vec3d vec3d = new Vec3d(this.x, this.y, this.z);
for (Entity entity : list) {
if (!entity.isImmuneToExplosions()) {
double d12 = MathHelper.sqrt(entity.getDistanceSq(vec3d)) / f3;
if (d12 <= 1.0D) {
double d5 = entity.posX - this.x;
double d7 = ((EntityBridge) entity).bridge$getEyeHeight() - this.y;
double d9 = entity.posZ - this.z;
double d13 = MathHelper.sqrt(d5 * d5 + d7 * d7 + d9 * d9);
if (d13 != 0.0D) {
d5 = d5 / d13;
d7 = d7 / d13;
d9 = d9 / d13;
double d14 = Explosion.getBlockDensity(vec3d, entity);
double d10 = (1.0D - d12) * d14;
CraftEventFactory.entityDamage = this.exploder;
((EntityBridge) entity).bridge$setForceExplosionKnockback(false);
boolean wasDamaged = entity.attackEntityFrom(this.getDamageSource(), (float) ((int) ((d10 * d10 + d10) / 2.0D * 7.0D * (double) f3 + 1.0D)));
CraftEventFactory.entityDamage = null;
if (!wasDamaged && !(entity instanceof TNTEntity || entity instanceof FallingBlockEntity) && !((EntityBridge) entity).bridge$isForceExplosionKnockback()) {
continue;
}
double d11 = d10;
if (entity instanceof LivingEntity) {
d11 = ProtectionEnchantment.getBlastDamageReduction((LivingEntity) entity, d10);
}
entity.setMotion(entity.getMotion().add(d5 * d11, d7 * d11, d9 * d11));
if (entity instanceof PlayerEntity) {
PlayerEntity playerentity = (PlayerEntity) entity;
if (!playerentity.isSpectator() && (!playerentity.isCreative() || !playerentity.abilities.isFlying)) {
this.playerKnockbackMap.put(playerentity, new Vec3d(d5 * d10, d7 * d10, d9 * d10));
}
}
}
}
}
}
}
use of net.minecraft.entity.item.TNTEntity in project Mekanism by mekanism.
the class BlockObsidianTNT method createAndAddEntity.
public static void createAndAddEntity(@Nonnull World world, @Nonnull BlockPos pos, @Nullable LivingEntity igniter) {
TNTEntity tnt = EntityObsidianTNT.create(world, pos.getX() + 0.5F, pos.getY(), pos.getZ() + 0.5F, igniter);
if (tnt != null) {
world.addFreshEntity(tnt);
world.playSound(null, tnt.getX(), tnt.getY(), tnt.getZ(), SoundEvents.TNT_PRIMED, SoundCategory.BLOCKS, 1.0F, 1.0F);
}
}
use of net.minecraft.entity.item.TNTEntity in project ChocolateQuestRepoured by TeamChocoQuest.
the class ProtectedRegionHelper method removeExplosionPreventedPositions.
public static void removeExplosionPreventedPositions(World world, Explosion explosion, boolean checkForOrigin) {
IProtectedRegionManager manager = ProtectedRegionManager.getInstance(world);
if (manager == null) {
return;
}
List<BlockPos> affectedBlockPositions = explosion.getToBlow();
if (affectedBlockPositions.isEmpty()) {
return;
}
// If the exploder is our own custom tnt => let it blow!
if (explosion.source instanceof EntityTNTPrimedCQR) {
return;
}
boolean flag = explosion.source instanceof TNTEntity;
boolean flag1 = (flag && CQRConfig.dungeonProtection.enablePreventExplosionTNT) || (!flag && CQRConfig.dungeonProtection.enablePreventExplosionOther);
boolean flag2 = CQRConfig.dungeonProtection.protectionSystemEnabled && flag1;
if (flag2) {
BlockPos pos = new BlockPos(explosion.getPosition());
for (ProtectedRegion protectedRegion : manager.getProtectedRegions()) {
if ((flag && protectedRegion.preventExplosionsTNT()) || (!flag && protectedRegion.preventExplosionsOther())) {
if (checkForOrigin && protectedRegion.isInsideProtectedRegion(pos)) {
affectedBlockPositions.clear();
} else {
for (int i = 0; i < affectedBlockPositions.size(); i++) {
BlockPos pos1 = affectedBlockPositions.get(i);
if (protectedRegion.isInsideProtectedRegion(pos1)) {
affectedBlockPositions.remove(i--);
}
}
}
}
if (affectedBlockPositions.isEmpty()) {
return;
}
}
}
for (ProtectedRegion protectedRegion : manager.getProtectedRegions()) {
for (BlockPos pos1 : affectedBlockPositions) {
protectedRegion.setProtectionState(pos1, 0);
}
}
}
use of net.minecraft.entity.item.TNTEntity in project Fragile-Glass by fredtargaryen.
the class EntityDataManager method addCapabilityIfPossible.
public void addCapabilityIfPossible(Entity e, AttachCapabilitiesEvent<Entity> evt) {
// A player would reasonably expect many existing entities to be able to break fragile blocks, but it is
// very unlikely that anyone would go to the trouble of writing out all the config lines for every entity.
// The following code does some type checks and creates BreakerDatas if the entity probably would break a block.
BreakerData breakerData = this.data.get(e.getType());
if (breakerData == null) {
// A breakerdata for this entitytype has not been created yet
if (e instanceof LivingEntity || e instanceof ArrowEntity || e instanceof FireballEntity || e instanceof MinecartEntity || e instanceof FireworkRocketEntity || e instanceof BoatEntity || e instanceof TNTEntity || e instanceof FallingBlockEntity) {
breakerData = new BreakerData(DataReference.MINIMUM_ENTITY_SPEED_SQUARED, DataReference.MAXIMUM_ENTITY_SPEED_SQUARED, new String[] {});
this.data.put(e.getType(), breakerData);
}
}
if (breakerData != null) {
// The entity was predefined (via configs or commands) as being able to break a block,
// or a BreakerData was automatically created above.
ICapabilityProvider iCapProv = new ICapabilityProvider() {
IBreakCapability inst = new IBreakCapability() {
@Override
public void init(Entity e) {
}
@Override
public void update(Entity e) {
}
@Override
public double getSpeedSquared(Entity e) {
Vector3d motion = e.getMotion();
return motion.x * motion.x + motion.y * motion.y + motion.z * motion.z;
}
@Override
public boolean isAbleToBreak(Entity e, double speedSq) {
BreakerData breakerData = EntityDataManager.this.data.get(e.getType());
if (breakerData == null)
return false;
return speedSq >= breakerData.getMinSpeedSquared() && speedSq <= breakerData.getMaxSpeedSquared();
}
@Override
public double getMotionX(Entity e) {
return e.getMotion().x;
}
@Override
public double getMotionY(Entity e) {
return e.getMotion().y;
}
@Override
public double getMotionZ(Entity e) {
return e.getMotion().z;
}
@Override
public byte getNoOfBreaks(Entity e) {
return 1;
}
};
@Nullable
@Override
public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> capability, @Nullable Direction facing) {
return capability == FragileGlassBase.BREAKCAP ? LazyOptional.of(() -> (T) inst) : LazyOptional.empty();
}
};
evt.addCapability(DataReference.BREAK_LOCATION, iCapProv);
}
}
use of net.minecraft.entity.item.TNTEntity in project Mekanism by mekanism.
the class BlockObsidianTNT method wasExploded.
@Override
public void wasExploded(World world, @Nonnull BlockPos pos, @Nonnull Explosion explosion) {
if (!world.isClientSide) {
TNTEntity tnt = EntityObsidianTNT.create(world, pos.getX() + 0.5F, pos.getY(), pos.getZ() + 0.5F, explosion.getSourceMob());
if (tnt != null) {
tnt.setFuse((short) (world.random.nextInt(tnt.getLife() / 4) + tnt.getLife() / 8));
world.addFreshEntity(tnt);
}
}
}
Aggregations