-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove hardcoded 128 block train update limit
- Loading branch information
Showing
6 changed files
with
76 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.lx862.mtrotp.config; | ||
|
||
import com.google.gson.GsonBuilder; | ||
import com.google.gson.JsonObject; | ||
import com.google.gson.JsonParser; | ||
import com.lx862.mtrotp.MTROTPClient; | ||
import net.fabricmc.loader.api.FabricLoader; | ||
|
||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.Collections; | ||
|
||
public class ServerConfig { | ||
private static final Path CONFIG_PATH = Paths.get(FabricLoader.getInstance().getConfigDir().toString(), "mtrotp_server.json"); | ||
public static int trainUpdateDistance = 128; | ||
|
||
public static void load() { | ||
if(!Files.exists(CONFIG_PATH)) { | ||
MTROTPClient.LOGGER.info("[MTR-OTP] Server config not found, generating one..."); | ||
writeConfig(); | ||
return; | ||
} | ||
|
||
MTROTPClient.LOGGER.info("[MTR-OTP] Reading server config..."); | ||
try { | ||
final JsonObject jsonConfig = JsonParser.parseString(String.join("", Files.readAllLines(CONFIG_PATH))).getAsJsonObject(); | ||
try { | ||
trainUpdateDistance = jsonConfig.get("trainUpdateDistance").getAsInt(); | ||
} catch (Exception ignored) {} | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
public static void writeConfig() { | ||
MTROTPClient.LOGGER.info("[MTR-OTP] Writing server config..."); | ||
final JsonObject jsonConfig = new JsonObject(); | ||
jsonConfig.addProperty("trainUpdateDistance", trainUpdateDistance); | ||
|
||
try { | ||
Files.write(CONFIG_PATH, Collections.singleton(new GsonBuilder().setPrettyPrinting().create().toJson(jsonConfig))); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/lx862/mtrotp/mixin/TrainServerMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.lx862.mtrotp.mixin; | ||
|
||
import com.lx862.mtrotp.config.ServerConfig; | ||
import mtr.data.TrainServer; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.ModifyArg; | ||
|
||
@Mixin(value = TrainServer.class, remap = false) | ||
public class TrainServerMixin { | ||
@ModifyArg(method = "handlePositions", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/phys/AABB;inflate(D)Lnet/minecraft/world/phys/AABB;")) | ||
public double modifyAABBBoundary(double d) { | ||
return ServerConfig.trainUpdateDistance; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters