Skip to content
Draft
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ dependencies {
// tasmod dependencies
embed "com.dselent:bigarraylist:1.6"
embed "com.github.KaptainWutax:SeedUtils:b6a383113c"

implementation "com.google.code.gson:gson:2.14.0"

// loom dependencies
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings ploceus.mcpMappings(project.mcp_channel, project.mcp_mcversion, project.mcp_build)
Expand Down
31 changes: 22 additions & 9 deletions src/main/java/com/minecrafttas/tasmod/TASmod.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.minecrafttas.tasmod.handlers.PlayUntilHandler;
import com.minecrafttas.tasmod.ktrng.GlobalRNG;
import com.minecrafttas.tasmod.ktrng.builtin.MathRNG;
import com.minecrafttas.tasmod.ktrng.builtin.SquidRNG;
import com.minecrafttas.tasmod.ktrng.builtin.WorldSeedRNG;
import com.minecrafttas.tasmod.ktrng.events.KillTheRNGMonitor;
import com.minecrafttas.tasmod.ktrng.handlers.UUIDHandler;
Expand All @@ -42,10 +43,13 @@
import com.minecrafttas.tasmod.savestates.handlers.SavestateGuiHandlerServer;
import com.minecrafttas.tasmod.savestates.handlers.SavestateResourcePackHandler;
import com.minecrafttas.tasmod.savestates.storage.builtin.ClientMotionStorage;
import com.minecrafttas.tasmod.savestates.storage.builtin.EntityBatSpawnPositionStorage;
import com.minecrafttas.tasmod.savestates.storage.builtin.EntitySquidRotationStorage;
import com.minecrafttas.tasmod.savestates.storage.builtin.EntityTickTimersStorage;
import com.minecrafttas.tasmod.savestates.storage.builtin.EntityAiTaskStorage;
import com.minecrafttas.tasmod.savestates.storage.builtin.EntityStorage;
import com.minecrafttas.tasmod.savestates.storage.builtin.KTRNGSeedStorage;
import com.minecrafttas.tasmod.savestates.storage.builtin.entity.BatSpawnPositionSubStorage;
import com.minecrafttas.tasmod.savestates.storage.builtin.entity.CreeperDetonateSubStorage;
import com.minecrafttas.tasmod.savestates.storage.builtin.entity.LivingTickTimersSubStorage;
import com.minecrafttas.tasmod.savestates.storage.builtin.entity.SquidRotationSubStorage;
import com.minecrafttas.tasmod.tickratechanger.TickrateChangerServer;
import com.minecrafttas.tasmod.ticksync.TickSyncServer;
import com.minecrafttas.tasmod.util.LoggerMarkers;
Expand Down Expand Up @@ -102,14 +106,14 @@ public class TASmod implements ModInitializer, EventServerStart, EventServerInit
public static GlobalRNG globalRandomness;

public static KTRNGSeedStorage seedStorage = new KTRNGSeedStorage();
public static EntityTickTimersStorage entityTickTimers = new EntityTickTimersStorage();
public static EntityBatSpawnPositionStorage entityBatSpawnPositionStorage = new EntityBatSpawnPositionStorage();
public static EntitySquidRotationStorage entitySquidRotationStorage = new EntitySquidRotationStorage();
public static EntityAiTaskStorage entityAiTaskStorage = new EntityAiTaskStorage();

public static MathRNG mathRandomness = new MathRNG(0);

public static WorldSeedRNG worldSeedRandomness = new WorldSeedRNG(0);

public static SquidRNG squidRNG = new SquidRNG(0L);

public static KillTheRNGMonitor debugRand = new KillTheRNGMonitor();

public static UUIDHandler uuidHandler = new UUIDHandler();
Expand Down Expand Up @@ -173,6 +177,7 @@ public void onServerStart(MinecraftServer server) {
EventListenerRegistry.register(globalRandomness);
}
mathRandomness = new MathRNG(0);
squidRNG.setSeed(globalRandomness.getCurrentSeed() + 1000L);
}

@Override
Expand Down Expand Up @@ -239,9 +244,17 @@ public void onServerStop(MinecraftServer mcserver) {
private void registerSavestateStorage() {
TASmodAPIRegistry.SAVESTATE_STORAGE.register(motionStorage);
TASmodAPIRegistry.SAVESTATE_STORAGE.register(seedStorage);
TASmodAPIRegistry.SAVESTATE_STORAGE.register(entityTickTimers);
TASmodAPIRegistry.SAVESTATE_STORAGE.register(entityBatSpawnPositionStorage);
TASmodAPIRegistry.SAVESTATE_STORAGE.register(entitySquidRotationStorage);
//@formatter:off
TASmodAPIRegistry.SAVESTATE_STORAGE.register(
new EntityStorage(
new BatSpawnPositionSubStorage(),
new CreeperDetonateSubStorage(),
new SquidRotationSubStorage(),
new LivingTickTimersSubStorage()
)
);
//@formatter:on
TASmodAPIRegistry.SAVESTATE_STORAGE.register(entityAiTaskStorage);
}

public static MinecraftServer getServerInstance() {
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/com/minecrafttas/tasmod/ktrng/builtin/SquidRNG.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.minecrafttas.tasmod.ktrng.builtin;

import com.minecrafttas.tasmod.ktrng.RandomBase;

public class SquidRNG extends RandomBase {

public SquidRNG(long l) {
super(l);
}

@Override
public String getExtensionName() {
return "SquidRNG";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.spongepowered.asm.mixin.injection.At;

import com.llamalad7.mixinextras.injector.v2.WrapWithCondition;
import com.minecrafttas.tasmod.TASmod;

import net.minecraft.entity.passive.EntitySquid;

Expand All @@ -14,6 +15,9 @@ public class MixinEntitySquid {

@WrapWithCondition(method = "<init>", at = @At(value = "INVOKE", target = "Ljava/util/Random;setSeed(J)V"))
public boolean remove_setSeed(Random rand, long seed) {
if (TASmod.squidRNG.nextInt(1000) == 0) {
TASmod.LOGGER.error("SQUIDS ARE EVIL!!");
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,17 @@

public abstract class SavestateStorageExtensionBase implements Registerable {
protected final Logger logger = TASmod.LOGGER;
protected final Gson json = JsonUtils.getJsonInstance();
protected final Gson gsonInstance;

public final Path fileName;

public SavestateStorageExtensionBase(String fileName) {
public SavestateStorageExtensionBase(String filename) {
this(filename, JsonUtils.getGsonInstance());
}

public SavestateStorageExtensionBase(String fileName, Gson gson) {
this.fileName = Paths.get(fileName);
this.gsonInstance = gson;
}

public abstract JsonObject onSavestate(MinecraftServer server, JsonObject dataToSave);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void onServerSavestate(MinecraftServer server, SavestatePaths paths) {
JsonObject dataToSave = storage.onSavestate(server, new JsonObject());

try {
JsonUtils.saveJson(dataPath, dataToSave);
JsonUtils.saveJson(dataPath, dataToSave, storage.gsonInstance);
} catch (IOException e) {
throw new SavestateException(e, "Can't save %s from %s extension", storage.fileName, storage.getExtensionName());
}
Expand Down Expand Up @@ -71,7 +71,7 @@ private void load(SavestatePaths paths) {

JsonObject loadedData;
try {
loadedData = JsonUtils.loadJson(dataPath);
loadedData = JsonUtils.loadJson(dataPath, storage.gsonInstance);
} catch (IOException e) {
throw new LoadstateException(e, "Can't load %s in %s extension", storage.fileName, storage.getExtensionName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public JsonObject onSavestate(MinecraftServer server, JsonObject dataToSave) {
if (player.getName().equals(server.getServerOwner())) {
uuid = "singleplayer";
}
dataToSave.add(uuid, json.toJsonTree(data));
dataToSave.add(uuid, gsonInstance.toJsonTree(data));

} catch (TimeoutException e) {
throw new SavestateException(e, "Writing client motion for %s timed out!", player.getName());
Expand All @@ -92,7 +92,7 @@ public void onLoadstatePost(MinecraftServer server, JsonObject loadedData) {

for (Entry<String, JsonElement> motionDataJsonElement : loadedData.entrySet()) {
String playerUUID = motionDataJsonElement.getKey();
MotionData motionData = json.fromJson(motionDataJsonElement.getValue(), MotionData.class);
MotionData motionData = gsonInstance.fromJson(motionDataJsonElement.getValue(), MotionData.class);

EntityPlayerMP player;
if (playerUUID.equals("singleplayer")) {
Expand Down
Loading