Paper/patches/server/0644-Only-set-despawnTimer-for-Wandering-Traders-spawned-.patch

59 lines
4.4 KiB
Diff
Raw Normal View History

2021-06-11 14:02:28 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2021-06-17 11:37:24 +02:00
From: Jason Penilla <11360596+jpenilla@users.noreply.github.com>
2021-06-11 14:02:28 +02:00
Date: Fri, 19 Mar 2021 16:07:21 -0700
Subject: [PATCH] Only set despawnTimer for Wandering Traders spawned by
MobSpawnerTrader
diff --git a/src/main/java/net/minecraft/world/entity/EntityType.java b/src/main/java/net/minecraft/world/entity/EntityType.java
2021-06-17 22:20:03 +02:00
index f38ccdecbade43983358dfbeadca86be7d15a68c..b50bf044a3cb05b811fd06796a351e6b15b352ad 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/world/entity/EntityType.java
+++ b/src/main/java/net/minecraft/world/entity/EntityType.java
2021-06-17 22:20:03 +02:00
@@ -332,6 +332,12 @@ public class EntityType<T extends Entity> implements EntityTypeTest<Entity, T> {
2021-06-11 14:02:28 +02:00
@Nullable
public T spawnCreature(ServerLevel worldserver, @Nullable CompoundTag nbttagcompound, @Nullable Component ichatbasecomponent, @Nullable Player entityhuman, BlockPos blockposition, MobSpawnType enummobspawn, boolean flag, boolean flag1, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason spawnReason) {
+ // Paper start - add consumer to modify entity before spawn
+ return this.spawnCreature(worldserver, nbttagcompound, ichatbasecomponent, entityhuman, blockposition, enummobspawn, flag, flag1, spawnReason, null);
+ }
+ @Nullable
+ public T spawnCreature(ServerLevel worldserver, @Nullable CompoundTag nbttagcompound, @Nullable Component ichatbasecomponent, @Nullable Player entityhuman, BlockPos blockposition, MobSpawnType enummobspawn, boolean flag, boolean flag1, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason spawnReason, @Nullable java.util.function.Consumer<T> op) {
+ // Paper end
// Paper start - Call PreCreatureSpawnEvent
org.bukkit.entity.EntityType type = org.bukkit.entity.EntityType.fromName(EntityType.getKey(this).getPath());
if (type != null) {
2021-06-17 22:20:03 +02:00
@@ -347,6 +353,7 @@ public class EntityType<T extends Entity> implements EntityTypeTest<Entity, T> {
2021-06-11 14:02:28 +02:00
}
// Paper end
T t0 = this.create(worldserver, nbttagcompound, ichatbasecomponent, entityhuman, blockposition, enummobspawn, flag, flag1);
+ if (t0 != null && op != null) op.accept(t0); // Paper
if (t0 != null) {
worldserver.addAllEntities(t0, spawnReason);
diff --git a/src/main/java/net/minecraft/world/entity/npc/WanderingTrader.java b/src/main/java/net/minecraft/world/entity/npc/WanderingTrader.java
2021-06-15 04:59:31 +02:00
index 59c4ab697ef0a336ffce19d215952f3a8ff0852b..9f9b48546fd1ae23a04cad060b6996e21354efbb 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/world/entity/npc/WanderingTrader.java
+++ b/src/main/java/net/minecraft/world/entity/npc/WanderingTrader.java
2021-06-15 04:59:31 +02:00
@@ -60,7 +60,7 @@ public class WanderingTrader extends net.minecraft.world.entity.npc.AbstractVill
2021-06-11 14:02:28 +02:00
public WanderingTrader(EntityType<? extends WanderingTrader> type, Level world) {
super(type, world);
- this.setDespawnDelay(48000); // CraftBukkit - set default from MobSpawnerTrader
+ //this.setDespawnDelay(48000); // CraftBukkit - set default from MobSpawnerTrader // Paper - move back to MobSpawnerTrader - Vanilla behavior is that only traders spawned by it have this value set.
}
@Override
diff --git a/src/main/java/net/minecraft/world/entity/npc/WanderingTraderSpawner.java b/src/main/java/net/minecraft/world/entity/npc/WanderingTraderSpawner.java
2021-06-15 04:59:31 +02:00
index 60f08ecd0034e8ef2965b54b3abccce582d0ca54..f8ede3588bfda9a7d4d5807311a3e9c2651fd0a3 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/world/entity/npc/WanderingTraderSpawner.java
+++ b/src/main/java/net/minecraft/world/entity/npc/WanderingTraderSpawner.java
2021-06-15 04:59:31 +02:00
@@ -121,7 +121,7 @@ public class WanderingTraderSpawner implements CustomSpawner {
2021-06-11 14:02:28 +02:00
return false;
}
2021-06-15 04:59:31 +02:00
- WanderingTrader entityvillagertrader = (WanderingTrader) EntityType.WANDERING_TRADER.spawnCreature(world, (CompoundTag) null, (Component) null, (Player) null, blockposition2, MobSpawnType.EVENT, false, false, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.NATURAL); // CraftBukkit
+ WanderingTrader entityvillagertrader = EntityType.WANDERING_TRADER.spawnCreature(world, null, null, null, blockposition2, MobSpawnType.EVENT, false, false, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.NATURAL, trader -> trader.setDespawnDelay(48000)); // CraftBukkit // Paper - set despawnTimer before spawn events called
2021-06-11 14:02:28 +02:00
if (entityvillagertrader != null) {
for (int i = 0; i < 2; ++i) {