本文整理汇总了Java中cn.nukkit.event.entity.EntityDamageByEntityEvent类的典型用法代码示例。如果您正苦于以下问题:Java EntityDamageByEntityEvent类的具体用法?Java EntityDamageByEntityEvent怎么用?Java EntityDamageByEntityEvent使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
EntityDamageByEntityEvent类属于cn.nukkit.event.entity包,在下文中一共展示了EntityDamageByEntityEvent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: attack
import cn.nukkit.event.entity.EntityDamageByEntityEvent; //导入依赖的package包/类
@Override
public void attack(EntityDamageEvent source) {
super.attack(source);
if (source.isCancelled()) return;
if (source instanceof EntityDamageByEntityEvent) {
Entity damager = ((EntityDamageByEntityEvent) source).getDamager();
if (damager instanceof Player) {
if (((Player) damager).isCreative()) {
this.kill();
}
if (this.getHealth() <= 0) {
if (((Player) damager).isSurvival()) {
this.level.dropItem(this, new ItemBoat());
}
this.close();
}
}
}
EntityEventPacket pk = new EntityEventPacket();
pk.eid = this.getId();
pk.event = this.getHealth() <= 0 ? EntityEventPacket.DEATH_ANIMATION : EntityEventPacket.HURT_ANIMATION;
Server.broadcastPacket(this.hasSpawned.values(), pk);
}
示例2: onDamage
import cn.nukkit.event.entity.EntityDamageByEntityEvent; //导入依赖的package包/类
@EventHandler
public void onDamage(EntityDamageEvent event){
if(this.status == STATUS_STOPPED){
if(event.getEntity() instanceof Player){
event.setCancelled();
}
}else{
if(event.getEntity() instanceof Player){
if(immortal.contains(((Player)event.getEntity()).getName())){
event.setCancelled();
}
}
}
if(event instanceof EntityDamageByEntityEvent){
EntityDamageByEntityEvent e = (EntityDamageByEntityEvent) event;
if(e.getDamager() instanceof Player){
if(this.isColleague(e.getDamager().getName(), e.getEntity().getName()) || this.status != STATUS_ONGOING){
event.setCancelled();
}
}
}
}
示例3: getDrops
import cn.nukkit.event.entity.EntityDamageByEntityEvent; //导入依赖的package包/类
@Override
public Item[] getDrops() {
if (this.lastDamageCause instanceof EntityDamageByEntityEvent) {
return new Item[]{Item.get(Item.GUNPOWDER, level.rand.nextInt(2) + 1)};
}
return new Item[0];
}
示例4: attack
import cn.nukkit.event.entity.EntityDamageByEntityEvent; //导入依赖的package包/类
@Override
public boolean attack(EntityDamageEvent source) {
if (invulnerable) {
return false;
} else {
Entity damager = ((EntityDamageByEntityEvent) source).getDamager();
boolean instantKill = damager instanceof Player && ((Player) damager).isCreative();
if (!instantKill) performHurtAnimation((int) source.getFinalDamage());
if (instantKill || getDamage() > 40) {
if (linkedEntity != null) {
mountEntity(linkedEntity);
}
if (instantKill && (!hasCustomName())) {
kill();
} else {
if (level.getGameRules().getBoolean("doEntityDrops")) {
dropItem();
}
close();
}
}
}
return true;
}
示例5: attack
import cn.nukkit.event.entity.EntityDamageByEntityEvent; //导入依赖的package包/类
@Override
public boolean attack(EntityDamageEvent source) {
if (super.attack(source)) {
if (source instanceof EntityDamageByEntityEvent) {
Entity damager = ((EntityDamageByEntityEvent) source).getDamager();
if (damager instanceof Player && ((Player) damager).isSurvival() && this.level.getGameRules().getBoolean("doEntityDrops")) {
this.level.dropItem(this, new ItemPainting());
}
}
this.close();
return true;
} else {
return false;
}
}
示例6: getDrops
import cn.nukkit.event.entity.EntityDamageByEntityEvent; //导入依赖的package包/类
@Override
public Item[] getDrops() {
if (this.lastDamageCause instanceof EntityDamageByEntityEvent) {
return new Item[]{Item.get(Item.WOOL, getColor(), 1)};
}
return new Item[0];
}
示例7: getDrops
import cn.nukkit.event.entity.EntityDamageByEntityEvent; //导入依赖的package包/类
@Override
public Item[] getDrops() {
Item drops[] = new Item[4];
drops[0] = new ItemPrismarineCrystals(0, random.nextRange(0, 1));
drops[1] = new ItemPrismarineShard(0, random.nextRange(0, 2));
//TODO: 60%の確率で生魚、25%の確率で生鮭、2%の確率でクマノミ、13%の確率でフグ。また焼死時には焼き魚、焼き鮭をドロップ
if (this.getLastDamageCause() instanceof EntityDamageByEntityEvent) {
drops[2] = new ItemBlock(new BlockSponge());
}
return drops;
}
示例8: getDrops
import cn.nukkit.event.entity.EntityDamageByEntityEvent; //导入依赖的package包/类
@Override
public Item[] getDrops(){
if(this.getLastDamageCause() instanceof EntityDamageByEntityEvent){
if(((EntityDamageByEntityEvent) this.getLastDamageCause()).getDamager() instanceof EntitySkeleton){
return new Item[]{Item.get(500 + new NukkitRandom().nextRange(0, 12), 0, 1)}; //レコード
}else{
return new Item[]{new ItemGunpowder(0, new NukkitRandom().nextRange(0, 2))};
}
}
return new Item[]{};
}
示例9: attack
import cn.nukkit.event.entity.EntityDamageByEntityEvent; //导入依赖的package包/类
@Override
public boolean attack(EntityDamageEvent source) {
if (invulnerable) {
return false;
} else {
Entity damager = ((EntityDamageByEntityEvent) source).getDamager();
boolean instantKill = damager instanceof Player && ((Player) damager).isCreative();
if (!instantKill) performHurtAnimation((int) source.getFinalDamage());
if (instantKill || getDamage() > 40) {
if (linkedEntity != null) {
mountEntity(linkedEntity);
}
if (instantKill && (!hasCustomName())) {
kill();
} else {
if (level.getGameRules().getBoolean("doentitydrops")) {
dropItem();
}
close();
}
}
}
return true;
}
示例10: attack
import cn.nukkit.event.entity.EntityDamageByEntityEvent; //导入依赖的package包/类
@Override
public boolean attack(EntityDamageEvent source) {
if (invulnerable) {
return false;
} else {
performHurtAnimation((int) source.getFinalDamage());
Entity damager = ((EntityDamageByEntityEvent) source).getDamager();
boolean instantKill = damager instanceof Player && ((Player) damager).isCreative();
if (instantKill || getDamage() > 40) {
if (linkedEntity != null) {
mountEntity(linkedEntity);
}
if (instantKill && (!hasCustomName())) {
kill();
} else {
if (level.getGameRules().getBoolean("doentitydrops")) {
this.level.dropItem(this, new ItemBoat());
}
close();
}
}
}
return true;
}
示例11: attack
import cn.nukkit.event.entity.EntityDamageByEntityEvent; //导入依赖的package包/类
@Override
public boolean attack(EntityDamageEvent source) {
if (super.attack(source)){
if (source instanceof EntityDamageByEntityEvent) {
Entity damager = ((EntityDamageByEntityEvent) source).getDamager();
if (damager instanceof Player && ((Player) damager).isSurvival()) {
this.level.dropItem(this, new ItemPainting());
}
}
this.close();
return true;
} else {
return false;
}
}
示例12: attack
import cn.nukkit.event.entity.EntityDamageByEntityEvent; //导入依赖的package包/类
@Override
public boolean attack(EntityDamageEvent source) {
if (this.attackTime > 0 || this.noDamageTicks > 0) {
EntityDamageEvent lastCause = this.getLastDamageCause();
if (lastCause != null && lastCause.getDamage() >= source.getDamage()) {
return false;
}
}
if (super.attack(source)) {
if (source instanceof EntityDamageByEntityEvent) {
Entity e = ((EntityDamageByEntityEvent) source).getDamager();
if (source instanceof EntityDamageByChildEntityEvent) {
e = ((EntityDamageByChildEntityEvent) source).getChild();
}
if (e.isOnFire() && !(e instanceof Player)) {
this.setOnFire(2 * this.server.getDifficulty());
}
double deltaX = this.x - e.x;
double deltaZ = this.z - e.z;
this.knockBack(e, source.getDamage(), deltaX, deltaZ, ((EntityDamageByEntityEvent) source).getKnockBack());
}
EntityEventPacket pk = new EntityEventPacket();
pk.entityRuntimeId = this.getId();
pk.event = this.getHealth() <= 0 ? EntityEventPacket.DEATH_ANIMATION : EntityEventPacket.HURT_ANIMATION;
Server.broadcastPacket(this.level.getPlayers().values(), pk);
this.attackTime = 10;
return true;
} else {
return false;
}
}
示例13: onStruckByLightning
import cn.nukkit.event.entity.EntityDamageByEntityEvent; //导入依赖的package包/类
public void onStruckByLightning(Entity entity) {
this.attack(new EntityDamageByEntityEvent(entity, this, DamageCause.LIGHTNING, 5));
if (this.fireTicks < 8 * 20) {
this.setOnFire(8);
}
}
示例14: getDrops
import cn.nukkit.event.entity.EntityDamageByEntityEvent; //导入依赖的package包/类
@Override
public Item[] getDrops() {
Item drops[] = new Item[3];
drops[0] = this.isOnFire() ? new ItemRabbitCooked(0, random.nextRange(0, 1)) : new ItemRabbitRaw(0, random.nextRange(0, 1));
drops[1] = new ItemRabbitHide(0, random.nextRange(0, 1));
if (this.getLastDamageCause() instanceof EntityDamageByEntityEvent && random.nextRange(1, 10) == 1) {
drops[2] = new ItemRabbitFoot(random.nextRange(0, 1));
}
return drops;
}
示例15: attack
import cn.nukkit.event.entity.EntityDamageByEntityEvent; //导入依赖的package包/类
@Override
public boolean attack(EntityDamageEvent source) {
if (super.attack(source)) {
if (source instanceof EntityDamageByEntityEvent) {
Entity damager = ((EntityDamageByEntityEvent) source).getDamager();
if (damager instanceof Player) {
if (((Player) damager).isCreative()) {
this.kill();
}
if (this.getHealth() <= 0) {
if (((Player) damager).isSurvival()) {
this.level.dropItem(this, new ItemBoat());
}
this.close();
}
}
}
EntityEventPacket pk = new EntityEventPacket();
pk.eid = this.getId();
pk.event = this.getHealth() <= 0 ? EntityEventPacket.DEATH_ANIMATION : EntityEventPacket.HURT_ANIMATION;
Server.broadcastPacket(this.hasSpawned.values(), pk);
return true;
} else {
return false;
}
}