mirror of
https://github.com/PurpurMC/Purpur.git
synced 2026-02-17 16:37:43 +01:00
391 lines
18 KiB
Diff
391 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 ab112953d312af47948b7d86b8574753410c1658..1aad0bed631b0a47a93de131136c90f8d567cb77 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/Entity.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
|
|
@@ -484,6 +484,21 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
|
|
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 513f58b00293134fade28a289afde71a69e9f447..6d7cb3e8f82cc6424db12fa9efbda6f2c7978228 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 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
|
|
+ protected boolean shouldBurnInDay = false; public boolean shouldBurnInDay() { return this.shouldBurnInDay; } public void setShouldBurnInDay(boolean shouldBurnInDay) { this.shouldBurnInDay = shouldBurnInDay; } // Purpur
|
|
|
|
@Override
|
|
public float getBukkitYaw() {
|
|
@@ -805,6 +806,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
|
|
@@ -3547,6 +3554,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 d24f94f2c27523af10184cae27157169d5deabae..7dae759b777cf9077bf46d2e1189c20c1c2db60e 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/Mob.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/Mob.java
|
|
@@ -1739,17 +1739,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 93443238b77c04f6a9da3c25427d200ccf4699f8..892ae3a9ac2395896ff7881c49eaece8d46e831e 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
|
|
- 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();
|
|
}
|
|
|
|
@@ -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
|
|
if (nbt.contains("Paper.ShouldBurnInDay")) {
|
|
- this.shouldBurnInDay = nbt.getBoolean("Paper.ShouldBurnInDay");
|
|
+ // this.shouldBurnInDay = nbt.getBoolean("Paper.ShouldBurnInDay"); // Purpur - implemented in LivingEntity
|
|
}
|
|
// Paper end
|
|
}
|
|
@@ -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
|
|
|
|
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 31706620960f5f153565f3cf64e32d0f4d10feb8..1df39e11d4fe3146fba9a0605c623384513311ac 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 7c9f6076f68de295e882e69137ac573db8d9698b..8605dfe152a09f31492226b1eb2a5eb39db9fcbc 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
|
|
@@ -253,16 +254,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
|
|
- if (getRider() == null || !this.isControllable()) // Purpur
|
|
- this.setSecondsOnFire(8);
|
|
- }
|
|
-
|
|
+ // Purpur - moved down to shouldBurnInDay()
|
|
super.aiStep();
|
|
}
|
|
|
|
@@ -290,7 +282,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 +299,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
|
|
}
|
|
|
|
@@ -373,8 +365,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 a676d66dcb5ee72e6d8ffef4e210a3d2c8d605f2..0bc90b6d5c5a3cb3477d41336a9bb1130ff32fa1 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/monster/Zombie.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/monster/Zombie.java
|
|
@@ -95,11 +95,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 3985663536d17afe73ece47702bdc41dcfd46819..41089892e735eec7e3914084bbc278d67c4b6ea0 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
|
|
@@ -209,6 +209,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 3ca4ba907b42dfddf24dbab56e4bdfbc8a60f72a..70830f57e3929bc37b20fd95fc4998c717e99706 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
|
|
@@ -1082,5 +1082,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
|
|
}
|