3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-23 06:40:07 +01:00
Paper/nms-patches/EntityLightning.patch

84 Zeilen
4.4 KiB
Diff

2015-05-25 12:37:24 +02:00
--- a/net/minecraft/server/EntityLightning.java
+++ b/net/minecraft/server/EntityLightning.java
2019-04-23 04:00:00 +02:00
@@ -5,6 +5,8 @@
import java.util.List;
2018-07-15 02:00:00 +02:00
import javax.annotation.Nullable;
+import org.bukkit.craftbukkit.event.CraftEventFactory; // CraftBukkit
+
2019-04-23 04:00:00 +02:00
public class EntityLightning extends Entity {
private int lifeTicks;
2019-04-23 04:00:00 +02:00
@@ -13,9 +15,11 @@
private final boolean e;
2018-07-15 02:00:00 +02:00
@Nullable
2019-04-23 04:00:00 +02:00
private EntityPlayer f;
2016-02-29 22:32:46 +01:00
+ public boolean isEffect; // CraftBukkit
2015-02-26 23:41:06 +01:00
2016-02-29 22:32:46 +01:00
public EntityLightning(World world, double d0, double d1, double d2, boolean flag) {
2018-07-15 02:00:00 +02:00
super(EntityTypes.LIGHTNING_BOLT, world);
2016-02-29 22:32:46 +01:00
+ this.isEffect = flag; // CraftBukkit
2019-12-10 23:00:00 +01:00
this.ac = true;
this.setPositionRotation(d0, d1, d2, 0.0F, 0.0F);
this.lifeTicks = 2;
2019-04-23 04:00:00 +02:00
@@ -43,7 +47,24 @@
2018-07-15 02:00:00 +02:00
public void tick() {
super.tick();
if (this.lifeTicks == 2) {
2019-12-10 23:00:00 +01:00
- 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
2019-12-10 23:00:00 +01:00
+ // 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;
2019-04-23 04:00:00 +02:00
+ for (EntityPlayer player : (List<EntityPlayer>) (List) this.world.getPlayers()) {
2019-12-10 23:00:00 +01:00
+ 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);
2019-12-10 23:00:00 +01:00
+ 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 {
2019-12-10 23:00:00 +01:00
+ player.playerConnection.sendPacket(new PacketPlayOutNamedSoundEffect(SoundEffects.ENTITY_LIGHTNING_BOLT_THUNDER, SoundCategory.WEATHER, this.locX(), this.locY(), this.locZ(), 10000.0F, pitch));
+ }
+ }
+ // CraftBukkit end
2019-12-10 23:00:00 +01:00
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);
}
2019-04-23 04:00:00 +02:00
@@ -59,7 +80,7 @@
}
}
- if (this.lifeTicks >= 0) {
+ if (this.lifeTicks >= 0 && !this.isEffect) { // CraftBukkit - add !this.isEffect
2015-02-26 23:41:06 +01:00
if (this.world.isClientSide) {
2019-04-23 04:00:00 +02:00
this.world.c(2);
} else if (!this.e) {
@@ -87,14 +108,22 @@
2018-07-15 02:00:00 +02:00
BlockPosition blockposition = new BlockPosition(this);
2019-04-23 04:00:00 +02:00
if (this.world.getType(blockposition).isAir() && iblockdata.canPlace(this.world, blockposition)) {
2018-07-15 02:00:00 +02:00
- 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) {
2019-04-23 04:00:00 +02:00
BlockPosition blockposition1 = blockposition.b(this.random.nextInt(3) - 1, this.random.nextInt(3) - 1, this.random.nextInt(3) - 1);
2018-07-15 02:00:00 +02:00
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
}
}