13
0
geforkt von Mirrors/Paper
Paper/nms-patches/EntityLightning.patch
2020-08-12 07:00:00 +10:00

73 Zeilen
4.0 KiB
Diff

--- a/net/minecraft/server/EntityLightning.java
+++ b/net/minecraft/server/EntityLightning.java
@@ -5,6 +5,8 @@
import java.util.List;
import javax.annotation.Nullable;
+import org.bukkit.craftbukkit.event.CraftEventFactory; // CraftBukkit
+
public class EntityLightning extends Entity {
private int lifeTicks;
@@ -45,7 +47,24 @@
this.a(4);
}
- this.world.playSound((EntityHuman) null, this.locX(), this.locY(), this.locZ(), SoundEffects.ENTITY_LIGHTNING_BOLT_THUNDER, SoundCategory.WEATHER, 10000.0F, 0.8F + this.random.nextFloat() * 0.2F);
+ // CraftBukkit start - Use relative location for far away sounds
+ // this.world.playSound((EntityHuman) null, this.locX(), this.locY(), this.locZ(), SoundEffects.ENTITY_LIGHTNING_BOLT_THUNDER, SoundCategory.WEATHER, 10000.0F, 0.8F + this.random.nextFloat() * 0.2F);
+ float pitch = 0.8F + this.random.nextFloat() * 0.2F;
+ int viewDistance = ((WorldServer) this.world).getServer().getViewDistance() * 16;
+ for (EntityPlayer player : (List<EntityPlayer>) (List) this.world.getPlayers()) {
+ double deltaX = this.locX() - player.locX();
+ double deltaZ = this.locZ() - player.locZ();
+ double distanceSquared = deltaX * deltaX + deltaZ * deltaZ;
+ if (distanceSquared > viewDistance * viewDistance) {
+ double deltaLength = Math.sqrt(distanceSquared);
+ double relativeX = player.locX() + (deltaX / deltaLength) * viewDistance;
+ double relativeZ = player.locZ() + (deltaZ / deltaLength) * viewDistance;
+ player.playerConnection.sendPacket(new PacketPlayOutNamedSoundEffect(SoundEffects.ENTITY_LIGHTNING_BOLT_THUNDER, SoundCategory.WEATHER, relativeX, this.locY(), relativeZ, 10000.0F, pitch));
+ } else {
+ player.playerConnection.sendPacket(new PacketPlayOutNamedSoundEffect(SoundEffects.ENTITY_LIGHTNING_BOLT_THUNDER, SoundCategory.WEATHER, this.locX(), this.locY(), this.locZ(), 10000.0F, pitch));
+ }
+ }
+ // CraftBukkit end
this.world.playSound((EntityHuman) null, this.locX(), this.locY(), this.locZ(), SoundEffects.ENTITY_LIGHTNING_BOLT_IMPACT, SoundCategory.WEATHER, 2.0F, 0.5F + this.random.nextFloat() * 0.2F);
}
@@ -61,7 +80,7 @@
}
}
- if (this.lifeTicks >= 0) {
+ if (this.lifeTicks >= 0 && !this.isEffect) { // CraftBukkit - add !this.isEffect
if (!(this.world instanceof WorldServer)) {
this.world.c(2);
} else if (!this.isEffect) {
@@ -89,7 +108,11 @@
IBlockData iblockdata = BlockFireAbstract.a((IBlockAccess) this.world, blockposition);
if (this.world.getType(blockposition).isAir() && iblockdata.canPlace(this.world, blockposition)) {
- this.world.setTypeUpdate(blockposition, iblockdata);
+ // CraftBukkit start - add "!isEffect"
+ if (!isEffect && !CraftEventFactory.callBlockIgniteEvent(world, blockposition, this).isCancelled()) {
+ this.world.setTypeUpdate(blockposition, iblockdata);
+ }
+ // CraftBukkit end
}
for (int j = 0; j < i; ++j) {
@@ -97,7 +120,11 @@
iblockdata = BlockFireAbstract.a((IBlockAccess) this.world, blockposition1);
if (this.world.getType(blockposition1).isAir() && iblockdata.canPlace(this.world, blockposition1)) {
- this.world.setTypeUpdate(blockposition1, iblockdata);
+ // CraftBukkit start - add "!isEffect"
+ if (!isEffect && !CraftEventFactory.callBlockIgniteEvent(world, blockposition1, this).isCancelled()) {
+ this.world.setTypeUpdate(blockposition1, iblockdata);
+ }
+ // CraftBukkit end
}
}