mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-01 05:47:45 +01:00
Add EntityZapEvent
This commit is contained in:
parent
8141041554
commit
472983f423
@ -0,0 +1,14 @@
|
|||||||
|
--- a/net/minecraft/world/entity/ConversionParams.java
|
||||||
|
+++ b/net/minecraft/world/entity/ConversionParams.java
|
||||||
|
@@ -12,4 +12,11 @@
|
||||||
|
public interface AfterConversion<T extends Mob> {
|
||||||
|
void finalizeConversion(T convertedEntity);
|
||||||
|
}
|
||||||
|
+
|
||||||
|
+ // Paper start - entity zap event - allow conversion to be cancelled during finalization
|
||||||
|
+ @FunctionalInterface
|
||||||
|
+ public interface CancellingAfterConversion<T extends Mob> {
|
||||||
|
+ boolean finalizeConversionOrCancel(final T convertedEntity);
|
||||||
|
+ }
|
||||||
|
+ // Paper start - entity zap event - allow conversion to be cancelled during finalization
|
||||||
|
}
|
@ -26,15 +26,15 @@
|
|||||||
public GoalSelector targetSelector;
|
public GoalSelector targetSelector;
|
||||||
@Nullable
|
@Nullable
|
||||||
private LivingEntity target;
|
private LivingEntity target;
|
||||||
@@ -132,6 +144,8 @@
|
@@ -131,6 +143,8 @@
|
||||||
|
private Leashable.LeashData leashData;
|
||||||
private BlockPos restrictCenter;
|
private BlockPos restrictCenter;
|
||||||
private float restrictRadius;
|
private float restrictRadius;
|
||||||
|
|
||||||
+ public boolean aware = true; // CraftBukkit
|
|
||||||
+
|
+
|
||||||
|
+ public boolean aware = true; // CraftBukkit
|
||||||
|
|
||||||
protected Mob(EntityType<? extends Mob> type, Level world) {
|
protected Mob(EntityType<? extends Mob> type, Level world) {
|
||||||
super(type, world);
|
super(type, world);
|
||||||
this.handItems = NonNullList.withSize(2, ItemStack.EMPTY);
|
|
||||||
@@ -160,6 +174,12 @@
|
@@ -160,6 +174,12 @@
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -48,7 +48,7 @@
|
|||||||
protected void registerGoals() {}
|
protected void registerGoals() {}
|
||||||
|
|
||||||
public static AttributeSupplier.Builder createMobAttributes() {
|
public static AttributeSupplier.Builder createMobAttributes() {
|
||||||
@@ -264,11 +284,42 @@
|
@@ -264,13 +284,44 @@
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
protected final LivingEntity getTargetFromBrain() {
|
protected final LivingEntity getTargetFromBrain() {
|
||||||
@ -60,8 +60,8 @@
|
|||||||
- this.target = target;
|
- this.target = target;
|
||||||
+ // CraftBukkit start - fire event
|
+ // CraftBukkit start - fire event
|
||||||
+ this.setTarget(target, EntityTargetEvent.TargetReason.UNKNOWN, true);
|
+ this.setTarget(target, EntityTargetEvent.TargetReason.UNKNOWN, true);
|
||||||
+ }
|
}
|
||||||
+
|
|
||||||
+ public boolean setTarget(LivingEntity entityliving, EntityTargetEvent.TargetReason reason, boolean fireEvent) {
|
+ public boolean setTarget(LivingEntity entityliving, EntityTargetEvent.TargetReason reason, boolean fireEvent) {
|
||||||
+ if (this.getTarget() == entityliving) return false;
|
+ if (this.getTarget() == entityliving) return false;
|
||||||
+ if (fireEvent) {
|
+ if (fireEvent) {
|
||||||
@ -90,9 +90,11 @@
|
|||||||
+ this.target = entityliving;
|
+ this.target = entityliving;
|
||||||
+ return true;
|
+ return true;
|
||||||
+ // CraftBukkit end
|
+ // CraftBukkit end
|
||||||
}
|
+ }
|
||||||
|
+
|
||||||
@Override
|
@Override
|
||||||
|
public boolean canAttackType(EntityType<?> type) {
|
||||||
|
return type != EntityType.GHAST;
|
||||||
@@ -399,6 +450,12 @@
|
@@ -399,6 +450,12 @@
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -276,7 +278,7 @@
|
|||||||
|
|
||||||
optional.ifPresent((entityinsentient) -> {
|
optional.ifPresent((entityinsentient) -> {
|
||||||
this.onOffspringSpawnedFromEgg(player, entityinsentient);
|
this.onOffspringSpawnedFromEgg(player, entityinsentient);
|
||||||
@@ -1389,28 +1490,45 @@
|
@@ -1389,28 +1490,51 @@
|
||||||
return this.restrictRadius != -1.0F;
|
return this.restrictRadius != -1.0F;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -288,6 +290,12 @@
|
|||||||
+
|
+
|
||||||
+ @Nullable
|
+ @Nullable
|
||||||
+ public <T extends Mob> T convertTo(EntityType<T> entitytypes, ConversionParams conversionparams, EntitySpawnReason entityspawnreason, ConversionParams.AfterConversion<T> conversionparams_a, EntityTransformEvent.TransformReason transformReason, CreatureSpawnEvent.SpawnReason spawnReason) {
|
+ public <T extends Mob> T convertTo(EntityType<T> entitytypes, ConversionParams conversionparams, EntitySpawnReason entityspawnreason, ConversionParams.AfterConversion<T> conversionparams_a, EntityTransformEvent.TransformReason transformReason, CreatureSpawnEvent.SpawnReason spawnReason) {
|
||||||
|
+ // Paper start - entity zap event - allow cancellation of conversion post creation
|
||||||
|
+ return this.convertTo(entitytypes, conversionparams, entityspawnreason, e -> { conversionparams_a.finalizeConversion(e); return true; }, transformReason, spawnReason);
|
||||||
|
+ }
|
||||||
|
+ @Nullable
|
||||||
|
+ public <T extends Mob> T convertTo(EntityType<T> entitytypes, ConversionParams conversionparams, EntitySpawnReason entityspawnreason, ConversionParams.CancellingAfterConversion<T> conversionparams_a, EntityTransformEvent.TransformReason transformReason, CreatureSpawnEvent.SpawnReason spawnReason) {
|
||||||
|
+ // Paper end - entity zap event - allow cancellation of conversion post creation
|
||||||
+ // CraftBukkit end
|
+ // CraftBukkit end
|
||||||
if (this.isRemoved()) {
|
if (this.isRemoved()) {
|
||||||
return null;
|
return null;
|
||||||
@ -301,7 +309,7 @@
|
|||||||
- context.type().convert(this, t0, context);
|
- context.type().convert(this, t0, context);
|
||||||
- finalizer.finalizeConversion(t0);
|
- finalizer.finalizeConversion(t0);
|
||||||
+ conversionparams.type().convert(this, t0, conversionparams);
|
+ conversionparams.type().convert(this, t0, conversionparams);
|
||||||
+ conversionparams_a.finalizeConversion(t0);
|
+ if (!conversionparams_a.finalizeConversionOrCancel(t0)) return null; // Paper - entity zap event - return null if conversion was cancelled
|
||||||
Level world = this.level();
|
Level world = this.level();
|
||||||
|
|
||||||
+ // CraftBukkit start
|
+ // CraftBukkit start
|
||||||
@ -328,7 +336,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
return t0;
|
return t0;
|
||||||
@@ -1420,10 +1538,17 @@
|
@@ -1420,10 +1544,22 @@
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public <T extends Mob> T convertTo(EntityType<T> entityType, ConversionParams context, ConversionParams.AfterConversion<T> finalizer) {
|
public <T extends Mob> T convertTo(EntityType<T> entityType, ConversionParams context, ConversionParams.AfterConversion<T> finalizer) {
|
||||||
@ -339,6 +347,11 @@
|
|||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
+ public <T extends Mob> T convertTo(EntityType<T> entitytypes, ConversionParams conversionparams, ConversionParams.AfterConversion<T> conversionparams_a, EntityTransformEvent.TransformReason transformReason, CreatureSpawnEvent.SpawnReason spawnReason) {
|
+ public <T extends Mob> T convertTo(EntityType<T> entitytypes, ConversionParams conversionparams, ConversionParams.AfterConversion<T> conversionparams_a, EntityTransformEvent.TransformReason transformReason, CreatureSpawnEvent.SpawnReason spawnReason) {
|
||||||
|
+ // Paper start - entity zap event - allow cancellation of conversion post creation
|
||||||
|
+ return this.convertTo(entitytypes, conversionparams, e -> { conversionparams_a.finalizeConversion(e); return true; }, transformReason, spawnReason);
|
||||||
|
+ }
|
||||||
|
+ public <T extends Mob> T convertTo(EntityType<T> entitytypes, ConversionParams conversionparams, ConversionParams.CancellingAfterConversion<T> conversionparams_a, EntityTransformEvent.TransformReason transformReason, CreatureSpawnEvent.SpawnReason spawnReason) {
|
||||||
|
+ // Paper start - entity zap event - allow cancellation of conversion post creation
|
||||||
+ return this.convertTo(entitytypes, conversionparams, EntitySpawnReason.CONVERSION, conversionparams_a, transformReason, spawnReason);
|
+ return this.convertTo(entitytypes, conversionparams, EntitySpawnReason.CONVERSION, conversionparams_a, transformReason, spawnReason);
|
||||||
+ // CraftBukkit end
|
+ // CraftBukkit end
|
||||||
+ }
|
+ }
|
||||||
@ -347,7 +360,7 @@
|
|||||||
@Override
|
@Override
|
||||||
public Leashable.LeashData getLeashData() {
|
public Leashable.LeashData getLeashData() {
|
||||||
return this.leashData;
|
return this.leashData;
|
||||||
@@ -1458,6 +1583,7 @@
|
@@ -1458,6 +1594,7 @@
|
||||||
boolean flag1 = super.startRiding(entity, force);
|
boolean flag1 = super.startRiding(entity, force);
|
||||||
|
|
||||||
if (flag1 && this.isLeashed()) {
|
if (flag1 && this.isLeashed()) {
|
||||||
@ -355,7 +368,7 @@
|
|||||||
this.dropLeash();
|
this.dropLeash();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1542,7 +1668,7 @@
|
@@ -1542,7 +1679,7 @@
|
||||||
|
|
||||||
if (f1 > 0.0F && target instanceof LivingEntity) {
|
if (f1 > 0.0F && target instanceof LivingEntity) {
|
||||||
entityliving = (LivingEntity) target;
|
entityliving = (LivingEntity) target;
|
||||||
|
@ -109,16 +109,29 @@
|
|||||||
Entity entity = damageSource.getEntity();
|
Entity entity = damageSource.getEntity();
|
||||||
|
|
||||||
if (entity != null) {
|
if (entity != null) {
|
||||||
@@ -808,7 +839,7 @@
|
@@ -803,12 +834,19 @@
|
||||||
|
@Override
|
||||||
|
public void thunderHit(ServerLevel world, LightningBolt lightning) {
|
||||||
|
if (world.getDifficulty() != Difficulty.PEACEFUL) {
|
||||||
|
- Villager.LOGGER.info("Villager {} was struck by lightning {}.", this, lightning);
|
||||||
|
+ // Paper - Add EntityZapEvent; move log down, event can cancel
|
||||||
|
Witch entitywitch = (Witch) this.convertTo(EntityType.WITCH, ConversionParams.single(this, false, false), (entitywitch1) -> {
|
||||||
|
+ // Paper start - Add EntityZapEvent
|
||||||
|
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callEntityZapEvent(this, lightning, entitywitch1).isCancelled()) {
|
||||||
|
+ return false;
|
||||||
|
+ }
|
||||||
|
+ if (org.spigotmc.SpigotConfig.logVillagerDeaths) Villager.LOGGER.info("Villager {} was struck by lightning {}.", this, lightning); // Move down
|
||||||
|
+ // Paper end - Add EntityZapEvent
|
||||||
entitywitch1.finalizeSpawn(world, world.getCurrentDifficultyAt(entitywitch1.blockPosition()), EntitySpawnReason.CONVERSION, (SpawnGroupData) null);
|
entitywitch1.finalizeSpawn(world, world.getCurrentDifficultyAt(entitywitch1.blockPosition()), EntitySpawnReason.CONVERSION, (SpawnGroupData) null);
|
||||||
entitywitch1.setPersistenceRequired();
|
entitywitch1.setPersistenceRequired();
|
||||||
this.releaseAllPois();
|
this.releaseAllPois();
|
||||||
- });
|
- });
|
||||||
|
+ return true; // Paper start - Add EntityZapEvent
|
||||||
+ }, EntityTransformEvent.TransformReason.LIGHTNING, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.LIGHTNING); // CraftBukkit
|
+ }, EntityTransformEvent.TransformReason.LIGHTNING, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.LIGHTNING); // CraftBukkit
|
||||||
|
|
||||||
if (entitywitch == null) {
|
if (entitywitch == null) {
|
||||||
super.thunderHit(world, lightning);
|
super.thunderHit(world, lightning);
|
||||||
@@ -906,7 +937,7 @@
|
@@ -906,7 +944,7 @@
|
||||||
}).limit(5L).toList();
|
}).limit(5L).toList();
|
||||||
|
|
||||||
if (list1.size() >= requiredCount) {
|
if (list1.size() >= requiredCount) {
|
||||||
@ -127,7 +140,7 @@
|
|||||||
list.forEach(GolemSensor::golemDetected);
|
list.forEach(GolemSensor::golemDetected);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -963,7 +994,7 @@
|
@@ -963,7 +1001,7 @@
|
||||||
@Override
|
@Override
|
||||||
public void startSleeping(BlockPos pos) {
|
public void startSleeping(BlockPos pos) {
|
||||||
super.startSleeping(pos);
|
super.startSleeping(pos);
|
||||||
@ -136,7 +149,7 @@
|
|||||||
this.brain.eraseMemory(MemoryModuleType.WALK_TARGET);
|
this.brain.eraseMemory(MemoryModuleType.WALK_TARGET);
|
||||||
this.brain.eraseMemory(MemoryModuleType.CANT_REACH_WALK_TARGET_SINCE);
|
this.brain.eraseMemory(MemoryModuleType.CANT_REACH_WALK_TARGET_SINCE);
|
||||||
}
|
}
|
||||||
@@ -971,7 +1002,7 @@
|
@@ -971,7 +1009,7 @@
|
||||||
@Override
|
@Override
|
||||||
public void stopSleeping() {
|
public void stopSleeping() {
|
||||||
super.stopSleeping();
|
super.stopSleeping();
|
||||||
|
@ -1215,6 +1215,14 @@ public class CraftEventFactory {
|
|||||||
return !event.isCancelled();
|
return !event.isCancelled();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Paper start
|
||||||
|
public static com.destroystokyo.paper.event.entity.EntityZapEvent callEntityZapEvent(Entity entity, Entity lightning, Entity changedEntity) {
|
||||||
|
com.destroystokyo.paper.event.entity.EntityZapEvent event = new com.destroystokyo.paper.event.entity.EntityZapEvent(entity.getBukkitEntity(), (LightningStrike) lightning.getBukkitEntity(), changedEntity.getBukkitEntity());
|
||||||
|
entity.getBukkitEntity().getServer().getPluginManager().callEvent(event);
|
||||||
|
return event;
|
||||||
|
}
|
||||||
|
// Paper end
|
||||||
|
|
||||||
public static boolean callEntityChangeBlockEvent(Entity entity, BlockPos position, net.minecraft.world.level.block.state.BlockState newBlock) {
|
public static boolean callEntityChangeBlockEvent(Entity entity, BlockPos position, net.minecraft.world.level.block.state.BlockState newBlock) {
|
||||||
return CraftEventFactory.callEntityChangeBlockEvent(entity, position, newBlock, false);
|
return CraftEventFactory.callEntityChangeBlockEvent(entity, position, newBlock, false);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user