Add project files
This commit is contained in:
parent
1d47ac0466
commit
8d1c9da4ba
18 changed files with 757 additions and 1 deletions
32
src/main/java/net/chaoticbyte/truncated/Truncated.java
Normal file
32
src/main/java/net/chaoticbyte/truncated/Truncated.java
Normal file
|
@ -0,0 +1,32 @@
|
|||
package net.chaoticbyte.truncated;
|
||||
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
|
||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
|
||||
import net.fabricmc.fabric.api.gamerule.v1.GameRuleFactory;
|
||||
import net.fabricmc.fabric.api.gamerule.v1.GameRuleRegistry;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.world.GameRules;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class Truncated implements ModInitializer {
|
||||
public static final String MOD_ID = "truncated";
|
||||
public static final GameRules.Key<GameRules.IntRule> CHUNK_GEN_LIMIT_KEY = GameRuleRegistry.register(
|
||||
"chunkGenerationLimit", GameRules.Category.MISC, GameRuleFactory.createIntRule((28_000_000 / 16) - 1 ));
|
||||
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
|
||||
|
||||
private static MinecraftServer server;
|
||||
|
||||
public static int getLimit() {
|
||||
return server.getGameRules().getInt(CHUNK_GEN_LIMIT_KEY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
ServerLifecycleEvents.SERVER_STARTING.register(minecraftServer -> {
|
||||
server = minecraftServer;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package net.chaoticbyte.truncated.mixin;
|
||||
|
||||
import net.chaoticbyte.truncated.Truncated;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.ChunkRegion;
|
||||
import net.minecraft.world.StructureWorldAccess;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
@Mixin(ChunkRegion.class)
|
||||
public abstract class ChunkRegionMixin implements StructureWorldAccess {
|
||||
|
||||
@Inject(
|
||||
method = "isValidForSetBlock",
|
||||
at = @At("HEAD"),
|
||||
cancellable = true
|
||||
)
|
||||
public void isValidForSetBlock(BlockPos pos, CallbackInfoReturnable<Boolean> ci) {
|
||||
var limit = Truncated.getLimit();
|
||||
var x = pos.getX() / 16;
|
||||
var z = pos.getZ() / 16;
|
||||
if (x > limit || x < -limit || z > limit || z < -limit) {
|
||||
ci.setReturnValue(false);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
package net.chaoticbyte.truncated.mixin;
|
||||
|
||||
import net.chaoticbyte.truncated.Truncated;
|
||||
import net.minecraft.registry.entry.RegistryEntry;
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
import net.minecraft.world.HeightLimitView;
|
||||
import net.minecraft.world.Heightmap;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraft.world.biome.GenerationSettings;
|
||||
import net.minecraft.world.biome.source.BiomeSource;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
import net.minecraft.world.gen.StructureAccessor;
|
||||
import net.minecraft.world.gen.chunk.*;
|
||||
import net.minecraft.world.gen.noise.NoiseConfig;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Function;
|
||||
|
||||
@Mixin(FlatChunkGenerator.class)
|
||||
public abstract class FlatChunkGeneratorMixin extends ChunkGenerator {
|
||||
|
||||
@Shadow public abstract VerticalBlockSample getColumnSample(int x, int z, HeightLimitView world, NoiseConfig noiseConfig);
|
||||
|
||||
public FlatChunkGeneratorMixin(BiomeSource biomeSource, Function<RegistryEntry<Biome>, GenerationSettings> generationSettingsGetter) {
|
||||
super(biomeSource, generationSettingsGetter);
|
||||
}
|
||||
|
||||
@Inject(
|
||||
method = "populateNoise(Lnet/minecraft/world/gen/chunk/Blender;Lnet/minecraft/world/gen/noise/NoiseConfig;Lnet/minecraft/world/gen/StructureAccessor;Lnet/minecraft/world/chunk/Chunk;)Ljava/util/concurrent/CompletableFuture;",
|
||||
at = @At("HEAD"),
|
||||
cancellable = true
|
||||
)
|
||||
public void populateNoise(Blender blender, NoiseConfig noiseConfig, StructureAccessor structureAccessor, Chunk chunk, CallbackInfoReturnable<CompletableFuture<Chunk>> ci) {
|
||||
ChunkPos p = chunk.getPos();
|
||||
int limit = Truncated.getLimit();
|
||||
if (p.x > limit || p.x < -limit || p.z > limit || p.z < -limit) {
|
||||
ci.setReturnValue(CompletableFuture.completedFuture(chunk));
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(
|
||||
method = "getHeight",
|
||||
at = @At("HEAD"),
|
||||
cancellable = true
|
||||
)
|
||||
public void getHeight(int x, int z, Heightmap.Type heightmap, HeightLimitView world, NoiseConfig noiseConfig, CallbackInfoReturnable<Integer> ci) {
|
||||
int limit = Truncated.getLimit();
|
||||
if (x > limit || x < -limit || z > limit || z < -limit) {
|
||||
ci.setReturnValue(0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
package net.chaoticbyte.truncated.mixin;
|
||||
|
||||
import net.chaoticbyte.truncated.Truncated;
|
||||
import net.minecraft.registry.entry.RegistryEntry;
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
import net.minecraft.world.HeightLimitView;
|
||||
import net.minecraft.world.Heightmap;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraft.world.biome.GenerationSettings;
|
||||
import net.minecraft.world.biome.source.BiomeSource;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
import net.minecraft.world.gen.StructureAccessor;
|
||||
import net.minecraft.world.gen.chunk.Blender;
|
||||
import net.minecraft.world.gen.chunk.ChunkGenerator;
|
||||
import net.minecraft.world.gen.chunk.NoiseChunkGenerator;
|
||||
import net.minecraft.world.gen.chunk.VerticalBlockSample;
|
||||
import net.minecraft.world.gen.noise.NoiseConfig;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Function;
|
||||
|
||||
@Mixin(NoiseChunkGenerator.class)
|
||||
public abstract class NoiseChunkGeneratorMixin extends ChunkGenerator {
|
||||
|
||||
@Shadow public abstract VerticalBlockSample getColumnSample(int x, int z, HeightLimitView world, NoiseConfig noiseConfig);
|
||||
|
||||
public NoiseChunkGeneratorMixin(BiomeSource biomeSource, Function<RegistryEntry<Biome>, GenerationSettings> generationSettingsGetter) {
|
||||
super(biomeSource, generationSettingsGetter);
|
||||
}
|
||||
|
||||
@Inject(
|
||||
method = "populateNoise(Lnet/minecraft/world/gen/chunk/Blender;Lnet/minecraft/world/gen/noise/NoiseConfig;Lnet/minecraft/world/gen/StructureAccessor;Lnet/minecraft/world/chunk/Chunk;)Ljava/util/concurrent/CompletableFuture;",
|
||||
at = @At("HEAD"),
|
||||
cancellable = true
|
||||
)
|
||||
public void populateNoise(Blender blender, NoiseConfig noiseConfig, StructureAccessor structureAccessor, Chunk chunk, CallbackInfoReturnable<CompletableFuture<Chunk>> ci) {
|
||||
ChunkPos p = chunk.getPos();
|
||||
int limit = Truncated.getLimit();
|
||||
if (p.x > limit || p.x < -limit || p.z > limit || p.z < -limit) {
|
||||
ci.setReturnValue(CompletableFuture.completedFuture(chunk));
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(
|
||||
method = "populateBiomes(Lnet/minecraft/world/gen/noise/NoiseConfig;Lnet/minecraft/world/gen/chunk/Blender;Lnet/minecraft/world/gen/StructureAccessor;Lnet/minecraft/world/chunk/Chunk;)Ljava/util/concurrent/CompletableFuture;",
|
||||
at = @At("HEAD"),
|
||||
cancellable = true
|
||||
)
|
||||
public void populateBiomes(NoiseConfig noiseConfig, Blender blender, StructureAccessor structureAccessor, Chunk chunk, CallbackInfoReturnable<CompletableFuture<Chunk>> ci) {
|
||||
ChunkPos p = chunk.getPos();
|
||||
int limit = Truncated.getLimit();
|
||||
if (p.x > limit || p.x < -limit || p.z > limit || p.z < -limit) {
|
||||
ci.setReturnValue(CompletableFuture.completedFuture(chunk));
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(
|
||||
method = "getHeight",
|
||||
at = @At("HEAD"),
|
||||
cancellable = true
|
||||
)
|
||||
public void getHeight(int x, int z, Heightmap.Type heightmap, HeightLimitView world, NoiseConfig noiseConfig, CallbackInfoReturnable<Integer> ci) {
|
||||
int limit = Truncated.getLimit();
|
||||
if (x > limit || x < -limit || z > limit || z < -limit) {
|
||||
ci.setReturnValue(0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
BIN
src/main/resources/assets/truncated/icon.png
Normal file
BIN
src/main/resources/assets/truncated/icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.3 KiB |
3
src/main/resources/assets/truncated/lang/en_us.json
Normal file
3
src/main/resources/assets/truncated/lang/en_us.json
Normal file
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"gamerule.chunkGenerationLimit": "Chunk Generation Limit"
|
||||
}
|
31
src/main/resources/fabric.mod.json
Normal file
31
src/main/resources/fabric.mod.json
Normal file
|
@ -0,0 +1,31 @@
|
|||
{
|
||||
"schemaVersion": 1,
|
||||
"id": "truncated",
|
||||
"version": "${version}",
|
||||
"name": "Truncated",
|
||||
"description": "Limit your generated world size! Configurable via the gamerule chunkGeneratorLimit.",
|
||||
"authors": ["ChaoticByte"],
|
||||
"contact": {
|
||||
"issues": "https://github.com/ChaoticByte/truncated/issues",
|
||||
"sources": "https://github.com/ChaoticByte/truncated"
|
||||
},
|
||||
"license": "MIT",
|
||||
"icon": "assets/truncated/icon.png",
|
||||
"environment": "*",
|
||||
"entrypoints": {
|
||||
"main": [
|
||||
"net.chaoticbyte.truncated.Truncated"
|
||||
],
|
||||
"client": []
|
||||
},
|
||||
"mixins": [
|
||||
"truncated.mixins.json"
|
||||
],
|
||||
"depends": {
|
||||
"fabricloader": ">=0.16.5",
|
||||
"minecraft": "~1.21.1",
|
||||
"java": ">=21",
|
||||
"fabric-api": "*"
|
||||
},
|
||||
"suggests": {}
|
||||
}
|
13
src/main/resources/truncated.mixins.json
Normal file
13
src/main/resources/truncated.mixins.json
Normal file
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
"required": true,
|
||||
"package": "net.chaoticbyte.truncated.mixin",
|
||||
"compatibilityLevel": "JAVA_21",
|
||||
"mixins": [
|
||||
"FlatChunkGeneratorMixin",
|
||||
"NoiseChunkGeneratorMixin",
|
||||
"ChunkRegionMixin"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue