Skip to content

Commit

Permalink
Add way to disable OversizedChunkWarnings and add more info (the worl…
Browse files Browse the repository at this point in the history
…d name) to the log message.

Also tells the player it's a good idea to not overload a chunk :D
  • Loading branch information
EverNife committed May 2, 2024
1 parent 6f59520 commit 9bdc2dd
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
25 changes: 22 additions & 3 deletions patches/net/minecraft/world/chunk/storage/RegionFile.java.patch
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
--- ../src-base/minecraft/net/minecraft/world/chunk/storage/RegionFile.java
+++ ../src-work/minecraft/net/minecraft/world/chunk/storage/RegionFile.java
@@ -1,373 +1,303 @@
@@ -1,373 +1,323 @@
package net.minecraft.world.chunk.storage;

-import java.io.BufferedInputStream;
Expand All @@ -19,6 +19,7 @@
+import java.io.*;
import java.util.ArrayList;
+import java.util.List;
+import java.util.regex.Pattern;
import java.util.zip.DeflaterOutputStream;
import java.util.zip.GZIPInputStream;
import java.util.zip.InflaterInputStream;
Expand All @@ -31,6 +32,7 @@
+ // Minecraft is limited to 256 sections per chunk. So 1MB. This can easily be override.
+ // So we extend this to use the REAL size when the count is maxed by seeking to that section and reading the length.
+ private static final boolean FORGE_ENABLE_EXTENDED_SAVE = CrucibleConfigs.configs.crucible_enableOversizedChunk;
+ private static final boolean FORGE_ENABLE_EXTENDED_WARNING = CrucibleConfigs.configs.crucible_warnOversizedChunk;
+ private static final long SECTOR_LENGTH = 4096L;
+ private static final byte[] EMPTY_SECTOR = new byte[(int) SECTOR_LENGTH];
private final File fileName;
Expand All @@ -42,6 +44,7 @@
private int sizeDelta;
private long lastModified;
private static final String __OBFID = "CL_00000381";
+ private String filePathName = null;

- public RegionFile(File p_i2001_1_)
- {
Expand Down Expand Up @@ -327,7 +330,21 @@
- int i1 = l >> 8;
- int j1 = l & 255;
- int k1 = (p_76706_4_ + 5) / 4096 + 1;
-
+ public String getFilePathName() {
+ if (filePathName == null){
+ String[] parts = this.fileName.getAbsolutePath().split(Pattern.quote("\\"));
+ StringBuilder stringBuilder = new StringBuilder();
+ for (int i = Math.max(0, parts.length - 3); i < parts.length; i++) {
+ stringBuilder.append(parts[i]);
+ if (i < parts.length - 1) {
+ stringBuilder.append("/");
+ }
+ }
+ filePathName = stringBuilder.toString();
+ }
+ return filePathName;
+ }

- if (k1 >= 256)
- {
- return;
Expand All @@ -348,7 +365,9 @@
- {
- this.write(i1, p_76706_3_, p_76706_4_);
+ if (sectorsNeeded >= 256) { //crucible - info: chunk has a limit of 255 sectors
+ CrucibleModContainer.logger.warn("[Crucible] Oversized Chunk at ({}, {})", x, z);
+ if (FORGE_ENABLE_EXTENDED_WARNING){
+ CrucibleModContainer.logger.warn("[Crucible] Found Oversized Chunk to be saved at [{}] in Chunk ({}, {})! Its recommended to not overload a chunk with too much data!", getFilePathName(), x, z);
+ }
+ if (!FORGE_ENABLE_EXTENDED_SAVE) {
+ return;
+ }
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/io/github/crucible/CrucibleConfigs.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,14 @@ public class CrucibleConfigs extends YamlConfig {
" discarted by vanilla mc rolling back the chunk to the previous valid disk version.",
"Why is it enabled by default?",
" - Oversized chunks are abused by dupers to possibly damage your server and economy, having it enabled by default",
" will prevent the headache of having to deal with duped items later plus it's warned in the console when",
" a oversized chunk is saved helping you to find it later, it also might save some player base with a big applied energistics system."})
" will prevent the headache of having to deal with duped items later.",
" It also might save some player's bases with a big applied energistics system"})
public boolean crucible_enableOversizedChunk = true;

@Comments({"Warn about Oversized Chunks",
"Log in the console when an oversized chunk is saved helping you to find it later."})
public boolean crucible_warnOversizedChunk = true;

@Comment("Size of cached chunk")
public int crucible_chunkCacheSize = 256;

Expand Down

0 comments on commit 9bdc2dd

Please sign in to comment.