Skip to content

Commit c757fd3

Browse files
ScribbleScribble
authored andcommitted
Fixes #136
Fixing #58 again ._.
1 parent b55b27d commit c757fd3

File tree

4 files changed

+72
-13
lines changed

4 files changed

+72
-13
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package de.scribble.lp.tasmod.mixin.accessors;
2+
3+
import java.util.Set;
4+
5+
import org.spongepowered.asm.mixin.Mixin;
6+
import org.spongepowered.asm.mixin.gen.Accessor;
7+
8+
import net.minecraft.world.NextTickListEntry;
9+
import net.minecraft.world.WorldServer;
10+
11+
@Mixin(WorldServer.class)
12+
public interface AccessorWorldServer {
13+
@Accessor("pendingTickListEntriesHashSet")
14+
public Set<NextTickListEntry> getTickListEntries();
15+
}

src/main/java/de/scribble/lp/tasmod/savestates/server/SavestateHandler.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,14 @@ public void loadState(int savestateIndex, boolean tickrate0, boolean changeIndex
313313
// Send a notification that the savestate has been loaded
314314
server.getPlayerList().sendMessage(new TextComponentString(TextFormatting.GREEN + "Savestate " + indexToLoad + " loaded"));
315315

316+
// Add players to the chunk
317+
server.getPlayerList().getPlayers().forEach(player->{
318+
SavestatesChunkControl.addPlayerToServerChunk(player);
319+
});
320+
321+
// Updating redstone component timers to the new world time (#136)
322+
SavestatesChunkControl.updateWorldServerTickListEntries();
323+
316324
WorldServer[] worlds = DimensionManager.getWorlds();
317325

318326
for (WorldServer world : worlds) {
@@ -548,6 +556,6 @@ public static void playerLoadSavestateEventServer() {
548556

549557
@SideOnly(Side.CLIENT)
550558
public static void playerLoadSavestateEventClient() {
551-
SavestatesChunkControl.addPlayerToChunk(Minecraft.getMinecraft().player);
559+
SavestatesChunkControl.addPlayerToClientChunk(Minecraft.getMinecraft().player);
552560
}
553561
}

src/main/java/de/scribble/lp/tasmod/savestates/server/chunkloading/SavestatesChunkControl.java

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
import java.util.List;
44

5+
import de.scribble.lp.tasmod.TASmod;
56
import de.scribble.lp.tasmod.duck.ChunkProviderDuck;
67
import de.scribble.lp.tasmod.mixin.accessors.AccessorSaveHandler;
78
import de.scribble.lp.tasmod.mixin.accessors.AccessorWorld;
9+
import de.scribble.lp.tasmod.mixin.accessors.AccessorWorldServer;
810
import de.scribble.lp.tasmod.mixin.savestates.MixinChunkProviderClient;
911
import de.scribble.lp.tasmod.mixin.savestates.MixinChunkProviderServer;
1012
import net.minecraft.client.Minecraft;
@@ -13,6 +15,7 @@
1315
import net.minecraft.entity.player.EntityPlayerMP;
1416
import net.minecraft.server.MinecraftServer;
1517
import net.minecraft.util.math.MathHelper;
18+
import net.minecraft.world.NextTickListEntry;
1619
import net.minecraft.world.WorldServer;
1720
import net.minecraft.world.chunk.Chunk;
1821
import net.minecraft.world.gen.ChunkProviderServer;
@@ -177,26 +180,59 @@ public static void keepPlayerInLoadedEntityList(net.minecraft.entity.player.Enti
177180
* <br>
178181
* Even after adding the player to the world, the chunks may not load the player correctly. <br>
179182
* <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>
181184
* This state is fixed, once the player moves into a different chunk, since the new chunk adds the player to it's list. <br>
182185
* <br>
183186
*
184187
* 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>
186189
* <br>
187190
* Side: Client
188191
*/
189192
@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) {
191194
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+
}
198201
}
199-
chunk.addEntity(player);
202+
chunk.addEntity(player);
200203
}
201204

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+
}
202238
}

src/main/resources/mixins.tasmod.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
"accessors.AccessorEntity",
2727
"accessors.AccessorMinecraftServer",
2828
"accessors.AccessorSaveHandler",
29-
"accessors.AccessorWorld"
30-
29+
"accessors.AccessorWorld",
30+
"accessors.AccessorWorldServer"
3131

3232
],
3333
"client": [

0 commit comments

Comments
 (0)