diff options
Diffstat (limited to 'patch-remap/mache-spigotflower/net/minecraft/world/level/BaseSpawner.java.patch')
-rw-r--r-- | patch-remap/mache-spigotflower/net/minecraft/world/level/BaseSpawner.java.patch | 367 |
1 files changed, 367 insertions, 0 deletions
diff --git a/patch-remap/mache-spigotflower/net/minecraft/world/level/BaseSpawner.java.patch b/patch-remap/mache-spigotflower/net/minecraft/world/level/BaseSpawner.java.patch new file mode 100644 index 0000000000..d948068a10 --- /dev/null +++ b/patch-remap/mache-spigotflower/net/minecraft/world/level/BaseSpawner.java.patch @@ -0,0 +1,367 @@ +--- a/net/minecraft/world/level/BaseSpawner.java ++++ b/net/minecraft/world/level/BaseSpawner.java +@@ -19,9 +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.SpawnGroupData; + import net.minecraft.world.entity.SpawnPlacements; + import net.minecraft.world.level.entity.EntityTypeTest; + import net.minecraft.world.level.gameevent.GameEvent; +@@ -33,39 +33,40 @@ + 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<?> entitytype, @Nullable Level level, RandomSource randomsource, BlockPos blockpos) { +- this.getOrCreateNextSpawnData(level, randomsource, blockpos).getEntityToSpawn().putString("id", BuiltInRegistries.ENTITY_TYPE.getKey(entitytype).toString()); ++ 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 blockpos) { +- return level.hasNearbyAlivePlayer((double) blockpos.getX() + 0.5D, (double) blockpos.getY() + 0.5D, (double) blockpos.getZ() + 0.5D, (double) this.requiredPlayerRange); ++ private boolean isNearPlayer(Level level, BlockPos pos) { ++ 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 blockpos) { +- if (!this.isNearPlayer(level, blockpos)) { ++ public void clientTick(Level level, BlockPos pos) { ++ if (!this.isNearPlayer(level, pos)) { + this.oSpin = this.spin; + } else if (this.displayEntity != null) { + RandomSource randomsource = level.getRandom(); +- double d0 = (double) blockpos.getX() + randomsource.nextDouble(); +- double d1 = (double) blockpos.getY() + randomsource.nextDouble(); +- double d2 = (double) blockpos.getZ() + randomsource.nextDouble(); ++ 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); +@@ -79,88 +80,93 @@ + + } + +- public void serverTick(ServerLevel serverlevel, BlockPos blockpos) { +- if (this.isNearPlayer(serverlevel, blockpos)) { ++ public void serverTick(ServerLevel serverLevel, BlockPos pos) { ++ if (this.isNearPlayer(serverLevel, pos)) { + if (this.spawnDelay == -1) { +- this.delay(serverlevel, blockpos); ++ this.delay(serverLevel, pos); + } + + if (this.spawnDelay > 0) { + --this.spawnDelay; + } else { + boolean flag = false; +- RandomSource randomsource = serverlevel.getRandom(); +- SpawnData spawndata = this.getOrCreateNextSpawnData(serverlevel, randomsource, blockpos); ++ RandomSource randomsource = serverLevel.getRandom(); ++ SpawnData mobspawnerdata = this.getOrCreateNextSpawnData(serverLevel, randomsource, pos); + + for (int i = 0; i < this.spawnCount; ++i) { +- CompoundTag compoundtag = spawndata.getEntityToSpawn(); +- Optional<EntityType<?>> optional = EntityType.by(compoundtag); ++ CompoundTag nbttagcompound = mobspawnerdata.getEntityToSpawn(); ++ Optional<EntityType<?>> optional = EntityType.by(nbttagcompound); + + if (optional.isEmpty()) { +- this.delay(serverlevel, blockpos); ++ this.delay(serverLevel, pos); + return; + } + +- ListTag listtag = compoundtag.getList("Pos", 6); +- int j = listtag.size(); +- double d0 = j >= 1 ? listtag.getDouble(0) : (double) blockpos.getX() + (randomsource.nextDouble() - randomsource.nextDouble()) * (double) this.spawnRange + 0.5D; +- double d1 = j >= 2 ? listtag.getDouble(1) : (double) (blockpos.getY() + randomsource.nextInt(3) - 1); +- double d2 = j >= 3 ? listtag.getDouble(2) : (double) blockpos.getZ() + (randomsource.nextDouble() - randomsource.nextDouble()) * (double) this.spawnRange + 0.5D; ++ 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 blockpos1 = BlockPos.containing(d0, d1, d2); ++ if (serverLevel.noCollision(((EntityType) optional.get()).getAABB(d0, d1, d2))) { ++ BlockPos blockposition1 = BlockPos.containing(d0, d1, d2); + +- if (spawndata.getCustomSpawnRules().isPresent()) { +- if (!((EntityType) optional.get()).getCategory().isFriendly() && serverlevel.getDifficulty() == Difficulty.PEACEFUL) { ++ if (mobspawnerdata.getCustomSpawnRules().isPresent()) { ++ if (!((EntityType) optional.get()).getCategory().isFriendly() && serverLevel.getDifficulty() == Difficulty.PEACEFUL) { + continue; + } + +- SpawnData.CustomSpawnRules spawndata_customspawnrules = (SpawnData.CustomSpawnRules) spawndata.getCustomSpawnRules().get(); ++ SpawnData.CustomSpawnRules mobspawnerdata_a = (SpawnData.CustomSpawnRules) mobspawnerdata.getCustomSpawnRules().get(); + +- if (!spawndata_customspawnrules.blockLightLimit().isValueInRange(serverlevel.getBrightness(LightLayer.BLOCK, blockpos1)) || !spawndata_customspawnrules.skyLightLimit().isValueInRange(serverlevel.getBrightness(LightLayer.SKY, blockpos1))) { ++ if (!mobspawnerdata_a.blockLightLimit().isValueInRange(serverLevel.getBrightness(EnumSkyBlock.BLOCK, blockposition1)) || !mobspawnerdata_a.skyLightLimit().isValueInRange(serverLevel.getBrightness(EnumSkyBlock.SKY, blockposition1))) { + continue; + } +- } else if (!SpawnPlacements.checkSpawnRules((EntityType) optional.get(), serverlevel, MobSpawnType.SPAWNER, blockpos1, serverlevel.getRandom())) { ++ } else if (!SpawnPlacements.checkSpawnRules((EntityType) optional.get(), serverLevel, EnumMobSpawn.SPAWNER, blockposition1, serverLevel.getRandom())) { + continue; + } + +- Entity entity = EntityType.loadEntityRecursive(compoundtag, serverlevel, (entity1) -> { ++ Entity entity = EntityType.loadEntityRecursive(nbttagcompound, serverLevel, (entity1) -> { + entity1.moveTo(d0, d1, d2, entity1.getYRot(), entity1.getXRot()); + return entity1; + }); + + if (entity == null) { +- this.delay(serverlevel, blockpos); ++ this.delay(serverLevel, pos); + return; + } + +- int k = serverlevel.getEntities(EntityTypeTest.forExactClass(entity.getClass()), (new AABB((double) blockpos.getX(), (double) blockpos.getY(), (double) blockpos.getZ(), (double) (blockpos.getX() + 1), (double) (blockpos.getY() + 1), (double) (blockpos.getZ() + 1))).inflate((double) this.spawnRange), EntitySelector.NO_SPECTATORS).size(); ++ 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, blockpos); ++ this.delay(serverLevel, pos); + return; + } + + entity.moveTo(entity.getX(), entity.getY(), entity.getZ(), randomsource.nextFloat() * 360.0F, 0.0F); + if (entity instanceof Mob) { +- Mob mob = (Mob) entity; ++ Mob entityinsentient = (Mob) entity; + +- if (spawndata.getCustomSpawnRules().isEmpty() && !mob.checkSpawnRules(serverlevel, MobSpawnType.SPAWNER) || !mob.checkSpawnObstruction(serverlevel)) { ++ if (mobspawnerdata.getCustomSpawnRules().isEmpty() && !entityinsentient.checkSpawnRules(serverLevel, EnumMobSpawn.SPAWNER) || !entityinsentient.checkSpawnObstruction(serverLevel)) { + continue; + } + +- if (spawndata.getEntityToSpawn().size() == 1 && spawndata.getEntityToSpawn().contains("id", 8)) { +- ((Mob) entity).finalizeSpawn(serverlevel, serverlevel.getCurrentDifficultyAt(entity.blockPosition()), MobSpawnType.SPAWNER, (SpawnGroupData) null, (CompoundTag) 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)) { +- this.delay(serverlevel, blockpos); ++ // 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, blockpos, 0); +- serverlevel.gameEvent(entity, GameEvent.ENTITY_PLACE, blockpos1); ++ serverLevel.levelEvent(2004, pos, 0); ++ serverLevel.gameEvent(entity, GameEvent.ENTITY_PLACE, blockposition1); + if (entity instanceof Mob) { + ((Mob) entity).spawnAnim(); + } +@@ -170,14 +176,14 @@ + } + + if (flag) { +- this.delay(serverlevel, blockpos); ++ this.delay(serverLevel, pos); + } + + } + } + } + +- private void delay(Level level, BlockPos blockpos) { ++ private void delay(Level level, BlockPos pos) { + RandomSource randomsource = level.random; + + if (this.maxSpawnDelay <= this.minSpawnDelay) { +@@ -186,83 +192,83 @@ + this.spawnDelay = this.minSpawnDelay + randomsource.nextInt(this.maxSpawnDelay - this.minSpawnDelay); + } + +- this.spawnPotentials.getRandom(randomsource).ifPresent((weightedentry_wrapper) -> { +- this.setNextSpawnData(level, blockpos, (SpawnData) weightedentry_wrapper.getData()); ++ this.spawnPotentials.getRandom(randomsource).ifPresent((weightedentry_b) -> { ++ this.setNextSpawnData(level, pos, (SpawnData) weightedentry_b.getData()); + }); +- this.broadcastEvent(level, blockpos, 1); ++ this.broadcastEvent(level, pos, 1); + } + +- public void load(@Nullable Level level, BlockPos blockpos, CompoundTag compoundtag) { +- this.spawnDelay = compoundtag.getShort("Delay"); +- boolean flag = compoundtag.contains("SpawnData", 10); ++ 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) SpawnData.CODEC.parse(NbtOps.INSTANCE, compoundtag.getCompound("SpawnData")).resultOrPartial((s) -> { ++ 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, blockpos, spawndata); ++ this.setNextSpawnData(level, pos, mobspawnerdata); + } + +- boolean flag1 = compoundtag.contains("SpawnPotentials", 9); ++ boolean flag1 = tag.contains("SpawnPotentials", 9); + + if (flag1) { +- ListTag listtag = compoundtag.getList("SpawnPotentials", 10); ++ ListTag nbttaglist = tag.getList("SpawnPotentials", 10); + +- this.spawnPotentials = (SimpleWeightedRandomList) SpawnData.LIST_CODEC.parse(NbtOps.INSTANCE, listtag).resultOrPartial((s) -> { ++ 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()); + } + +- if (compoundtag.contains("MinSpawnDelay", 99)) { +- this.minSpawnDelay = compoundtag.getShort("MinSpawnDelay"); +- this.maxSpawnDelay = compoundtag.getShort("MaxSpawnDelay"); +- this.spawnCount = compoundtag.getShort("SpawnCount"); ++ if (tag.contains("MinSpawnDelay", 99)) { ++ this.minSpawnDelay = tag.getShort("MinSpawnDelay"); ++ this.maxSpawnDelay = tag.getShort("MaxSpawnDelay"); ++ this.spawnCount = tag.getShort("SpawnCount"); + } + +- if (compoundtag.contains("MaxNearbyEntities", 99)) { +- this.maxNearbyEntities = compoundtag.getShort("MaxNearbyEntities"); +- this.requiredPlayerRange = compoundtag.getShort("RequiredPlayerRange"); ++ if (tag.contains("MaxNearbyEntities", 99)) { ++ this.maxNearbyEntities = tag.getShort("MaxNearbyEntities"); ++ this.requiredPlayerRange = tag.getShort("RequiredPlayerRange"); + } + +- if (compoundtag.contains("SpawnRange", 99)) { +- this.spawnRange = compoundtag.getShort("SpawnRange"); ++ if (tag.contains("SpawnRange", 99)) { ++ this.spawnRange = tag.getShort("SpawnRange"); + } + + this.displayEntity = null; + } + +- public CompoundTag save(CompoundTag compoundtag) { +- compoundtag.putShort("Delay", (short) this.spawnDelay); +- compoundtag.putShort("MinSpawnDelay", (short) this.minSpawnDelay); +- compoundtag.putShort("MaxSpawnDelay", (short) this.maxSpawnDelay); +- compoundtag.putShort("SpawnCount", (short) this.spawnCount); +- compoundtag.putShort("MaxNearbyEntities", (short) this.maxNearbyEntities); +- compoundtag.putShort("RequiredPlayerRange", (short) this.requiredPlayerRange); +- compoundtag.putShort("SpawnRange", (short) this.spawnRange); ++ 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); + if (this.nextSpawnData != null) { +- compoundtag.put("SpawnData", (Tag) SpawnData.CODEC.encodeStart(NbtOps.INSTANCE, this.nextSpawnData).result().orElseThrow(() -> { ++ tag.put("SpawnData", (Tag) SpawnData.CODEC.encodeStart(NbtOps.INSTANCE, this.nextSpawnData).result().orElseThrow(() -> { + return new IllegalStateException("Invalid SpawnData"); + })); + } + +- compoundtag.put("SpawnPotentials", (Tag) SpawnData.LIST_CODEC.encodeStart(NbtOps.INSTANCE, this.spawnPotentials).result().orElseThrow()); +- return compoundtag; ++ 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 compoundtag = this.getOrCreateNextSpawnData(level, level.getRandom(), blockpos).getEntityToSpawn(); ++ CompoundTag nbttagcompound = this.getOrCreateNextSpawnData(world, world.getRandom(), blockposition).getEntityToSpawn(); + +- if (!compoundtag.contains("id", 8)) { ++ if (!nbttagcompound.contains("id", 8)) { + return null; + } + +- this.displayEntity = EntityType.loadEntityRecursive(compoundtag, level, Function.identity()); +- if (compoundtag.size() == 1 && this.displayEntity instanceof Mob) { ++ this.displayEntity = EntityType.loadEntityRecursive(nbttagcompound, world, Function.identity()); ++ if (nbttagcompound.size() == 1 && this.displayEntity instanceof Mob) { + ; + } + } +@@ -270,8 +276,8 @@ + return this.displayEntity; + } + +- public boolean onEventTriggered(Level level, int i) { +- if (i == 1) { ++ public boolean onEventTriggered(Level level, int id) { ++ if (id == 1) { + if (level.isClientSide) { + this.spawnDelay = this.minSpawnDelay; + } +@@ -282,15 +288,15 @@ + } + } + +- protected void setNextSpawnData(@Nullable Level level, BlockPos blockpos, SpawnData spawndata) { +- this.nextSpawnData = spawndata; ++ protected void setNextSpawnData(@Nullable Level level, BlockPos pos, SpawnData nextSpawnData) { ++ this.nextSpawnData = nextSpawnData; + } + +- private SpawnData getOrCreateNextSpawnData(@Nullable Level level, RandomSource randomsource, BlockPos blockpos) { ++ private SpawnData getOrCreateNextSpawnData(@Nullable Level level, RandomSource random, BlockPos pos) { + if (this.nextSpawnData != null) { + return this.nextSpawnData; + } else { +- this.setNextSpawnData(level, blockpos, (SpawnData) this.spawnPotentials.getRandom(randomsource).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; + } + } |