cn.nukkit.entity.item.EntityEndCrystal Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of powernukkit Show documentation
Show all versions of powernukkit Show documentation
A Minecraft Bedrock Edition server software implementation made in Java from scratch which supports all new features.
package cn.nukkit.entity.item;
import cn.nukkit.entity.Entity;
import cn.nukkit.entity.EntityExplosive;
import cn.nukkit.event.entity.EntityDamageEvent;
import cn.nukkit.level.Explosion;
import cn.nukkit.level.GameRule;
import cn.nukkit.level.Position;
import cn.nukkit.level.format.FullChunk;
import cn.nukkit.nbt.tag.CompoundTag;
/**
* @author PetteriM1
*/
public class EntityEndCrystal extends Entity implements EntityExplosive {
public static final int NETWORK_ID = 71;
/**
* @since 1.2.1.0-PN
*/
protected boolean detonated = false;
@Override
public int getNetworkId() {
return NETWORK_ID;
}
public EntityEndCrystal(FullChunk chunk, CompoundTag nbt) {
super(chunk, nbt);
}
@Override
protected void initEntity() {
super.initEntity();
if (this.namedTag.contains("ShowBottom")) {
this.setShowBase(this.namedTag.getBoolean("ShowBottom"));
}
this.fireProof = true;
this.setDataFlag(DATA_FLAGS, DATA_FLAG_FIRE_IMMUNE, true);
}
@Override
public void saveNBT() {
super.saveNBT();
this.namedTag.putBoolean("ShowBottom", this.showBase());
}
@Override
public float getHeight() {
return 0.98f;
}
@Override
public float getWidth() {
return 0.98f;
}
@Override
public boolean attack(EntityDamageEvent source) {
if (isClosed()) {
return false;
}
if (source.getCause() == EntityDamageEvent.DamageCause.FIRE || source.getCause() == EntityDamageEvent.DamageCause.FIRE_TICK || source.getCause() == EntityDamageEvent.DamageCause.LAVA) {
return false;
}
if (!super.attack(source)) {
return false;
}
explode();
return true;
}
@Override
public void explode() {
if (!this.detonated) {
this.detonated = true;
Position pos = this.getPosition();
Explosion explode = new Explosion(pos, 6, this);
this.close();
if (this.level.getGameRules().getBoolean(GameRule.MOB_GRIEFING)) {
explode.explodeA();
explode.explodeB();
}
}
}
@Override
public boolean canCollideWith(Entity entity) {
return false;
}
public boolean showBase() {
return this.getDataFlag(DATA_FLAGS, DATA_FLAG_SHOWBASE);
}
public void setShowBase(boolean value) {
this.setDataFlag(DATA_FLAGS, DATA_FLAG_SHOWBASE, value);
}
}