
net.minecraft.server.EntityFallingBlock Maven / Gradle / Ivy
package net.minecraft.server;
import com.google.common.collect.Lists;
import org.bukkit.craftbukkit.event.CraftEventFactory;
import org.bukkit.entity.FallingBlock;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
public class EntityFallingBlock extends Entity {
public int ticksLived;
public boolean dropItem = true;
public boolean hurtEntities; // PAIL: private -> public
public NBTTagCompound tileEntityData;
private IBlockData block;
private boolean e;
private int fallHurtMax = 40;
private float fallHurtAmount = 2.0F;
@NotNull
@Override
public FallingBlock getEntityBukkit() {
return (FallingBlock) super.getEntityBukkit();
}
public EntityFallingBlock(World world) {
super(world);
}
public EntityFallingBlock(World world, double d0, double d1, double d2, IBlockData iblockdata) {
super(world);
this.block = iblockdata;
this.preventEntitySpawning = true;
this.setSize(0.98F, 0.98F);
this.setPosition(d0, d1, d2);
this.motX = 0.0D;
this.motY = 0.0D;
this.motZ = 0.0D;
this.lastX = d0;
this.lastY = d1;
this.lastZ = d2;
}
protected boolean canTriggerWalking() {
return false;
}
protected void entityInit() {
}
public boolean canBeCollidedWith() {
return !this.dead;
}
public void onUpdate() {
final Block block = this.block.getBlock();
if (block.getMaterial() == Material.AIR) {
this.die();
return;
}
this.lastX = this.locX;
this.lastY = this.locY;
this.lastZ = this.locZ;
BlockPosition blockposition;
if (this.ticksLived++ == 0) {
blockposition = new BlockPosition(this);
if (this.world.getType(blockposition).getBlock() == block && !CraftEventFactory.callEntityChangeBlockEvent(this, blockposition.getX(), blockposition.getY(), blockposition.getZ(), Blocks.AIR, 0).isCancelled()) {
this.world.setAir(blockposition);
} else if (!this.world.isClientSide) {
this.die();
return;
}
}
this.motY -= 0.03999999910593033D;
this.move(this.motX, this.motY, this.motZ);
this.motX *= 0.9800000190734863D;
this.motY *= 0.9800000190734863D;
this.motZ *= 0.9800000190734863D;
if (!this.world.isClientSide) {
blockposition = new BlockPosition(this);
if (this.onGround) {
this.motX *= 0.699999988079071D;
this.motZ *= 0.699999988079071D;
this.motY *= -0.5D;
final IBlockData data = world.getType(blockposition);
if (data.getBlock() != Blocks.PISTON_EXTENSION) {
this.die();
if (!this.e) {
if (this.world.a(block, blockposition, true, EnumDirection.UP, null, null) && !BlockFalling.canFall(this.world, blockposition.down()) /* mimic the false conditions of setTypeIdAndData */ && blockposition.getX() >= -30000000 && blockposition.getZ() >= -30000000 && blockposition.getX() < 30000000 && blockposition.getZ() < 30000000 && blockposition.getY() >= 0 && blockposition.getY() < 256 && data != this.block) {
if (CraftEventFactory.callEntityChangeBlockEvent(this, blockposition.getX(), blockposition.getY(), blockposition.getZ(), this.block.getBlock(), this.block.getBlock().toLegacyData(this.block)).isCancelled())
return;
this.world.setTypeAndData(blockposition, this.block, 3);
// CraftBukkit end
if (block instanceof BlockFalling) {
((BlockFalling) block).a_(this.world, blockposition);
}
if (this.tileEntityData != null && block instanceof IContainer) {
TileEntity tileentity = this.world.getTileEntity(blockposition);
if (tileentity != null) {
NBTTagCompound nbttagcompound = new NBTTagCompound();
tileentity.b(nbttagcompound);
for (String s : this.tileEntityData.c()) {
NBTBase nbtbase = this.tileEntityData.get(s);
if (!s.equals("x") && !s.equals("y") && !s.equals("z")) {
nbttagcompound.set(s, nbtbase.clone());
}
}
tileentity.a(nbttagcompound);
tileentity.update();
}
}
} else if (this.dropItem && this.world.getGameRules().getBoolean("doEntityDrops")) {
this.dropItem(new ItemStack(block, 1, block.getDropData(this.block)), 0.0F);
}
}
}
} else if (this.ticksLived > 100 && !this.world.isClientSide && (blockposition.getY() < 1 || blockposition.getY() > 256) || this.ticksLived > 600) {
if (this.dropItem && this.world.getGameRules().getBoolean("doEntityDrops")) {
this.dropItem(new ItemStack(block, 1, block.getDropData(this.block)), 0.0F);
}
this.die();
}
}
}
public void fall(final float f, final float f1) {
final Block block = this.block.getBlock();
if (this.hurtEntities) {
final int i = MathHelper.f(f - 1.0F);
if (i > 0) {
final ArrayList arraylist = Lists.newArrayList(this.world.getEntities(this, this.getBoundingBox()));
final boolean flag = block == Blocks.ANVIL;
final DamageSource damagesource = flag ? DamageSource.ANVIL : DamageSource.FALLING_BLOCK;
for (final Entity o : arraylist) {
CraftEventFactory.entityDamage = this; // CraftBukkit
o.damageEntity(damagesource, (float) Math.min(MathHelper.d((float) i * this.fallHurtAmount), this.fallHurtMax));
CraftEventFactory.entityDamage = null; // CraftBukkit
}
if (flag && (double) this.random.nextFloat() < 0.05000000074505806D + (double) i * 0.05D) {
int j = this.block.get(BlockAnvil.DAMAGE);
++j;
if (j > 2) {
this.e = true;
} else {
this.block = this.block.set(BlockAnvil.DAMAGE, j);
}
}
}
}
}
protected void saveEntityData(NBTTagCompound tag) {
Block block = this.block != null ? this.block.getBlock() : Blocks.AIR;
MinecraftKey minecraftkey = Block.REGISTRY.c(block);
tag.setString("Block", minecraftkey == null ? "" : minecraftkey.toString());
tag.setByte("Data", (byte) block.toLegacyData(this.block));
tag.setByte("Time", (byte) this.ticksLived);
tag.setBoolean("DropItem", this.dropItem);
tag.setBoolean("HurtEntities", this.hurtEntities);
tag.setFloat("FallHurtAmount", this.fallHurtAmount);
tag.setInt("FallHurtMax", this.fallHurtMax);
if (this.tileEntityData != null) {
tag.set("TileEntityData", this.tileEntityData);
}
}
protected void loadEntityData(NBTTagCompound tag) {
int i = tag.getByte("Data") & 255;
if (tag.hasKeyOfType("Block", 8)) {
this.block = Block.getByName(tag.getString("Block")).fromLegacyData(i);
} else if (tag.hasKeyOfType("TileID", 99)) {
this.block = Block.getById(tag.getInt("TileID")).fromLegacyData(i);
} else {
this.block = Block.getById(tag.getByte("Tile") & 255).fromLegacyData(i);
}
this.ticksLived = tag.getByte("Time") & 255;
Block block = this.block.getBlock();
if (tag.hasKeyOfType("HurtEntities", 99)) {
this.hurtEntities = tag.getBoolean("HurtEntities");
this.fallHurtAmount = tag.getFloat("FallHurtAmount");
this.fallHurtMax = tag.getInt("FallHurtMax");
} else if (block == Blocks.ANVIL) {
this.hurtEntities = true;
}
if (tag.hasKeyOfType("DropItem", 99)) {
this.dropItem = tag.getBoolean("DropItem");
}
if (tag.hasKeyOfType("TileEntityData", 10)) {
this.tileEntityData = tag.getCompound("TileEntityData");
}
if (block == null || block.getMaterial() == Material.AIR) {
this.block = Blocks.SAND.getBlockData();
}
}
public void a(boolean flag) {
this.hurtEntities = flag;
}
public void appendEntityCrashDetails(CrashReportSystemDetails crash) {
super.appendEntityCrashDetails(crash);
if (this.block != null) {
Block block = this.block.getBlock();
crash.a("Immitating block ID", Block.getId(block));
crash.a("Immitating block data", block.toLegacyData(this.block));
}
}
public IBlockData getBlock() {
return this.block;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy