mirror of
https://github.com/PurpurMC/Purpur.git
synced 2026-02-18 00:47:42 +01:00
Upstream has released updates that appear to apply and compile correctly Paper Changes: PaperMC/Paper@31699ae Updated Upstream (Bukkit/CraftBukkit) (#10242)
392 lines
18 KiB
Diff
392 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 7579c2d4c716695ab1854a055bc595d7b55201e5..f8f311e0e4715a8d648d743c0b5a664b7f004efe 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/Entity.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
|
|
@@ -561,6 +561,21 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
|
|
return true;
|
|
}
|
|
|
|
+ // Purpur start - copied from Mob
|
|
+ public boolean isSunBurnTick() {
|
|
+ if (this.level().isDay() && !this.level().isClientSide) {
|
|
+ float f = this.getLightLevelDependentMagicValue();
|
|
+ BlockPos blockposition = BlockPos.containing(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;
|
|
+ }
|
|
+
|
|
public final boolean hardCollides() {
|
|
return this.hardCollides;
|
|
}
|
|
diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
|
index e997844c0cead8eef82a8025283d43163b1a6848..1ebc5cfac7e7e47e1e9c10a90d707a4fa799ca43 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
|
@@ -262,6 +262,7 @@ public abstract class LivingEntity extends Entity implements Attackable {
|
|
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
|
|
public net.kyori.adventure.util.TriState frictionState = net.kyori.adventure.util.TriState.NOT_SET; // Paper - Friction API
|
|
+ protected boolean shouldBurnInDay = false; public boolean shouldBurnInDay() { return this.shouldBurnInDay; } public void setShouldBurnInDay(boolean shouldBurnInDay) { this.shouldBurnInDay = shouldBurnInDay; } // Purpur
|
|
|
|
@Override
|
|
public float getBukkitYaw() {
|
|
@@ -803,6 +804,7 @@ public abstract class LivingEntity extends Entity implements Attackable {
|
|
dataresult.resultOrPartial(logger::error).ifPresent((nbtbase) -> {
|
|
nbt.put("Brain", nbtbase);
|
|
});
|
|
+ nbt.putBoolean("Purpur.ShouldBurnInDay", shouldBurnInDay); // Purpur
|
|
}
|
|
|
|
@Override
|
|
@@ -889,6 +891,11 @@ public abstract class LivingEntity extends Entity implements Attackable {
|
|
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
|
|
@@ -3599,6 +3606,27 @@ public abstract class LivingEntity extends Entity implements Attackable {
|
|
this.hurt(this.damageSources().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 c5cf5e84893f137ee4bead287e80eb57ff1a7407..8588f230724e7fec2093b0b5c8c80b3d1944ce47 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/Mob.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/Mob.java
|
|
@@ -1765,17 +1765,7 @@ public abstract class Mob extends LivingEntity implements Targeting {
|
|
}
|
|
|
|
public boolean isSunBurnTick() {
|
|
- if (this.level().isDay() && !this.level().isClientSide) {
|
|
- float f = this.getLightLevelDependentMagicValue();
|
|
- BlockPos blockposition = BlockPos.containing(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();
|
|
}
|
|
|
|
@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 9d259d7e2aa3e44e350eb5927314cfceaffaf3f3..3f9e81c0bdd85bec24a1209ad3fd3dc43d988a4f 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/monster/AbstractSkeleton.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/monster/AbstractSkeleton.java
|
|
@@ -66,6 +66,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
|
|
@@ -101,35 +102,14 @@ public abstract class AbstractSkeleton extends Monster implements RangedAttackMo
|
|
}
|
|
|
|
// Paper start - shouldBurnInDay API
|
|
- 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 - shouldBurnInDay API
|
|
|
|
@Override
|
|
public void aiStep() {
|
|
- boolean flag = shouldBurnInDay && this.isSunBurnTick(); // Paper - shouldBurnInDay API
|
|
-
|
|
- 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();
|
|
}
|
|
|
|
@@ -194,7 +174,6 @@ public abstract class AbstractSkeleton extends Monster implements RangedAttackMo
|
|
} else {
|
|
this.goalSelector.addGoal(4, this.meleeGoal);
|
|
}
|
|
-
|
|
}
|
|
}
|
|
|
|
@@ -238,7 +217,7 @@ public abstract class AbstractSkeleton extends Monster implements RangedAttackMo
|
|
this.reassessWeaponGoal();
|
|
// Paper start - shouldBurnInDay API
|
|
if (nbt.contains("Paper.ShouldBurnInDay")) {
|
|
- this.shouldBurnInDay = nbt.getBoolean("Paper.ShouldBurnInDay");
|
|
+ // this.shouldBurnInDay = nbt.getBoolean("Paper.ShouldBurnInDay"); // Purpur - implemented in LivingEntity
|
|
}
|
|
// Paper end - shouldBurnInDay API
|
|
}
|
|
@@ -247,7 +226,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 - shouldBurnInDay API
|
|
|
|
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 f6d6df27c2ca7a33ed3ca8e299725b6a5c4aafc3..5ac87650e357f3ac48e37713b9b0b18ad4d6feb6 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/monster/Husk.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/monster/Husk.java
|
|
@@ -22,6 +22,7 @@ public class Husk extends Zombie {
|
|
|
|
public Husk(EntityType<? extends Husk> type, Level world) {
|
|
super(type, world);
|
|
+ this.setShouldBurnInDay(false); // Purpur
|
|
}
|
|
|
|
// Purpur start
|
|
@@ -77,7 +78,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 637b229817f9f2c3ad224f300b56a6bee4c8a341..bcb1912ea218fbb4b849ab84a7025202100b82c3 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
|
|
@@ -254,16 +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 - shouldBurnInDay API
|
|
- if (getRider() == null || !this.isControllable())
|
|
- // Purpur end
|
|
- if (getRider() == null || !this.isControllable()) // Purpur
|
|
- this.setSecondsOnFire(8);
|
|
- }
|
|
-
|
|
+ // Purpur - moved down to shouldBurnInDay()
|
|
super.aiStep();
|
|
}
|
|
|
|
@@ -291,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
|
|
@@ -308,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
|
|
}
|
|
|
|
@@ -377,8 +369,15 @@ public class Phantom extends FlyingMob implements Enemy {
|
|
return spawningEntity;
|
|
}
|
|
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 94b92c6e588f871d4b0d86bb8f860a99e473a4ea..e568d014f577ab705645152446156dc04895b3bf 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 - Add more Zombie API
|
|
+ // private boolean shouldBurnInDay = true; // Paper - Add more Zombie API // 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 - Configurable door breaking difficulty
|
|
+ this.setShouldBurnInDay(true); // Purpur
|
|
}
|
|
|
|
public Zombie(Level world) {
|
|
@@ -296,30 +297,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();
|
|
}
|
|
|
|
@@ -357,6 +335,7 @@ public class Zombie extends Monster {
|
|
|
|
}
|
|
|
|
+ public boolean shouldBurnInDay() { return isSunSensitive(); } // Purpur - for ABI compatibility
|
|
public boolean isSunSensitive() {
|
|
return this.shouldBurnInDay; // Paper - Add more Zombie API
|
|
}
|
|
@@ -486,7 +465,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 - Add more Zombie API
|
|
+ // nbt.putBoolean("Paper.ShouldBurnInDay", this.shouldBurnInDay); // Paper - Add more Zombie API // Purpur - implemented in LivingEntity
|
|
}
|
|
|
|
@Override
|
|
@@ -500,7 +479,7 @@ public class Zombie extends Monster {
|
|
}
|
|
// Paper start - Add more Zombie API
|
|
if (nbt.contains("Paper.ShouldBurnInDay")) {
|
|
- this.shouldBurnInDay = nbt.getBoolean("Paper.ShouldBurnInDay");
|
|
+ // this.shouldBurnInDay = nbt.getBoolean("Paper.ShouldBurnInDay"); // Purpur - implemented in LivingEntity
|
|
}
|
|
// Paper end - Add more Zombie API
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
|
|
index a260e3768892dcf7ddd955cf8753d4d19cd2e8d3..9304a2d06400dfa244ddb4d9591de988b334c3cf 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
|
|
@@ -83,6 +83,11 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
|
|
this.entityType = CraftEntityType.minecraftToBukkit(entity.getType());
|
|
}
|
|
|
|
+ @Override
|
|
+ public boolean isInDaylight() {
|
|
+ return getHandle().isSunBurnTick();
|
|
+ }
|
|
+
|
|
public static <T extends Entity> CraftEntity getEntity(CraftServer server, T entity) {
|
|
Preconditions.checkArgument(entity != null, "Unknown entity");
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
|
|
index 1bcd9d9729952e68c56ff6e169ace11611b44e97..332c553db22aaeb0cda5e628c5e464e130c7abb0 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
|
|
@@ -1173,5 +1173,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
|
|
}
|