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

Paper Changes:
PaperMC/Paper@f7e3976 Revert "Legacy data should look for legacy materials (Fixes #6618)" (Fixes #6664)
PaperMC/Paper@ce1e7e8 Fix jline relocation (#6677)
PaperMC/Paper@3e8fb21 Suggest PlayerPostRespawnEvent if changing player state (#6679)
PaperMC/Paper@2b404b0 Fix nullability on Block#breakNaturally (#6651)
PaperMC/Paper@8ee9bdd Fix stacktrace deobf where thrownProxy got initialized before rewriting (#6684)
PaperMC/Paper@fce7905 Option to prevent NBT copy in smithing recipes (#6671)
PaperMC/Paper@3b2b835 Fix click event when vanilla scoreboard name coloring is enabled (#6652)
PaperMC/Paper@425edfa More CommandBlock API (#5746)
PaperMC/Paper@6847f57 Improve ItemStack#editMeta (#6502)
PaperMC/Paper@6703c13 Preserve overstacked loot (#5943)
PaperMC/Paper@0032236 Make Levels Use Correct Spawn Settings (#6419)
PaperMC/Paper@4a27a4a Update head rotation in missing places (#5481)
PaperMC/Paper@ebfd70b Use null for null resource pack prompts (#6572)
PaperMC/Paper@826acaf Fix plugin provides load order (#6687)
PaperMC/Paper@f905057 Prevent unintended light block manipulation (#6601)
PaperMC/Paper@45c4f90 Readd root/admin user detection (#6593)
PaperMC/Paper@e8830b2 Revert "Readd root/admin user detection (#6593)" (#6699)
PaperMC/Paper@cc38c16 Updated Upstream (Bukkit/CraftBukkit) (#6638)
PaperMC/Paper@7dd7c0c [ci skip] update issue template to remove checkboxes and add datapacks (#6702)
PaperMC/Paper@bde7b98 Make legacyRenderer a ViewerUnaware renderer (#6691)
PaperMC/Paper@e391591 Update paperweight to 1.1.12 (#6653)
PaperMC/Paper@e14aff9 Don't count named piglins and hoglins towards mob cap (#6452)
PaperMC/Paper@a978f41 Start console thread after PaperConfig & MinecraftServer.console are initialized (#6716)
PaperMC/Paper@b1f0cbd [ci skip] Remove redundant/broken readme badges (#6715)
PaperMC/Paper@e3ef498 [ci skip] remove markdown from issue template (#6705)
PaperMC/Paper@7ebf08a Handle missing Spawn Egg item meta for 1.17 mobs (#6700)
PaperMC/Paper@90f717f Add missing team sidebar display slots (#6690)
2021-10-04 15:11:25 -04:00

370 lines
17 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 2be6fb58d3abc731dbf0ff911cad022b8c78875d..12662cb04b247bd46b3e1fab060e1c17a56e84a3 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -4378,5 +4378,18 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, n
public boolean canSaveToDisk() {
return true;
}
+
+ // Purpur start - copied from Mob
+ public boolean isSunBurnTick() {
+ if (this.level.isDay()) {
+ float brightness = this.getBrightness();
+ BlockPos pos = new BlockPos(this.getX(), this.getEyeY(), this.getZ());
+ boolean flag = this.isInWaterRainOrBubble() || this.isInPowderSnow || this.wasInPowderSnow;
+ if (brightness > 0.5F && this.random.nextFloat() * 30.0F < (brightness - 0.4F) * 2.0F && !flag && this.level.canSeeSky(pos)) {
+ 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 e1308770c3510f54da40b2ff38d08186bac22518..214bc2bcbcb88a9a62d2151a62aaa57beadc7da0 100644
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
@@ -264,6 +264,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() {
@@ -768,6 +769,7 @@ public abstract class LivingEntity extends Entity {
dataresult.resultOrPartial(logger::error).ifPresent((nbtbase) -> {
nbt.put("Brain", nbtbase);
});
+ nbt.putBoolean("Purpur.ShouldBurnInDay", shouldBurnInDay); // Purpur
}
@Override
@@ -843,6 +845,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
@@ -3318,6 +3325,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 a52ea8628f70861a80c2d62301da1cbf478b477f..5e62ecb980199f8dba97703403ef811167a24ec5 100644
--- a/src/main/java/net/minecraft/world/entity/Mob.java
+++ b/src/main/java/net/minecraft/world/entity/Mob.java
@@ -1643,17 +1643,7 @@ public abstract class Mob extends LivingEntity {
}
public boolean isSunBurnTick() {
- if (this.level.isDay() && !this.level.isClientSide) {
- float f = this.getBrightness();
- 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 74f4f8e1c9faef3b50fa817ca3dfbb6b19b1622d..5b19d8db09867791782c899d41d314c511f6c8a2 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();
}
@@ -189,7 +169,6 @@ public abstract class AbstractSkeleton extends Monster implements RangedAttackMo
} else {
this.goalSelector.addGoal(4, this.meleeGoal);
}
-
}
}
@@ -233,7 +212,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
}
@@ -242,7 +221,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 7bb8ef0bb2de9a0b0d5048f8a4089835c41de568..3a643b0f614a875d6781e9e703e47b60254f8ad3 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
@@ -65,7 +66,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 26ef372ddeb707ad0962297ce736c245f713d9f2..516f0c11d32a6bc7e7b83c65d18b7c76d404bbeb 100644
--- a/src/main/java/net/minecraft/world/entity/monster/Phantom.java
+++ b/src/main/java/net/minecraft/world/entity/monster/Phantom.java
@@ -61,6 +61,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
@@ -232,7 +233,7 @@ public class Phantom extends FlyingMob implements Enemy {
@Override
public void aiStep() {
- if (this.isAlive() && getRider() == null && (((shouldBurnInDay || level.purpurConfig.phantomBurnInDaylight) && this.isSunBurnTick()) || (level.purpurConfig.phantomBurnInLight > 0 && level.getMaxLocalRawBrightness(blockPosition()) >= level.purpurConfig.phantomBurnInLight))) { // Paper - Configurable Burning // Purpur
+ if (this.isAlive() && getRider() == null && (((shouldBurnInDay() || level.purpurConfig.phantomBurnInDaylight) && this.isSunBurnTick()) || (level.purpurConfig.phantomBurnInLight > 0 && level.getMaxLocalRawBrightness(blockPosition()) >= level.purpurConfig.phantomBurnInLight))) { // Paper - Configurable Burning // Purpur
this.setSecondsOnFire(8);
}
@@ -264,7 +265,7 @@ public class Phantom extends FlyingMob implements Enemy {
this.spawningEntity = nbt.getUUID("Paper.SpawningEntity");
}
if (nbt.contains("Paper.ShouldBurnInDay")) {
- this.shouldBurnInDay = nbt.getBoolean("Paper.ShouldBurnInDay");
+ // this.shouldBurnInDay = nbt.getBoolean("Paper.ShouldBurnInDay"); // Purpur - implemented in LivingEntity
}
// Paper end
}
@@ -280,7 +281,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
}
@@ -341,7 +342,7 @@ public class Phantom extends FlyingMob implements Enemy {
}
public void setSpawningEntity(java.util.UUID entity) { this.spawningEntity = entity; }
- 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
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 9e4f6bf67301d62f431254a6863d7739e8c6b370..9716cf7d4e203905db252a4e3e82e8a9f8731f75 100644
--- a/src/main/java/net/minecraft/world/entity/monster/Zombie.java
+++ b/src/main/java/net/minecraft/world/entity/monster/Zombie.java
@@ -96,11 +96,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.zombieBreakDoors)); // Paper
+ this.setShouldBurnInDay(true); // Purpur
}
public Zombie(Level world) {
@@ -282,30 +283,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();
}
@@ -343,6 +321,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
}
@@ -472,7 +451,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
@@ -486,7 +465,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 5ae88a924b2f2cfd714bd693eebc708e7c029ee8..b75661886bafcfa340c5ac388401aa3c1cda78a9 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
@@ -1297,5 +1297,10 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
entity.absMoveTo(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
return !entity.valid && entity.level.addEntity(entity, spawnReason);
}
+
+ @Override
+ public boolean isInDaylight() {
+ return getHandle().isSunBurnTick();
+ }
// Purpur end
}
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
index 7a888d9c464f080297fa27e39837734a06b013a9..9ecf1ef7e876418d2b454d6cd8ac8739194acfaa 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
@@ -933,5 +933,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
}