use of net.minecraft.entity.item.FallingBlockEntity in project Fragile-Glass by fredtargaryen.
the class FallData method onCrash.
@Override
public void onCrash(World world, BlockState state, @Nullable TileEntity te, BlockPos pos, @Nullable Entity crasher, double speedSq) {
if (speedSq > this.breakSpeedSq) {
if (FallingBlock.canFallThrough(world.getBlockState(pos.down()))) {
FallingBlockEntity fallingBlock = new FallingBlockEntity(world, pos.getX() + 0.5D, pos.getY(), pos.getZ() + 0.5D, world.getBlockState(pos));
if (te != null) {
fallingBlock.tileEntityData = te.write(new CompoundNBT());
}
world.addEntity(fallingBlock);
}
}
}
use of net.minecraft.entity.item.FallingBlockEntity 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.FallingBlockEntity in project MCMOD-Industria by M-Marvin.
the class BlockBagStack method entityInside.
@SuppressWarnings("deprecation")
@Override
public void entityInside(BlockState state, World worldIn, BlockPos pos, Entity entityIn) {
if (entityIn instanceof FallingBlockEntity && state.getValue(BAGS) < 4 && entityIn.isAlive()) {
BlockState fallingBags = ((FallingBlockEntity) entityIn).getBlockState();
if (fallingBags.getBlock() == this) {
int bagsToStack = Math.min(fallingBags.getValue(BAGS), 4 - state.getValue(BAGS));
worldIn.setBlockAndUpdate(pos, state.setValue(BAGS, state.getValue(BAGS) + bagsToStack));
if (fallingBags.getValue(BAGS) == bagsToStack) {
entityIn.remove();
} else {
fallingBags = fallingBags.setValue(BAGS, fallingBags.getValue(BAGS) - bagsToStack);
if (worldIn.getBlockState(pos.above()).isAir()) {
worldIn.setBlockAndUpdate(pos.above(), fallingBags);
((FallingBlockEntity) entityIn).dropItem = false;
entityIn.remove();
}
}
}
}
}
use of net.minecraft.entity.item.FallingBlockEntity in project MCMOD-Industria by M-Marvin.
the class BlockBiogas method detonate.
public void detonate(World worldIn, BlockPos pos) {
float spreadForce = 0.2F;
int spreadAmountMin = 0;
int spreadAmountRnd = 2;
float explosionForce = 1.2F;
worldIn.explode(null, pos.getX() + 0.5F, pos.getY() + 0.5F, pos.getZ() + 0.5F, explosionForce, true, Mode.BREAK);
for (int i = worldIn.random.nextInt(spreadAmountRnd) + spreadAmountMin; i >= 0; i--) {
worldIn.setBlockAndUpdate(pos, Blocks.FIRE.defaultBlockState());
FallingBlockEntity spreadFire = new FallingBlockEntity(worldIn, pos.getX(), pos.getY(), pos.getZ(), Blocks.FIRE.defaultBlockState());
float mX = (worldIn.random.nextFloat() - 0.5F) * spreadForce;
float mY = (worldIn.random.nextFloat() * 0.5F) * spreadForce;
float mZ = (worldIn.random.nextFloat() - 0.5F) * spreadForce;
spreadFire.setDeltaMovement(mX, mY, mZ);
Field timeField;
try {
timeField = FallingBlockEntity.class.getDeclaredField("field_145812_b");
timeField.setAccessible(true);
timeField.set(spreadFire, 1);
} catch (NoSuchFieldException | SecurityException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
worldIn.addFreshEntity(spreadFire);
}
}
use of net.minecraft.entity.item.FallingBlockEntity in project MCMOD-Industria by M-Marvin.
the class BlockFuelGas method detonate.
public void detonate(World worldIn, BlockPos pos) {
float spreadForce = 1;
int spreadAmountMin = 1;
int spreadAmountRnd = 2;
float explosionForce = 3;
if (worldIn.random.nextInt(10) == 0 && !worldIn.isClientSide) {
worldIn.explode(null, pos.getX() + 0.5F, pos.getY() + 0.5F, pos.getZ() + 0.5F, explosionForce, true, Mode.BREAK);
for (int i = worldIn.random.nextInt(spreadAmountRnd) + spreadAmountMin; i >= 0; i--) {
worldIn.setBlockAndUpdate(pos, Blocks.FIRE.defaultBlockState());
FallingBlockEntity spreadFire = new FallingBlockEntity(worldIn, pos.getX(), pos.getY(), pos.getZ(), Blocks.FIRE.defaultBlockState());
CompoundNBT timeNBT = new CompoundNBT();
timeNBT.putInt("Time", 1);
spreadFire.load(timeNBT);
float mX = (worldIn.random.nextFloat() - 0.5F) * spreadForce;
float mY = (worldIn.random.nextFloat() * 0.5F) * spreadForce;
float mZ = (worldIn.random.nextFloat() - 0.5F) * spreadForce;
spreadFire.setDeltaMovement(mX, mY, mZ);
Field timeField;
try {
timeField = FallingBlockEntity.class.getDeclaredField("field_145812_b");
timeField.setAccessible(true);
timeField.set(spreadFire, 1);
} catch (NoSuchFieldException | SecurityException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
worldIn.addFreshEntity(spreadFire);
}
}
}
Aggregations