|
2 | 2 |
|
3 | 3 | import java.util.List; |
4 | 4 |
|
| 5 | +import de.scribble.lp.tasmod.TASmod; |
5 | 6 | import de.scribble.lp.tasmod.duck.ChunkProviderDuck; |
6 | 7 | import de.scribble.lp.tasmod.mixin.accessors.AccessorSaveHandler; |
7 | 8 | import de.scribble.lp.tasmod.mixin.accessors.AccessorWorld; |
| 9 | +import de.scribble.lp.tasmod.mixin.accessors.AccessorWorldServer; |
8 | 10 | import de.scribble.lp.tasmod.mixin.savestates.MixinChunkProviderClient; |
9 | 11 | import de.scribble.lp.tasmod.mixin.savestates.MixinChunkProviderServer; |
10 | 12 | import net.minecraft.client.Minecraft; |
|
13 | 15 | import net.minecraft.entity.player.EntityPlayerMP; |
14 | 16 | import net.minecraft.server.MinecraftServer; |
15 | 17 | import net.minecraft.util.math.MathHelper; |
| 18 | +import net.minecraft.world.NextTickListEntry; |
16 | 19 | import net.minecraft.world.WorldServer; |
17 | 20 | import net.minecraft.world.chunk.Chunk; |
18 | 21 | import net.minecraft.world.gen.ChunkProviderServer; |
@@ -177,26 +180,59 @@ public static void keepPlayerInLoadedEntityList(net.minecraft.entity.player.Enti |
177 | 180 | * <br> |
178 | 181 | * Even after adding the player to the world, the chunks may not load the player correctly. <br> |
179 | 182 | * <br> |
180 | | - * Without this, no model is shown in third person and the player is able to place blocks inside of him.<br> |
| 183 | + * Without this, no model is shown in third person<br> |
181 | 184 | * This state is fixed, once the player moves into a different chunk, since the new chunk adds the player to it's list. <br> |
182 | 185 | * <br> |
183 | 186 | * |
184 | 187 | * TLDR:<br> |
185 | | - * Adds the player to the chunk so he can't place any blocks inside himself <br> |
| 188 | + * Adds the player to the chunk so the player is shown in third person <br> |
186 | 189 | * <br> |
187 | 190 | * Side: Client |
188 | 191 | */ |
189 | 192 | @SideOnly(Side.CLIENT) |
190 | | - public static void addPlayerToChunk(net.minecraft.entity.player.EntityPlayer player) { |
| 193 | + public static void addPlayerToClientChunk(net.minecraft.entity.player.EntityPlayer player) { |
191 | 194 | int i = MathHelper.floor(player.posX / 16.0D); |
192 | | - int j = MathHelper.floor(player.posZ / 16.0D); |
193 | | - Chunk chunk=Minecraft.getMinecraft().world.getChunkFromChunkCoords(i, j); |
194 | | - for (int k = 0; k < chunk.getEntityLists().length; k++) { |
195 | | - if(chunk.getEntityLists()[k].contains(player)) { |
196 | | - return; |
197 | | - } |
| 195 | + int j = MathHelper.floor(player.posZ / 16.0D); |
| 196 | + Chunk chunk = Minecraft.getMinecraft().world.getChunkFromChunkCoords(i, j); |
| 197 | + for (int k = 0; k < chunk.getEntityLists().length; k++) { |
| 198 | + if (chunk.getEntityLists()[k].contains(player)) { |
| 199 | + return; |
| 200 | + } |
198 | 201 | } |
199 | | - chunk.addEntity(player); |
| 202 | + chunk.addEntity(player); |
200 | 203 | } |
201 | 204 |
|
| 205 | + /** |
| 206 | + * Just like {@link #addPlayerToClientChunk(EntityPlayer)}, adds the player to the chunk on the server. |
| 207 | + * This prevents the player from being able to place block inside of him |
| 208 | + * |
| 209 | + * Side: Server |
| 210 | + */ |
| 211 | + public static void addPlayerToServerChunk(net.minecraft.entity.player.EntityPlayerMP player) { |
| 212 | + int i = MathHelper.floor(player.posX / 16.0D); |
| 213 | + int j = MathHelper.floor(player.posZ / 16.0D); |
| 214 | + WorldServer world = player.getServerWorld(); |
| 215 | + Chunk chunk = world.getChunkFromChunkCoords(i, j); |
| 216 | + for (int k = 0; k < chunk.getEntityLists().length; k++) { |
| 217 | + if (chunk.getEntityLists()[k].contains(player)) { |
| 218 | + return; |
| 219 | + } |
| 220 | + } |
| 221 | + chunk.addEntity(player); |
| 222 | + } |
| 223 | + |
| 224 | + /** |
| 225 | + * Updates ticklist entries to the current world time, allowing them to not be stuck in a pressed state #136 |
| 226 | + */ |
| 227 | + public static void updateWorldServerTickListEntries() { |
| 228 | + MinecraftServer server=TASmod.getServerInstance(); |
| 229 | + for (WorldServer world : server.worlds) { |
| 230 | + AccessorWorldServer acworld=(AccessorWorldServer) world; |
| 231 | + |
| 232 | + for (NextTickListEntry nextticklistentry : acworld.getTickListEntries()) |
| 233 | + { |
| 234 | + nextticklistentry.setScheduledTime(world.getTotalWorldTime()); |
| 235 | + } |
| 236 | + } |
| 237 | + } |
202 | 238 | } |
0 commit comments