Защитить Жителей от удара молнии

olegtrick78

Активный участник
Пользователь
Баллы
66
Добрый день (ночь). Пытаюсь решить проблему с неуязвимостью жителей . Урон от entity запретил,

@EventHandler
public void onEntityDamage(EntityDamageEvent es) {
if(es.getEntity() instanceof Villager) {
es.setCancelled(true);}
}

Проблема неуязвимости не решена полностью, при ударе молнии житель превращается в ведьму и его можно убить. Пробовал код :

@EventHandler
private void onLightningStrikeEvent (EntityDamageByEntityEvent h) {
if(h.getEntity() instanceof Villager) {
if(h.getCause() == DamageCause.LIGHTNING) {
h.setCancelled(true);
}
}
}
----- тоже не помогает .
 
Можно попытаться ловить LightningStrikeEvent, проверять наличие жителей поблизости и отменять если они есть.
 
Я смотрел тут примеры, https://www.programcreek.com/java-api-examples/index.php?api=org.bukkit.event.weather.LightningStrikeEvent

Пробовал такой вариант. Не получается

@EventHandler(ignoreCancelled = true)
void onLightningStrike(LightningStrikeEvent event) {
// workaround: preventing lightning strikes near villager shopkeepers
// because they would turn into witches
Location loc = event.getLightning().getLocation();
for (Entity entity : Utils.getNearbyEntities(loc, VILLAGER_ZAP_RADIUS, EntityType.VILLAGER)) {
if (plugin.isShopkeeper(entity)) {
event.setCancelled(true);
}
}

. Shopkeeper - название плагина. VILLAGER_ZAP_RADIUS - такого нет в Спиготе у меня.
 
Это и есть то что я предлагал. Только под себя перепиши.
 
Скачал исходники ShopKeepers , создал класс Utils.java, загнал туда необходимое ( Utils.getNearbyEntities ), попробую оживить эту конструкцию )) .

Спасибо , Cool_boy !! Немного таких разрабов, которые пишут по существу.
 
Вот что мне ответили на spigotmc.org

You could always try to create a Custom NMS mob and override the associated method.
( Вы можете создать NMS моба и переопределить связанный метод. )

This is straight from the EntityVillager class: ( Это из класса EntityVillager )
----------------------------------------------------------------------------------------------------
Code (Java):
public void onLightningStrike(EntityLightning entitylightning) {
if (!this.world.isClientSide && !this.dead) {
EntityWitch entitywitch = new EntityWitch(this.world);

entitywitch.setPositionRotation(this.locX, this.locY, this.locZ, this.yaw, this.pitch);
entitywitch.prepare(this.world.D(new BlockPosition(entitywitch)), (GroupDataEntity) null);
entitywitch.setNoAI(this.isNoAI());
if (this.hasCustomName()) {
entitywitch.setCustomName(this.getCustomName());
entitywitch.setCustomNameVisible(this.getCustomNameVisible());
}

this.world.addEntity(entitywitch);
this.die();
}
}
--------------------------------------------------------------------------------------------------
Это просто КАПЕЦ костыль... Надо пробовать )))
 
Вот что мне ответили на spigotmc.org

You could always try to create a Custom NMS mob and override the associated method.
( Вы можете создать NMS моба и переопределить связанный метод. )

This is straight from the EntityVillager class: ( Это из класса EntityVillager )
----------------------------------------------------------------------------------------------------
Code (Java):
public void onLightningStrike(EntityLightning entitylightning) {
if (!this.world.isClientSide && !this.dead) {
EntityWitch entitywitch = new EntityWitch(this.world);

entitywitch.setPositionRotation(this.locX, this.locY, this.locZ, this.yaw, this.pitch);
entitywitch.prepare(this.world.D(new BlockPosition(entitywitch)), (GroupDataEntity) null);
entitywitch.setNoAI(this.isNoAI());
if (this.hasCustomName()) {
entitywitch.setCustomName(this.getCustomName());
entitywitch.setCustomNameVisible(this.getCustomNameVisible());
}

this.world.addEntity(entitywitch);
this.die();
}
}
--------------------------------------------------------------------------------------------------
Это просто КАПЕЦ костыль... Надо пробовать )))
Отмена LightningStrikeEvent не помогла?
 
Назад
Верх