aboutsummaryrefslogtreecommitdiffhomepage
path: root/patch-remap/mache-vineflower/net/minecraft/world/level/levelgen/PatrolSpawner.java.patch
blob: d68ddd74f3b7dcc67ca87da011eb4eb69785cc29 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
--- a/net/minecraft/world/level/levelgen/PatrolSpawner.java
+++ b/net/minecraft/world/level/levelgen/PatrolSpawner.java
@@ -2,22 +2,27 @@
 
 import net.minecraft.core.BlockPos;
 import net.minecraft.core.Holder;
+import net.minecraft.nbt.CompoundTag;
 import net.minecraft.server.level.ServerLevel;
 import net.minecraft.tags.BiomeTags;
 import net.minecraft.util.RandomSource;
 import net.minecraft.world.entity.EntityType;
-import net.minecraft.world.entity.MobSpawnType;
+import net.minecraft.world.entity.EnumMobSpawn;
+import net.minecraft.world.entity.GroupDataEntity;
 import net.minecraft.world.entity.monster.PatrollingMonster;
 import net.minecraft.world.entity.player.Player;
 import net.minecraft.world.level.CustomSpawner;
 import net.minecraft.world.level.GameRules;
 import net.minecraft.world.level.NaturalSpawner;
 import net.minecraft.world.level.biome.Biome;
-import net.minecraft.world.level.block.state.BlockState;
+import net.minecraft.world.level.block.state.IBlockData;
 
 public class PatrolSpawner implements CustomSpawner {
+
     private int nextTick;
 
+    public PatrolSpawner() {}
+
     @Override
     public int tick(ServerLevel level, boolean spawnEnemies, boolean spawnFriendlies) {
         if (!spawnEnemies) {
@@ -25,86 +30,94 @@
         } else if (!level.getGameRules().getBoolean(GameRules.RULE_DO_PATROL_SPAWNING)) {
             return 0;
         } else {
-            RandomSource randomSource = level.random;
-            this.nextTick--;
+            RandomSource randomsource = level.random;
+
+            --this.nextTick;
             if (this.nextTick > 0) {
                 return 0;
             } else {
-                this.nextTick = this.nextTick + 12000 + randomSource.nextInt(1200);
-                long l = level.getDayTime() / 24000L;
-                if (l < 5L || !level.isDay()) {
-                    return 0;
-                } else if (randomSource.nextInt(5) != 0) {
-                    return 0;
-                } else {
-                    int size = level.players().size();
-                    if (size < 1) {
+                this.nextTick += 12000 + randomsource.nextInt(1200);
+                long i = level.getDayTime() / 24000L;
+
+                if (i >= 5L && level.isDay()) {
+                    if (randomsource.nextInt(5) != 0) {
                         return 0;
                     } else {
-                        Player player = level.players().get(randomSource.nextInt(size));
-                        if (player.isSpectator()) {
+                        int j = level.players().size();
+
+                        if (j < 1) {
                             return 0;
-                        } else if (level.isCloseToVillage(player.blockPosition(), 2)) {
-                            return 0;
                         } else {
-                            int i = (24 + randomSource.nextInt(24)) * (randomSource.nextBoolean() ? -1 : 1);
-                            int i1 = (24 + randomSource.nextInt(24)) * (randomSource.nextBoolean() ? -1 : 1);
-                            BlockPos.MutableBlockPos mutableBlockPos = player.blockPosition().mutable().move(i, 0, i1);
-                            int i2 = 10;
-                            if (!level.hasChunksAt(
-                                mutableBlockPos.getX() - 10, mutableBlockPos.getZ() - 10, mutableBlockPos.getX() + 10, mutableBlockPos.getZ() + 10
-                            )) {
+                            Player entityhuman = (Player) level.players().get(randomsource.nextInt(j));
+
+                            if (entityhuman.isSpectator()) {
                                 return 0;
+                            } else if (level.isCloseToVillage(entityhuman.blockPosition(), 2)) {
+                                return 0;
                             } else {
-                                Holder<Biome> biome = level.getBiome(mutableBlockPos);
-                                if (biome.is(BiomeTags.WITHOUT_PATROL_SPAWNS)) {
+                                int k = (24 + randomsource.nextInt(24)) * (randomsource.nextBoolean() ? -1 : 1);
+                                int l = (24 + randomsource.nextInt(24)) * (randomsource.nextBoolean() ? -1 : 1);
+                                BlockPos.MutableBlockPos blockposition_mutableblockposition = entityhuman.blockPosition().mutable().move(k, 0, l);
+                                boolean flag2 = true;
+
+                                if (!level.hasChunksAt(blockposition_mutableblockposition.getX() - 10, blockposition_mutableblockposition.getZ() - 10, blockposition_mutableblockposition.getX() + 10, blockposition_mutableblockposition.getZ() + 10)) {
                                     return 0;
                                 } else {
-                                    int i3 = 0;
-                                    int i4 = (int)Math.ceil((double)level.getCurrentDifficultyAt(mutableBlockPos).getEffectiveDifficulty()) + 1;
+                                    Holder<Biome> holder = level.getBiome(blockposition_mutableblockposition);
 
-                                    for (int i5 = 0; i5 < i4; i5++) {
-                                        i3++;
-                                        mutableBlockPos.setY(level.getHeightmapPos(Heightmap.Types.MOTION_BLOCKING_NO_LEAVES, mutableBlockPos).getY());
-                                        if (i5 == 0) {
-                                            if (!this.spawnPatrolMember(level, mutableBlockPos, randomSource, true)) {
-                                                break;
+                                    if (holder.is(BiomeTags.WITHOUT_PATROL_SPAWNS)) {
+                                        return 0;
+                                    } else {
+                                        int i1 = 0;
+                                        int j1 = (int) Math.ceil((double) level.getCurrentDifficultyAt(blockposition_mutableblockposition).getEffectiveDifficulty()) + 1;
+
+                                        for (int k1 = 0; k1 < j1; ++k1) {
+                                            ++i1;
+                                            blockposition_mutableblockposition.setY(level.getHeightmapPos(Heightmap.Types.MOTION_BLOCKING_NO_LEAVES, blockposition_mutableblockposition).getY());
+                                            if (k1 == 0) {
+                                                if (!this.spawnPatrolMember(level, blockposition_mutableblockposition, randomsource, true)) {
+                                                    break;
+                                                }
+                                            } else {
+                                                this.spawnPatrolMember(level, blockposition_mutableblockposition, randomsource, false);
                                             }
-                                        } else {
-                                            this.spawnPatrolMember(level, mutableBlockPos, randomSource, false);
+
+                                            blockposition_mutableblockposition.setX(blockposition_mutableblockposition.getX() + randomsource.nextInt(5) - randomsource.nextInt(5));
+                                            blockposition_mutableblockposition.setZ(blockposition_mutableblockposition.getZ() + randomsource.nextInt(5) - randomsource.nextInt(5));
                                         }
 
-                                        mutableBlockPos.setX(mutableBlockPos.getX() + randomSource.nextInt(5) - randomSource.nextInt(5));
-                                        mutableBlockPos.setZ(mutableBlockPos.getZ() + randomSource.nextInt(5) - randomSource.nextInt(5));
+                                        return i1;
                                     }
-
-                                    return i3;
                                 }
                             }
                         }
                     }
+                } else {
+                    return 0;
                 }
             }
         }
     }
 
     private boolean spawnPatrolMember(ServerLevel level, BlockPos pos, RandomSource random, boolean leader) {
-        BlockState blockState = level.getBlockState(pos);
-        if (!NaturalSpawner.isValidEmptySpawnBlock(level, pos, blockState, blockState.getFluidState(), EntityType.PILLAGER)) {
+        IBlockData iblockdata = level.getBlockState(pos);
+
+        if (!NaturalSpawner.isValidEmptySpawnBlock(level, pos, iblockdata, iblockdata.getFluidState(), EntityType.PILLAGER)) {
             return false;
-        } else if (!PatrollingMonster.checkPatrollingMonsterSpawnRules(EntityType.PILLAGER, level, MobSpawnType.PATROL, pos, random)) {
+        } else if (!PatrollingMonster.checkPatrollingMonsterSpawnRules(EntityType.PILLAGER, level, EnumMobSpawn.PATROL, pos, random)) {
             return false;
         } else {
-            PatrollingMonster patrollingMonster = EntityType.PILLAGER.create(level);
-            if (patrollingMonster != null) {
+            PatrollingMonster entitymonsterpatrolling = (PatrollingMonster) EntityType.PILLAGER.create(level);
+
+            if (entitymonsterpatrolling != null) {
                 if (leader) {
-                    patrollingMonster.setPatrolLeader(true);
-                    patrollingMonster.findPatrolTarget();
+                    entitymonsterpatrolling.setPatrolLeader(true);
+                    entitymonsterpatrolling.findPatrolTarget();
                 }
 
-                patrollingMonster.setPos((double)pos.getX(), (double)pos.getY(), (double)pos.getZ());
-                patrollingMonster.finalizeSpawn(level, level.getCurrentDifficultyAt(pos), MobSpawnType.PATROL, null, null);
-                level.addFreshEntityWithPassengers(patrollingMonster);
+                entitymonsterpatrolling.setPos((double) pos.getX(), (double) pos.getY(), (double) pos.getZ());
+                entitymonsterpatrolling.finalizeSpawn(level, level.getCurrentDifficultyAt(pos), EnumMobSpawn.PATROL, (GroupDataEntity) null, (CompoundTag) null);
+                level.addFreshEntityWithPassengers(entitymonsterpatrolling, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.PATROL); // CraftBukkit
                 return true;
             } else {
                 return false;