aboutsummaryrefslogtreecommitdiffhomepage
path: root/patch-remap/mache-vineflower/net/minecraft/world/level/BaseSpawner.java.patch
diff options
context:
space:
mode:
Diffstat (limited to 'patch-remap/mache-vineflower/net/minecraft/world/level/BaseSpawner.java.patch')
-rw-r--r--patch-remap/mache-vineflower/net/minecraft/world/level/BaseSpawner.java.patch354
1 files changed, 354 insertions, 0 deletions
diff --git a/patch-remap/mache-vineflower/net/minecraft/world/level/BaseSpawner.java.patch b/patch-remap/mache-vineflower/net/minecraft/world/level/BaseSpawner.java.patch
new file mode 100644
index 0000000000..355c04a40d
--- /dev/null
+++ b/patch-remap/mache-vineflower/net/minecraft/world/level/BaseSpawner.java.patch
@@ -0,0 +1,354 @@
+--- a/net/minecraft/world/level/BaseSpawner.java
++++ b/net/minecraft/world/level/BaseSpawner.java
+@@ -10,6 +10,7 @@
+ import net.minecraft.nbt.CompoundTag;
+ import net.minecraft.nbt.ListTag;
+ import net.minecraft.nbt.NbtOps;
++import net.minecraft.nbt.Tag;
+ import net.minecraft.server.level.ServerLevel;
+ import net.minecraft.util.RandomSource;
+ import net.minecraft.util.random.SimpleWeightedRandomList;
+@@ -18,8 +19,9 @@
+ import net.minecraft.world.entity.Entity;
+ import net.minecraft.world.entity.EntitySelector;
+ import net.minecraft.world.entity.EntityType;
++import net.minecraft.world.entity.EnumMobSpawn;
++import net.minecraft.world.entity.GroupDataEntity;
+ import net.minecraft.world.entity.Mob;
+-import net.minecraft.world.entity.MobSpawnType;
+ import net.minecraft.world.entity.SpawnPlacements;
+ import net.minecraft.world.level.entity.EntityTypeTest;
+ import net.minecraft.world.level.gameevent.GameEvent;
+@@ -27,49 +29,55 @@
+ import org.slf4j.Logger;
+
+ public abstract class BaseSpawner {
++
+ public static final String SPAWN_DATA_TAG = "SpawnData";
+ private static final Logger LOGGER = LogUtils.getLogger();
+ private static final int EVENT_SPAWN = 1;
+- private int spawnDelay = 20;
+- private SimpleWeightedRandomList<SpawnData> spawnPotentials = SimpleWeightedRandomList.empty();
++ public int spawnDelay = 20;
++ public SimpleWeightedRandomList<SpawnData> spawnPotentials = SimpleWeightedRandomList.empty();
+ @Nullable
+- private SpawnData nextSpawnData;
++ public SpawnData nextSpawnData;
+ private double spin;
+ private double oSpin;
+- private int minSpawnDelay = 200;
+- private int maxSpawnDelay = 800;
+- private int spawnCount = 4;
++ public int minSpawnDelay = 200;
++ public int maxSpawnDelay = 800;
++ public int spawnCount = 4;
+ @Nullable
+ private Entity displayEntity;
+- private int maxNearbyEntities = 6;
+- private int requiredPlayerRange = 16;
+- private int spawnRange = 4;
++ public int maxNearbyEntities = 6;
++ public int requiredPlayerRange = 16;
++ public int spawnRange = 4;
+
++ public BaseSpawner() {}
++
+ public void setEntityId(EntityType<?> type, @Nullable Level level, RandomSource random, BlockPos pos) {
+ this.getOrCreateNextSpawnData(level, random, pos).getEntityToSpawn().putString("id", BuiltInRegistries.ENTITY_TYPE.getKey(type).toString());
++ this.spawnPotentials = SimpleWeightedRandomList.empty(); // CraftBukkit - SPIGOT-3496, MC-92282
+ }
+
+ private boolean isNearPlayer(Level level, BlockPos pos) {
+- return level.hasNearbyAlivePlayer((double)pos.getX() + 0.5, (double)pos.getY() + 0.5, (double)pos.getZ() + 0.5, (double)this.requiredPlayerRange);
++ return level.hasNearbyAlivePlayer((double) pos.getX() + 0.5D, (double) pos.getY() + 0.5D, (double) pos.getZ() + 0.5D, (double) this.requiredPlayerRange);
+ }
+
+ public void clientTick(Level level, BlockPos pos) {
+ if (!this.isNearPlayer(level, pos)) {
+ this.oSpin = this.spin;
+ } else if (this.displayEntity != null) {
+- RandomSource random = level.getRandom();
+- double d = (double)pos.getX() + random.nextDouble();
+- double d1 = (double)pos.getY() + random.nextDouble();
+- double d2 = (double)pos.getZ() + random.nextDouble();
+- level.addParticle(ParticleTypes.SMOKE, d, d1, d2, 0.0, 0.0, 0.0);
+- level.addParticle(ParticleTypes.FLAME, d, d1, d2, 0.0, 0.0, 0.0);
++ RandomSource randomsource = level.getRandom();
++ double d0 = (double) pos.getX() + randomsource.nextDouble();
++ double d1 = (double) pos.getY() + randomsource.nextDouble();
++ double d2 = (double) pos.getZ() + randomsource.nextDouble();
++
++ level.addParticle(ParticleTypes.SMOKE, d0, d1, d2, 0.0D, 0.0D, 0.0D);
++ level.addParticle(ParticleTypes.FLAME, d0, d1, d2, 0.0D, 0.0D, 0.0D);
+ if (this.spawnDelay > 0) {
+- this.spawnDelay--;
++ --this.spawnDelay;
+ }
+
+ this.oSpin = this.spin;
+- this.spin = (this.spin + (double)(1000.0F / ((float)this.spawnDelay + 200.0F))) % 360.0;
++ this.spin = (this.spin + (double) (1000.0F / ((float) this.spawnDelay + 200.0F))) % 360.0D;
+ }
++
+ }
+
+ public void serverTick(ServerLevel serverLevel, BlockPos pos) {
+@@ -79,93 +87,88 @@
+ }
+
+ if (this.spawnDelay > 0) {
+- this.spawnDelay--;
++ --this.spawnDelay;
+ } else {
+ boolean flag = false;
+- RandomSource random = serverLevel.getRandom();
+- SpawnData nextSpawnData = this.getOrCreateNextSpawnData(serverLevel, random, pos);
++ RandomSource randomsource = serverLevel.getRandom();
++ SpawnData mobspawnerdata = this.getOrCreateNextSpawnData(serverLevel, randomsource, pos);
+
+- for (int i = 0; i < this.spawnCount; i++) {
+- CompoundTag entityToSpawn = nextSpawnData.getEntityToSpawn();
+- Optional<EntityType<?>> optional = EntityType.by(entityToSpawn);
++ for (int i = 0; i < this.spawnCount; ++i) {
++ CompoundTag nbttagcompound = mobspawnerdata.getEntityToSpawn();
++ Optional<EntityType<?>> optional = EntityType.by(nbttagcompound);
++
+ if (optional.isEmpty()) {
+ this.delay(serverLevel, pos);
+ return;
+ }
+
+- ListTag list = entityToSpawn.getList("Pos", 6);
+- int size = list.size();
+- double d = size >= 1 ? list.getDouble(0) : (double)pos.getX() + (random.nextDouble() - random.nextDouble()) * (double)this.spawnRange + 0.5;
+- double d1 = size >= 2 ? list.getDouble(1) : (double)(pos.getY() + random.nextInt(3) - 1);
+- double d2 = size >= 3
+- ? list.getDouble(2)
+- : (double)pos.getZ() + (random.nextDouble() - random.nextDouble()) * (double)this.spawnRange + 0.5;
+- if (serverLevel.noCollision(optional.get().getAABB(d, d1, d2))) {
+- BlockPos blockPos = BlockPos.containing(d, d1, d2);
+- if (nextSpawnData.getCustomSpawnRules().isPresent()) {
+- if (!optional.get().getCategory().isFriendly() && serverLevel.getDifficulty() == Difficulty.PEACEFUL) {
++ ListTag nbttaglist = nbttagcompound.getList("Pos", 6);
++ int j = nbttaglist.size();
++ double d0 = j >= 1 ? nbttaglist.getDouble(0) : (double) pos.getX() + (randomsource.nextDouble() - randomsource.nextDouble()) * (double) this.spawnRange + 0.5D;
++ double d1 = j >= 2 ? nbttaglist.getDouble(1) : (double) (pos.getY() + randomsource.nextInt(3) - 1);
++ double d2 = j >= 3 ? nbttaglist.getDouble(2) : (double) pos.getZ() + (randomsource.nextDouble() - randomsource.nextDouble()) * (double) this.spawnRange + 0.5D;
++
++ if (serverLevel.noCollision(((EntityType) optional.get()).getAABB(d0, d1, d2))) {
++ BlockPos blockposition1 = BlockPos.containing(d0, d1, d2);
++
++ if (mobspawnerdata.getCustomSpawnRules().isPresent()) {
++ if (!((EntityType) optional.get()).getCategory().isFriendly() && serverLevel.getDifficulty() == Difficulty.PEACEFUL) {
+ continue;
+ }
+
+- SpawnData.CustomSpawnRules customSpawnRules = nextSpawnData.getCustomSpawnRules().get();
+- if (!customSpawnRules.blockLightLimit().isValueInRange(serverLevel.getBrightness(LightLayer.BLOCK, blockPos))
+- || !customSpawnRules.skyLightLimit().isValueInRange(serverLevel.getBrightness(LightLayer.SKY, blockPos))) {
++ SpawnData.CustomSpawnRules mobspawnerdata_a = (SpawnData.CustomSpawnRules) mobspawnerdata.getCustomSpawnRules().get();
++
++ if (!mobspawnerdata_a.blockLightLimit().isValueInRange(serverLevel.getBrightness(EnumSkyBlock.BLOCK, blockposition1)) || !mobspawnerdata_a.skyLightLimit().isValueInRange(serverLevel.getBrightness(EnumSkyBlock.SKY, blockposition1))) {
+ continue;
+ }
+- } else if (!SpawnPlacements.checkSpawnRules(optional.get(), serverLevel, MobSpawnType.SPAWNER, blockPos, serverLevel.getRandom())) {
++ } else if (!SpawnPlacements.checkSpawnRules((EntityType) optional.get(), serverLevel, EnumMobSpawn.SPAWNER, blockposition1, serverLevel.getRandom())) {
+ continue;
+ }
+
+- Entity entity = EntityType.loadEntityRecursive(entityToSpawn, serverLevel, entity1 -> {
+- entity1.moveTo(d, d1, d2, entity1.getYRot(), entity1.getXRot());
++ Entity entity = EntityType.loadEntityRecursive(nbttagcompound, serverLevel, (entity1) -> {
++ entity1.moveTo(d0, d1, d2, entity1.getYRot(), entity1.getXRot());
+ return entity1;
+ });
++
+ if (entity == null) {
+ this.delay(serverLevel, pos);
+ return;
+ }
+
+- int size1 = serverLevel.getEntities(
+- EntityTypeTest.forExactClass(entity.getClass()),
+- new AABB(
+- (double)pos.getX(),
+- (double)pos.getY(),
+- (double)pos.getZ(),
+- (double)(pos.getX() + 1),
+- (double)(pos.getY() + 1),
+- (double)(pos.getZ() + 1)
+- )
+- .inflate((double)this.spawnRange),
+- EntitySelector.NO_SPECTATORS
+- )
+- .size();
+- if (size1 >= this.maxNearbyEntities) {
++ int k = serverLevel.getEntities(EntityTypeTest.forExactClass(entity.getClass()), (new AABB((double) pos.getX(), (double) pos.getY(), (double) pos.getZ(), (double) (pos.getX() + 1), (double) (pos.getY() + 1), (double) (pos.getZ() + 1))).inflate((double) this.spawnRange), EntitySelector.NO_SPECTATORS).size();
++
++ if (k >= this.maxNearbyEntities) {
+ this.delay(serverLevel, pos);
+ return;
+ }
+
+- entity.moveTo(entity.getX(), entity.getY(), entity.getZ(), random.nextFloat() * 360.0F, 0.0F);
+- if (entity instanceof Mob mob) {
+- if (nextSpawnData.getCustomSpawnRules().isEmpty() && !mob.checkSpawnRules(serverLevel, MobSpawnType.SPAWNER)
+- || !mob.checkSpawnObstruction(serverLevel)) {
++ entity.moveTo(entity.getX(), entity.getY(), entity.getZ(), randomsource.nextFloat() * 360.0F, 0.0F);
++ if (entity instanceof Mob) {
++ Mob entityinsentient = (Mob) entity;
++
++ if (mobspawnerdata.getCustomSpawnRules().isEmpty() && !entityinsentient.checkSpawnRules(serverLevel, EnumMobSpawn.SPAWNER) || !entityinsentient.checkSpawnObstruction(serverLevel)) {
+ continue;
+ }
+
+- if (nextSpawnData.getEntityToSpawn().size() == 1 && nextSpawnData.getEntityToSpawn().contains("id", 8)) {
+- ((Mob)entity)
+- .finalizeSpawn(serverLevel, serverLevel.getCurrentDifficultyAt(entity.blockPosition()), MobSpawnType.SPAWNER, null, null);
++ if (mobspawnerdata.getEntityToSpawn().size() == 1 && mobspawnerdata.getEntityToSpawn().contains("id", 8)) {
++ ((Mob) entity).finalizeSpawn(serverLevel, serverLevel.getCurrentDifficultyAt(entity.blockPosition()), EnumMobSpawn.SPAWNER, (GroupDataEntity) null, (CompoundTag) null);
+ }
+ }
+
+- if (!serverLevel.tryAddFreshEntityWithPassengers(entity)) {
++ // CraftBukkit start
++ if (org.bukkit.craftbukkit.event.CraftEventFactory.callSpawnerSpawnEvent(entity, pos).isCancelled()) {
++ continue;
++ }
++ if (!serverLevel.tryAddFreshEntityWithPassengers(entity, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.SPAWNER)) {
++ // CraftBukkit end
+ this.delay(serverLevel, pos);
+ return;
+ }
+
+ serverLevel.levelEvent(2004, pos, 0);
+- serverLevel.gameEvent(entity, GameEvent.ENTITY_PLACE, blockPos);
++ serverLevel.gameEvent(entity, GameEvent.ENTITY_PLACE, blockposition1);
+ if (entity instanceof Mob) {
+- ((Mob)entity).spawnAnim();
++ ((Mob) entity).spawnAnim();
+ }
+
+ flag = true;
+@@ -175,40 +178,46 @@
+ if (flag) {
+ this.delay(serverLevel, pos);
+ }
++
+ }
+ }
+ }
+
+ private void delay(Level level, BlockPos pos) {
+- RandomSource randomSource = level.random;
++ RandomSource randomsource = level.random;
++
+ if (this.maxSpawnDelay <= this.minSpawnDelay) {
+ this.spawnDelay = this.minSpawnDelay;
+ } else {
+- this.spawnDelay = this.minSpawnDelay + randomSource.nextInt(this.maxSpawnDelay - this.minSpawnDelay);
++ this.spawnDelay = this.minSpawnDelay + randomsource.nextInt(this.maxSpawnDelay - this.minSpawnDelay);
+ }
+
+- this.spawnPotentials.getRandom(randomSource).ifPresent(data -> this.setNextSpawnData(level, pos, data.getData()));
++ this.spawnPotentials.getRandom(randomsource).ifPresent((weightedentry_b) -> {
++ this.setNextSpawnData(level, pos, (SpawnData) weightedentry_b.getData());
++ });
+ this.broadcastEvent(level, pos, 1);
+ }
+
+ public void load(@Nullable Level level, BlockPos pos, CompoundTag tag) {
+ this.spawnDelay = tag.getShort("Delay");
+ boolean flag = tag.contains("SpawnData", 10);
++
+ if (flag) {
+- SpawnData spawnData = SpawnData.CODEC
+- .parse(NbtOps.INSTANCE, tag.getCompound("SpawnData"))
+- .resultOrPartial(data -> LOGGER.warn("Invalid SpawnData: {}", data))
+- .orElseGet(SpawnData::new);
+- this.setNextSpawnData(level, pos, spawnData);
++ SpawnData mobspawnerdata = (SpawnData) SpawnData.CODEC.parse(NbtOps.INSTANCE, tag.getCompound("SpawnData")).resultOrPartial((s) -> {
++ BaseSpawner.LOGGER.warn("Invalid SpawnData: {}", s);
++ }).orElseGet(SpawnData::new);
++
++ this.setNextSpawnData(level, pos, mobspawnerdata);
+ }
+
+ boolean flag1 = tag.contains("SpawnPotentials", 9);
++
+ if (flag1) {
+- ListTag list = tag.getList("SpawnPotentials", 10);
+- this.spawnPotentials = SpawnData.LIST_CODEC
+- .parse(NbtOps.INSTANCE, list)
+- .resultOrPartial(potentials -> LOGGER.warn("Invalid SpawnPotentials list: {}", potentials))
+- .orElseGet(SimpleWeightedRandomList::empty);
++ ListTag nbttaglist = tag.getList("SpawnPotentials", 10);
++
++ this.spawnPotentials = (SimpleWeightedRandomList) SpawnData.LIST_CODEC.parse(NbtOps.INSTANCE, nbttaglist).resultOrPartial((s) -> {
++ BaseSpawner.LOGGER.warn("Invalid SpawnPotentials list: {}", s);
++ }).orElseGet(SimpleWeightedRandomList::empty);
+ } else {
+ this.spawnPotentials = SimpleWeightedRandomList.single(this.nextSpawnData != null ? this.nextSpawnData : new SpawnData());
+ }
+@@ -232,34 +241,35 @@
+ }
+
+ public CompoundTag save(CompoundTag tag) {
+- tag.putShort("Delay", (short)this.spawnDelay);
+- tag.putShort("MinSpawnDelay", (short)this.minSpawnDelay);
+- tag.putShort("MaxSpawnDelay", (short)this.maxSpawnDelay);
+- tag.putShort("SpawnCount", (short)this.spawnCount);
+- tag.putShort("MaxNearbyEntities", (short)this.maxNearbyEntities);
+- tag.putShort("RequiredPlayerRange", (short)this.requiredPlayerRange);
+- tag.putShort("SpawnRange", (short)this.spawnRange);
++ tag.putShort("Delay", (short) this.spawnDelay);
++ tag.putShort("MinSpawnDelay", (short) this.minSpawnDelay);
++ tag.putShort("MaxSpawnDelay", (short) this.maxSpawnDelay);
++ tag.putShort("SpawnCount", (short) this.spawnCount);
++ tag.putShort("MaxNearbyEntities", (short) this.maxNearbyEntities);
++ tag.putShort("RequiredPlayerRange", (short) this.requiredPlayerRange);
++ tag.putShort("SpawnRange", (short) this.spawnRange);
+ if (this.nextSpawnData != null) {
+- tag.put(
+- "SpawnData",
+- SpawnData.CODEC.encodeStart(NbtOps.INSTANCE, this.nextSpawnData).result().orElseThrow(() -> new IllegalStateException("Invalid SpawnData"))
+- );
++ tag.put("SpawnData", (Tag) SpawnData.CODEC.encodeStart(NbtOps.INSTANCE, this.nextSpawnData).result().orElseThrow(() -> {
++ return new IllegalStateException("Invalid SpawnData");
++ }));
+ }
+
+- tag.put("SpawnPotentials", SpawnData.LIST_CODEC.encodeStart(NbtOps.INSTANCE, this.spawnPotentials).result().orElseThrow());
++ tag.put("SpawnPotentials", (Tag) SpawnData.LIST_CODEC.encodeStart(NbtOps.INSTANCE, this.spawnPotentials).result().orElseThrow());
+ return tag;
+ }
+
+ @Nullable
+- public Entity getOrCreateDisplayEntity(Level level, BlockPos blockPos) {
++ public Entity getOrCreateDisplayEntity(Level world, BlockPos blockposition) {
+ if (this.displayEntity == null) {
+- CompoundTag entityToSpawn = this.getOrCreateNextSpawnData(level, level.getRandom(), blockPos).getEntityToSpawn();
+- if (!entityToSpawn.contains("id", 8)) {
++ CompoundTag nbttagcompound = this.getOrCreateNextSpawnData(world, world.getRandom(), blockposition).getEntityToSpawn();
++
++ if (!nbttagcompound.contains("id", 8)) {
+ return null;
+ }
+
+- this.displayEntity = EntityType.loadEntityRecursive(entityToSpawn, level, Function.identity());
+- if (entityToSpawn.size() == 1 && this.displayEntity instanceof Mob) {
++ this.displayEntity = EntityType.loadEntityRecursive(nbttagcompound, world, Function.identity());
++ if (nbttagcompound.size() == 1 && this.displayEntity instanceof Mob) {
++ ;
+ }
+ }
+
+@@ -286,7 +296,7 @@
+ if (this.nextSpawnData != null) {
+ return this.nextSpawnData;
+ } else {
+- this.setNextSpawnData(level, pos, this.spawnPotentials.getRandom(random).map(WeightedEntry.Wrapper::getData).orElseGet(SpawnData::new));
++ this.setNextSpawnData(level, pos, (SpawnData) this.spawnPotentials.getRandom(random).map(WeightedEntry.Wrapper::getData).orElseGet(SpawnData::new));
+ return this.nextSpawnData;
+ }
+ }