Files
Purpur/patches/server/0183-API-for-any-mob-to-burn-daylight.patch
BillyGalbreath aa349b9566 Updated Upstream (Paper)
Upstream has released updates that appear to apply and compile correctly

Paper Changes:
PaperMC/Paper@ea777c3 Add a consumer parameter to ProjectileSource#launchProjectile (#8374)
PaperMC/Paper@470c638 Configurable chat thread limit (#7878)
PaperMC/Paper@dbc2d60 Make WorldCreator#keepSpawnLoaded return the WorldCreator (Fixes #8321) (#8371)
PaperMC/Paper@f8742e2 Also load resources from LibraryLoader (#8335)
PaperMC/Paper@f7e6809 Fix Pathfinding After World Has Changed (#8068)
PaperMC/Paper@ad3dffe Respect preventMovingIntoUnloadedChunks for optimized collision checking (#8259)
PaperMC/Paper@8db45c4 Copper clear on lightning strike calls EntityChangeBlockEvent (#8126)
2022-09-20 00:58:02 -05:00

389 lines
18 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Ben Kerllenevich <ben@omega24.dev>
Date: Tue, 25 May 2021 16:31:09 -0400
Subject: [PATCH] API for any mob to burn daylight
Co-authored by: Encode42 <me@encode42.dev>
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index e9a931ce31257ad1a29c15d1619e5f80865f151b..9af78fde6b4d75cf7656c575b98e1e174f599e22 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -4611,5 +4611,20 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
public boolean canSaveToDisk() {
return true;
}
+
+ // Purpur start - copied from Mob
+ public boolean isSunBurnTick() {
+ if (this.level.isDay() && !this.level.isClientSide) {
+ float f = this.getLightLevelDependentMagicValue();
+ BlockPos blockposition = new BlockPos(this.getX(), this.getEyeY(), this.getZ());
+ boolean flag = this.isInWaterRainOrBubble() || this.isInPowderSnow || this.wasInPowderSnow;
+
+ if (f > 0.5F && this.random.nextFloat() * 30.0F < (f - 0.4F) * 2.0F && !flag && this.level.canSeeSky(blockposition)) {
+ return true;
+ }
+ }
+
+ return false;
+ }
// Purpur end
}
diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
index a0d3c0c15380cf42049e1b27d8c73ea8e1624b89..142f25da0d758821ce192cea9c65921324c27ef8 100644
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
@@ -265,6 +265,7 @@ public abstract class LivingEntity extends Entity {
public boolean bukkitPickUpLoot;
public org.bukkit.craftbukkit.entity.CraftLivingEntity getBukkitLivingEntity() { return (org.bukkit.craftbukkit.entity.CraftLivingEntity) super.getBukkitEntity(); } // Paper
public boolean silentDeath = false; // Paper - mark entity as dying silently for cancellable death event
+ protected boolean shouldBurnInDay = false; public boolean shouldBurnInDay() { return this.shouldBurnInDay; } public void setShouldBurnInDay(boolean shouldBurnInDay) { this.shouldBurnInDay = shouldBurnInDay; } // Purpur
@Override
public float getBukkitYaw() {
@@ -788,6 +789,7 @@ public abstract class LivingEntity extends Entity {
dataresult.resultOrPartial(logger::error).ifPresent((nbtbase) -> {
nbt.put("Brain", nbtbase);
});
+ nbt.putBoolean("Purpur.ShouldBurnInDay", shouldBurnInDay); // Purpur
}
@Override
@@ -863,6 +865,11 @@ public abstract class LivingEntity extends Entity {
this.brain = this.makeBrain(new Dynamic(NbtOps.INSTANCE, nbt.get("Brain")));
}
+ // Purpur start
+ if (nbt.contains("Purpur.ShouldBurnInDay")) {
+ shouldBurnInDay = nbt.getBoolean("Purpur.ShouldBurnInDay");
+ }
+ // Purpur end
}
// CraftBukkit start
@@ -3482,6 +3489,27 @@ public abstract class LivingEntity extends Entity {
this.hurt(DamageSource.DROWN, 1.0F);
}
+ // Purpur start - copied from Zombie
+ if (this.isAlive()) {
+ boolean flag = this.shouldBurnInDay() && this.isSunBurnTick();
+ if (flag) {
+ ItemStack itemstack = this.getItemBySlot(EquipmentSlot.HEAD);
+ if (!itemstack.isEmpty()) {
+ if (itemstack.isDamageableItem()) {
+ itemstack.setDamageValue(itemstack.getDamageValue() + this.random.nextInt(2));
+ if (itemstack.getDamageValue() >= itemstack.getMaxDamage()) {
+ this.broadcastBreakEvent(EquipmentSlot.HEAD);
+ this.setItemSlot(EquipmentSlot.HEAD, ItemStack.EMPTY);
+ }
+ }
+ flag = false;
+ }
+ if (flag) {
+ this.setSecondsOnFire(8);
+ }
+ }
+ }
+ // Purpur end
}
public boolean isSensitiveToWater() {
diff --git a/src/main/java/net/minecraft/world/entity/Mob.java b/src/main/java/net/minecraft/world/entity/Mob.java
index 5a83abf504ca785a15d3ae0142a88e08a991e204..9ae5053c9c6591bdd8349e434ef505e64048b881 100644
--- a/src/main/java/net/minecraft/world/entity/Mob.java
+++ b/src/main/java/net/minecraft/world/entity/Mob.java
@@ -1685,17 +1685,7 @@ public abstract class Mob extends LivingEntity {
}
public boolean isSunBurnTick() {
- if (this.level.isDay() && !this.level.isClientSide) {
- float f = this.getLightLevelDependentMagicValue();
- BlockPos blockposition = new BlockPos(this.getX(), this.getEyeY(), this.getZ());
- boolean flag = this.isInWaterRainOrBubble() || this.isInPowderSnow || this.wasInPowderSnow;
-
- if (f > 0.5F && this.random.nextFloat() * 30.0F < (f - 0.4F) * 2.0F && !flag && this.level.canSeeSky(blockposition)) {
- return true;
- }
- }
-
- return false;
+ return super.isSunBurnTick(); // Purpur - moved contents to Entity
}
@Override
diff --git a/src/main/java/net/minecraft/world/entity/monster/AbstractSkeleton.java b/src/main/java/net/minecraft/world/entity/monster/AbstractSkeleton.java
index 8cc4f6a4e8ef66c4e799a0e5bdb4ddc5466007e6..4505b61f10c3aad3d0ab144cea5ef6efc6ad7357 100644
--- a/src/main/java/net/minecraft/world/entity/monster/AbstractSkeleton.java
+++ b/src/main/java/net/minecraft/world/entity/monster/AbstractSkeleton.java
@@ -65,6 +65,7 @@ public abstract class AbstractSkeleton extends Monster implements RangedAttackMo
protected AbstractSkeleton(EntityType<? extends AbstractSkeleton> type, Level world) {
super(type, world);
this.reassessWeaponGoal();
+ this.setShouldBurnInDay(true); // Purpur
}
@Override
@@ -100,35 +101,14 @@ public abstract class AbstractSkeleton extends Monster implements RangedAttackMo
}
// Paper start
- private boolean shouldBurnInDay = true;
+ // private boolean shouldBurnInDay = true; // Purpur - moved to LivingEntity - keep methods for ABI compatibility
public boolean shouldBurnInDay() { return shouldBurnInDay; }
public void setShouldBurnInDay(boolean shouldBurnInDay) { this.shouldBurnInDay = shouldBurnInDay; }
// Paper end
@Override
public void aiStep() {
- boolean flag = shouldBurnInDay && this.isSunBurnTick(); // Paper - Configurable Burning
-
- if (flag) {
- ItemStack itemstack = this.getItemBySlot(EquipmentSlot.HEAD);
-
- if (!itemstack.isEmpty()) {
- if (itemstack.isDamageableItem()) {
- itemstack.setDamageValue(itemstack.getDamageValue() + this.random.nextInt(2));
- if (itemstack.getDamageValue() >= itemstack.getMaxDamage()) {
- this.broadcastBreakEvent(EquipmentSlot.HEAD);
- this.setItemSlot(EquipmentSlot.HEAD, ItemStack.EMPTY);
- }
- }
-
- flag = false;
- }
-
- if (flag) {
- this.setSecondsOnFire(8);
- }
- }
-
+ // Purpur start - implemented in LivingEntity
super.aiStep();
}
@@ -191,7 +171,6 @@ public abstract class AbstractSkeleton extends Monster implements RangedAttackMo
} else {
this.goalSelector.addGoal(4, this.meleeGoal);
}
-
}
}
@@ -235,7 +214,7 @@ public abstract class AbstractSkeleton extends Monster implements RangedAttackMo
this.reassessWeaponGoal();
// Paper start
if (nbt.contains("Paper.ShouldBurnInDay")) {
- this.shouldBurnInDay = nbt.getBoolean("Paper.ShouldBurnInDay");
+ // this.shouldBurnInDay = nbt.getBoolean("Paper.ShouldBurnInDay"); // Purpur - implemented in LivingEntity
}
// Paper end
}
@@ -244,7 +223,7 @@ public abstract class AbstractSkeleton extends Monster implements RangedAttackMo
@Override
public void addAdditionalSaveData(CompoundTag nbt) {
super.addAdditionalSaveData(nbt);
- nbt.putBoolean("Paper.ShouldBurnInDay", this.shouldBurnInDay);
+ // nbt.putBoolean("Paper.ShouldBurnInDay", this.shouldBurnInDay); // Purpur - implemented in LivingEntity
}
// Paper end
diff --git a/src/main/java/net/minecraft/world/entity/monster/Husk.java b/src/main/java/net/minecraft/world/entity/monster/Husk.java
index 47e4f62d177c14ceffeb13a3fee5bfa342da7184..bcbce83f9e304809fb946f80c9dd32c4a17a7afb 100644
--- a/src/main/java/net/minecraft/world/entity/monster/Husk.java
+++ b/src/main/java/net/minecraft/world/entity/monster/Husk.java
@@ -20,6 +20,7 @@ public class Husk extends Zombie {
public Husk(EntityType<? extends Husk> type, Level world) {
super(type, world);
+ this.setShouldBurnInDay(false); // Purpur
}
// Purpur start
@@ -75,7 +76,7 @@ public class Husk extends Zombie {
@Override
public boolean isSunSensitive() {
- return false;
+ return this.shouldBurnInDay; // Purpur - moved to LivingEntity - keep methods for ABI compatibility
}
@Override
diff --git a/src/main/java/net/minecraft/world/entity/monster/Phantom.java b/src/main/java/net/minecraft/world/entity/monster/Phantom.java
index f7689ba01ec6d7f3483be831026e0c5f995459e9..836ca1a47524088c78c6c72a9479c7ffabfbee10 100644
--- a/src/main/java/net/minecraft/world/entity/monster/Phantom.java
+++ b/src/main/java/net/minecraft/world/entity/monster/Phantom.java
@@ -60,6 +60,7 @@ public class Phantom extends FlyingMob implements Enemy {
this.xpReward = 5;
this.moveControl = new Phantom.PhantomMoveControl(this);
this.lookControl = new Phantom.PhantomLookControl(this);
+ this.setShouldBurnInDay(true); // Purpur
}
// Purpur start
@@ -254,15 +255,7 @@ public class Phantom extends FlyingMob implements Enemy {
@Override
public void aiStep() {
- // Purpur start
- boolean burnFromDaylight = this.shouldBurnInDay && this.level.purpurConfig.phantomBurnInDaylight;
- boolean burnFromLightSource = this.level.purpurConfig.phantomBurnInLight > 0 && this.level.getMaxLocalRawBrightness(blockPosition()) >= this.level.purpurConfig.phantomBurnInLight;
- if (this.isAlive() && (burnFromDaylight || burnFromLightSource)) { // Paper - Configurable Burning
- if (getRider() == null || !this.isControllable())
- // Purpur end
- this.setSecondsOnFire(8);
- }
-
+ // Purpur - moved down to shouldBurnInDay()
super.aiStep();
}
@@ -290,7 +283,7 @@ public class Phantom extends FlyingMob implements Enemy {
if (nbt.hasUUID("Paper.SpawningEntity")) {
this.spawningEntity = nbt.getUUID("Paper.SpawningEntity");
}
- if (nbt.contains("Paper.ShouldBurnInDay")) {
+ if (false && nbt.contains("Paper.ShouldBurnInDay")) { // Purpur - implemented in LivingEntity
this.shouldBurnInDay = nbt.getBoolean("Paper.ShouldBurnInDay");
}
// Paper end
@@ -307,7 +300,7 @@ public class Phantom extends FlyingMob implements Enemy {
if (this.spawningEntity != null) {
nbt.putUUID("Paper.SpawningEntity", this.spawningEntity);
}
- nbt.putBoolean("Paper.ShouldBurnInDay", shouldBurnInDay);
+ // nbt.putBoolean("Paper.ShouldBurnInDay", shouldBurnInDay); // Purpur - implemented in LivingEntity
// Paper end
}
@@ -368,8 +361,14 @@ public class Phantom extends FlyingMob implements Enemy {
}
public void setSpawningEntity(java.util.UUID entity) { this.spawningEntity = entity; }
- private boolean shouldBurnInDay = true;
- public boolean shouldBurnInDay() { return shouldBurnInDay; }
+ // private boolean shouldBurnInDay = true; // Purpur - moved to LivingEntity - keep methods for ABI compatibility
+ // Purpur start
+ public boolean shouldBurnInDay() {
+ boolean burnFromDaylight = this.shouldBurnInDay && this.level.purpurConfig.phantomBurnInDaylight;
+ boolean burnFromLightSource = this.level.purpurConfig.phantomBurnInLight > 0 && this.level.getMaxLocalRawBrightness(blockPosition()) >= this.level.purpurConfig.phantomBurnInLight;
+ return burnFromDaylight || burnFromLightSource;
+ }
+ // Purpur End
public void setShouldBurnInDay(boolean shouldBurnInDay) { this.shouldBurnInDay = shouldBurnInDay; }
// Paper end
private static enum AttackPhase {
diff --git a/src/main/java/net/minecraft/world/entity/monster/Zombie.java b/src/main/java/net/minecraft/world/entity/monster/Zombie.java
index cfecf0322ea22b42fa83bafe3cd2f5d74f0d1311..da2f736bd162a1e2e39473a963ef20bcbb31aa2a 100644
--- a/src/main/java/net/minecraft/world/entity/monster/Zombie.java
+++ b/src/main/java/net/minecraft/world/entity/monster/Zombie.java
@@ -94,11 +94,12 @@ public class Zombie extends Monster {
private int inWaterTime;
public int conversionTime;
private int lastTick = MinecraftServer.currentTick; // CraftBukkit - add field
- private boolean shouldBurnInDay = true; // Paper
+ // private boolean shouldBurnInDay = true; // Paper // Purpur - implemented in LivingEntity
public Zombie(EntityType<? extends Zombie> type, Level world) {
super(type, world);
this.breakDoorGoal = new BreakDoorGoal(this, com.google.common.base.Predicates.in(world.paperConfig().entities.behavior.doorBreakingDifficulty.getOrDefault(type, world.paperConfig().entities.behavior.doorBreakingDifficulty.get(EntityType.ZOMBIE)))); // Paper
+ this.setShouldBurnInDay(true); // Purpur
}
public Zombie(Level world) {
@@ -295,30 +296,7 @@ public class Zombie extends Monster {
@Override
public void aiStep() {
- if (this.isAlive()) {
- boolean flag = this.isSunSensitive() && this.isSunBurnTick();
-
- if (flag) {
- ItemStack itemstack = this.getItemBySlot(EquipmentSlot.HEAD);
-
- if (!itemstack.isEmpty()) {
- if (itemstack.isDamageableItem()) {
- itemstack.setDamageValue(itemstack.getDamageValue() + this.random.nextInt(2));
- if (itemstack.getDamageValue() >= itemstack.getMaxDamage()) {
- this.broadcastBreakEvent(EquipmentSlot.HEAD);
- this.setItemSlot(EquipmentSlot.HEAD, ItemStack.EMPTY);
- }
- }
-
- flag = false;
- }
-
- if (flag) {
- this.setSecondsOnFire(8);
- }
- }
- }
-
+ // Purpur - implemented in LivingEntity
super.aiStep();
}
@@ -356,6 +334,7 @@ public class Zombie extends Monster {
}
+ public boolean shouldBurnInDay() { return isSunSensitive(); } // Purpur - for ABI compatibility
public boolean isSunSensitive() {
return this.shouldBurnInDay; // Paper - use api value instead
}
@@ -485,7 +464,7 @@ public class Zombie extends Monster {
nbt.putBoolean("CanBreakDoors", this.canBreakDoors());
nbt.putInt("InWaterTime", this.isInWater() ? this.inWaterTime : -1);
nbt.putInt("DrownedConversionTime", this.isUnderWaterConverting() ? this.conversionTime : -1);
- nbt.putBoolean("Paper.ShouldBurnInDay", this.shouldBurnInDay); // Paper
+ // nbt.putBoolean("Paper.ShouldBurnInDay", this.shouldBurnInDay); // Paper // Purpur - implemented in LivingEntity
}
@Override
@@ -499,7 +478,7 @@ public class Zombie extends Monster {
}
// Paper start
if (nbt.contains("Paper.ShouldBurnInDay")) {
- this.shouldBurnInDay = nbt.getBoolean("Paper.ShouldBurnInDay");
+ // this.shouldBurnInDay = nbt.getBoolean("Paper.ShouldBurnInDay"); // Purpur - implemented in LivingEntity
}
// Paper end
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
index 7bca861c3ebfc7550b82ae74483464b11f8d6b55..b6e0d832a5685fd6105c5307015d58a2d7900221 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
@@ -205,6 +205,11 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
this.entity = entity;
}
+ @Override
+ public boolean isInDaylight() {
+ return getHandle().isSunBurnTick();
+ }
+
public static CraftEntity getEntity(CraftServer server, Entity entity) {
/*
* Order is *EXTREMELY* important -- keep it right! =D
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
index b211a2398aefe30ce1f344df11585ce78dcfc390..9076717d7c517b9cb349bcf044b5bfa355267585 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
@@ -995,5 +995,15 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
if (slot == null) return;
getHandle().broadcastBreakEvent(org.bukkit.craftbukkit.CraftEquipmentSlot.getNMS(slot));
}
+
+ @Override
+ public boolean shouldBurnInDay() {
+ return getHandle().shouldBurnInDay();
+ }
+
+ @Override
+ public void setShouldBurnInDay(boolean shouldBurnInDay) {
+ getHandle().setShouldBurnInDay(shouldBurnInDay);
+ }
// Purpur end
}