mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-23 11:06:29 +01:00
01a13871de
Patch documentation to come Issues with the old system that are fixed now: - World generation does not scale with cpu cores effectively. - Relies on the main thread for scheduling and maintaining chunk state, dropping chunk load/generate rates at lower tps. - Unreliable prioritisation of chunk gen/load calls that block the main thread. - Shutdown logic is utterly unreliable, as it has to wait for all chunks to unload - is it guaranteed that the chunk system is in a state on shutdown that it can reliably do this? Watchdog shutdown also typically failed due to thread checks, which is now resolved. - Saving of data is not unified (i.e can save chunk data without saving entity data, poses problems for desync if shutdown is really abnormal. - Entities are not loaded with chunks. This caused quite a bit of headache for Chunk#getEntities API, but now the new chunk system loads entities with chunks so that they are ready whenever the chunk loads in. Effectively brings the behavior back to 1.16 era, but still storing entities in their own separate regionfiles. The above list is not complete. The patch documentation will complete it. New chunk system hard relies on starlight and dataconverter, and most importantly the new concurrent utilities in ConcurrentUtil. Some of the old async chunk i/o interface (i.e the old file io thread reroutes _some_ calls to the new file io thread) is kept for plugin compat reasons. It will be removed in the next major version of minecraft. The old legacy chunk system patches have been moved to the removed folder in case we need them again.
168 lines
7.7 KiB
Diff
168 lines
7.7 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: BillyGalbreath <Blake.Galbreath@GMail.com>
|
|
Date: Fri, 24 Aug 2018 08:18:42 -0500
|
|
Subject: [PATCH] Slime Pathfinder Events
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/entity/monster/Slime.java b/src/main/java/net/minecraft/world/entity/monster/Slime.java
|
|
index 7b95d18fb5edbd1575f6be92bfcbb3e0d7f691c8..48feda682284321d18c846e4812909f0e7e649e3 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/monster/Slime.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/monster/Slime.java
|
|
@@ -41,6 +41,12 @@ import net.minecraft.world.level.ServerLevelAccessor;
|
|
import net.minecraft.world.level.WorldGenLevel;
|
|
import net.minecraft.world.level.levelgen.WorldgenRandom;
|
|
import net.minecraft.world.phys.Vec3;
|
|
+// Paper start
|
|
+import com.destroystokyo.paper.event.entity.SlimeChangeDirectionEvent;
|
|
+import com.destroystokyo.paper.event.entity.SlimeSwimEvent;
|
|
+import com.destroystokyo.paper.event.entity.SlimeTargetLivingEntityEvent;
|
|
+import com.destroystokyo.paper.event.entity.SlimeWanderEvent;
|
|
+// Paper end
|
|
// CraftBukkit start
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
@@ -106,6 +112,7 @@ public class Slime extends Mob implements Enemy {
|
|
@Override
|
|
public void addAdditionalSaveData(CompoundTag nbt) {
|
|
super.addAdditionalSaveData(nbt);
|
|
+ nbt.putBoolean("Paper.canWander", this.canWander); // Paper
|
|
nbt.putInt("Size", this.getSize() - 1);
|
|
nbt.putBoolean("wasOnGround", this.wasOnGround);
|
|
}
|
|
@@ -114,6 +121,11 @@ public class Slime extends Mob implements Enemy {
|
|
public void readAdditionalSaveData(CompoundTag nbt) {
|
|
this.setSize(nbt.getInt("Size") + 1, false);
|
|
super.readAdditionalSaveData(nbt);
|
|
+ // Paper start - check exists before loading or this will be loaded as false
|
|
+ if (nbt.contains("Paper.canWander")) {
|
|
+ this.canWander = nbt.getBoolean("Paper.canWander");
|
|
+ }
|
|
+ // Paper end
|
|
this.wasOnGround = nbt.getBoolean("wasOnGround");
|
|
}
|
|
|
|
@@ -448,7 +460,7 @@ public class Slime extends Mob implements Enemy {
|
|
|
|
@Override
|
|
public boolean canUse() {
|
|
- return (this.slime.isInWater() || this.slime.isInLava()) && this.slime.getMoveControl() instanceof Slime.SlimeMoveControl;
|
|
+ return (this.slime.isInWater() || this.slime.isInLava()) && this.slime.getMoveControl() instanceof Slime.SlimeMoveControl && this.slime.canWander && new SlimeSwimEvent((org.bukkit.entity.Slime) this.slime.getBukkitEntity()).callEvent(); // Paper
|
|
}
|
|
|
|
@Override
|
|
@@ -480,7 +492,15 @@ public class Slime extends Mob implements Enemy {
|
|
public boolean canUse() {
|
|
LivingEntity entityliving = this.slime.getTarget();
|
|
|
|
- return entityliving == null ? false : (!this.slime.canAttack(entityliving) ? false : this.slime.getMoveControl() instanceof Slime.SlimeMoveControl);
|
|
+ // Paper start
|
|
+ if (entityliving == null || !entityliving.isAlive()) {
|
|
+ return false;
|
|
+ }
|
|
+ if (!this.slime.canAttack(entityliving)) {
|
|
+ return false;
|
|
+ }
|
|
+ return this.slime.getMoveControl() instanceof Slime.SlimeMoveControl && this.slime.canWander && new SlimeTargetLivingEntityEvent((org.bukkit.entity.Slime) this.slime.getBukkitEntity(), (org.bukkit.entity.LivingEntity) entityliving.getBukkitEntity()).callEvent();
|
|
+ // Paper end
|
|
}
|
|
|
|
@Override
|
|
@@ -493,7 +513,15 @@ public class Slime extends Mob implements Enemy {
|
|
public boolean canContinueToUse() {
|
|
LivingEntity entityliving = this.slime.getTarget();
|
|
|
|
- return entityliving == null ? false : (!this.slime.canAttack(entityliving) ? false : --this.growTiredTimer > 0);
|
|
+ // Paper start
|
|
+ if (entityliving == null || !entityliving.isAlive()) {
|
|
+ return false;
|
|
+ }
|
|
+ if (!this.slime.canAttack(entityliving)) {
|
|
+ return false;
|
|
+ }
|
|
+ return --this.growTiredTimer > 0 && this.slime.canWander && new SlimeTargetLivingEntityEvent((org.bukkit.entity.Slime) this.slime.getBukkitEntity(), (org.bukkit.entity.LivingEntity) entityliving.getBukkitEntity()).callEvent();
|
|
+ // Paper end
|
|
}
|
|
|
|
@Override
|
|
@@ -511,6 +539,13 @@ public class Slime extends Mob implements Enemy {
|
|
|
|
((Slime.SlimeMoveControl) this.slime.getMoveControl()).setDirection(this.slime.getYRot(), this.slime.isDealsDamage());
|
|
}
|
|
+
|
|
+ // Paper start - clear timer and target when goal resets
|
|
+ public void stop() {
|
|
+ this.growTiredTimer = 0;
|
|
+ this.slime.setTarget(null);
|
|
+ }
|
|
+ // Paper end
|
|
}
|
|
|
|
private static class SlimeRandomDirectionGoal extends Goal {
|
|
@@ -526,7 +561,7 @@ public class Slime extends Mob implements Enemy {
|
|
|
|
@Override
|
|
public boolean canUse() {
|
|
- return this.slime.getTarget() == null && (this.slime.onGround || this.slime.isInWater() || this.slime.isInLava() || this.slime.hasEffect(MobEffects.LEVITATION)) && this.slime.getMoveControl() instanceof Slime.SlimeMoveControl;
|
|
+ return this.slime.getTarget() == null && (this.slime.onGround || this.slime.isInWater() || this.slime.isInLava() || this.slime.hasEffect(MobEffects.LEVITATION)) && this.slime.getMoveControl() instanceof Slime.SlimeMoveControl && this.slime.canWander; // Paper - add canWander
|
|
}
|
|
|
|
@Override
|
|
@@ -534,6 +569,11 @@ public class Slime extends Mob implements Enemy {
|
|
if (--this.nextRandomizeTime <= 0) {
|
|
this.nextRandomizeTime = this.adjustedTickDelay(40 + this.slime.getRandom().nextInt(60));
|
|
this.chosenDegrees = (float) this.slime.getRandom().nextInt(360);
|
|
+ // Paper start
|
|
+ SlimeChangeDirectionEvent event = new SlimeChangeDirectionEvent((org.bukkit.entity.Slime) this.slime.getBukkitEntity(), this.chosenDegrees);
|
|
+ if (!this.slime.canWander || !event.callEvent()) return;
|
|
+ this.chosenDegrees = event.getNewYaw();
|
|
+ // Paper end
|
|
}
|
|
|
|
((Slime.SlimeMoveControl) this.slime.getMoveControl()).setDirection(this.chosenDegrees, false);
|
|
@@ -551,7 +591,7 @@ public class Slime extends Mob implements Enemy {
|
|
|
|
@Override
|
|
public boolean canUse() {
|
|
- return !this.slime.isPassenger();
|
|
+ return !this.slime.isPassenger() && this.slime.canWander && new SlimeWanderEvent((org.bukkit.entity.Slime) this.slime.getBukkitEntity()).callEvent(); // Paper
|
|
}
|
|
|
|
@Override
|
|
@@ -559,4 +599,15 @@ public class Slime extends Mob implements Enemy {
|
|
((Slime.SlimeMoveControl) this.slime.getMoveControl()).setWantedMovement(1.0D);
|
|
}
|
|
}
|
|
+
|
|
+ // Paper start
|
|
+ private boolean canWander = true;
|
|
+ public boolean canWander() {
|
|
+ return canWander;
|
|
+ }
|
|
+
|
|
+ public void setWander(boolean canWander) {
|
|
+ this.canWander = canWander;
|
|
+ }
|
|
+ // Paper end
|
|
}
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftSlime.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftSlime.java
|
|
index 67fc37f909639e1effe6034526990f10d575d14d..4d401403de2399919043651345eed91c11ac986f 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftSlime.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftSlime.java
|
|
@@ -34,4 +34,16 @@ public class CraftSlime extends CraftMob implements Slime {
|
|
public EntityType getType() {
|
|
return EntityType.SLIME;
|
|
}
|
|
+
|
|
+ // Paper start
|
|
+ @Override
|
|
+ public boolean canWander() {
|
|
+ return getHandle().canWander();
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void setWander(boolean canWander) {
|
|
+ getHandle().setWander(canWander);
|
|
+ }
|
|
+ // Paper end
|
|
}
|