Skip to content

Commit

Permalink
1.20.2 bump, optimise search algorithm and increase search radius fro…
Browse files Browse the repository at this point in the history
…m 256 -> 512. Implement #2.
  • Loading branch information
SamB440 committed Oct 17, 2023
1 parent 66c455a commit 1fc7642
Show file tree
Hide file tree
Showing 17 changed files with 356 additions and 694 deletions.
827 changes: 159 additions & 668 deletions LICENSE

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Huge Structure Blocks

A mod that:
- Increases maximum structure size to 512 blocks
- Optimises the corner search algorithm
- Removes the Jigsaw depth limit
- Removes the 128 block distance limit from structure features/pools

## Download
You can get the latest release from:
- [GitHub](https://github.com/SamB440/huge-structure-blocks/releases)
- [CurseForge](https://legacy.curseforge.com/minecraft/mc-mods/huge-structure-blocks)
- [Modrinth](https://modrinth.com/mod/huge-structure-blocks)

## Usage

Just plop it in your mods folder. You now have huge structure blocks of up to 512 blocks!
Expand Down
6 changes: 5 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id 'java'
id 'fabric-loom' version '1.2-SNAPSHOT'
id 'fabric-loom' version '1.4-SNAPSHOT'
id 'maven-publish'
}

Expand Down Expand Up @@ -29,6 +29,10 @@ dependencies {
// You may need to force-disable transitiveness on them.
}

loom {
accessWidenerPath = file("src/main/resources/hugestructureblocks.accesswidener")
}

processResources {
inputs.property "version", project.version

Expand Down
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ org.gradle.jvmargs=-Xmx2G

# Fabric Properties
# check these on https://fabricmc.net/use
minecraft_version=1.20.1
yarn_mappings=1.20.1+build.5
loader_version=0.14.21
minecraft_version=1.20.2
yarn_mappings=1.20.2+build.4
loader_version=0.14.23

#Fabric api
fabric_version=0.84.0+1.20.1
fabric_version=0.90.0+1.20.2

# Mod Properties
mod_version = 1.0.8
mod_version = 1.0.9
maven_group = com.convallyria
archives_base_name = huge-structure-blocks

Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
3 changes: 2 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
22 changes: 13 additions & 9 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ done
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down Expand Up @@ -130,26 +131,29 @@ location of your Java installation."
fi
else
JAVACMD=java
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
if ! command -v java >/dev/null 2>&1
then
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
fi

# Increase the maximum file descriptors if we can.
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC2039,SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC2039,SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down Expand Up @@ -198,11 +202,11 @@ fi
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
# double quotes to make sure that they get re-expanded; and
# * put everything else in single quotes, so that it's not re-expanded.
# Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.

set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ public class HugeStructureBlocksMod implements ModInitializer {
public static final String NAME = "Huge Structure Blocks";
public static final String VERSION = "1.0.0";

public static final int NEW_STRUCTURE_SIZE = 512;

public static final Logger LOGGER = LogManager.getLogger();

@Override
public void onInitialize() {
LOGGER.info("Huge Structure Blocks is now making your structure blocks even bigger!");
LOGGER.info("New structure size = " + NEW_STRUCTURE_SIZE);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.convallyria.hugestructureblocks.mixin.structure;

import com.convallyria.hugestructureblocks.HugeStructureBlocksMod;
import net.minecraft.structure.pool.StructurePoolBasedGenerator;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.Constant;
import org.spongepowered.asm.mixin.injection.ModifyConstant;

@Mixin(value = StructurePoolBasedGenerator.class, priority = 999)
public class JigsawPlacementUnlimit {

@ModifyConstant(method = "generate(Lnet/minecraft/server/world/ServerWorld;Lnet/minecraft/registry/entry/RegistryEntry;Lnet/minecraft/util/Identifier;ILnet/minecraft/util/math/BlockPos;Z)Z", constant = @Constant(intValue = 128), require = 0)
private static int changeMaxGenDistance(int value) {
return HugeStructureBlocksMod.NEW_STRUCTURE_SIZE;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package com.convallyria.hugestructureblocks.mixin.structure;

import com.convallyria.hugestructureblocks.HugeStructureBlocksMod;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.structure.pool.StructurePool;
import net.minecraft.util.Identifier;
import net.minecraft.util.dynamic.Codecs;
import net.minecraft.world.Heightmap;
import net.minecraft.world.gen.heightprovider.HeightProvider;
import net.minecraft.world.gen.structure.JigsawStructure;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Mutable;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.Constant;
import org.spongepowered.asm.mixin.injection.ModifyConstant;

import static net.minecraft.world.gen.structure.Structure.configCodecBuilder;

@Mixin(value = JigsawStructure.class, priority = 999)
public class JigsawStructureUnlimit {

@Shadow
@Final
@Mutable
// Is this even used?
public static final int MAX_SIZE = Integer.MAX_VALUE;

// I tried so many ways to do this without replacing the codec but nothing worked.
@Shadow
@Final
@Mutable
public static final Codec<JigsawStructure> CODEC = Codecs.validate(
RecordCodecBuilder.mapCodec(
instance -> instance.group(
configCodecBuilder(instance),
StructurePool.REGISTRY_CODEC.fieldOf("start_pool").forGetter(structure -> structure.startPool),
Identifier.CODEC.optionalFieldOf("start_jigsaw_name").forGetter(structure -> structure.startJigsawName),
Codec.INT.fieldOf("size").forGetter(structure -> structure.size),
HeightProvider.CODEC.fieldOf("start_height").forGetter(structure -> structure.startHeight),
Codec.BOOL.fieldOf("use_expansion_hack").forGetter(structure -> structure.useExpansionHack),
Heightmap.Type.CODEC.optionalFieldOf("project_start_to_heightmap").forGetter(structure -> structure.projectStartToHeightmap),
Codec.INT.fieldOf("max_distance_from_center").forGetter(structure -> structure.maxDistanceFromCenter)
)
.apply(instance, JigsawStructure::new)
),
JigsawStructure::validate
)
.codec();

@ModifyConstant(method = "<init>(Lnet/minecraft/world/gen/structure/Structure$Config;Lnet/minecraft/registry/entry/RegistryEntry;ILnet/minecraft/world/gen/heightprovider/HeightProvider;Z)V", constant = @Constant(intValue = 80), require = 0)
private static int init1(int value) {
return HugeStructureBlocksMod.NEW_STRUCTURE_SIZE;
}

@ModifyConstant(method = "<init>(Lnet/minecraft/world/gen/structure/Structure$Config;Lnet/minecraft/registry/entry/RegistryEntry;ILnet/minecraft/world/gen/heightprovider/HeightProvider;ZLnet/minecraft/world/Heightmap$Type;)V", constant = @Constant(intValue = 80), require = 0)
private static int init2(int value) {
return HugeStructureBlocksMod.NEW_STRUCTURE_SIZE;
}

@ModifyConstant(method = "validate", constant = @Constant(intValue = 128), require = 0)
private static int maxDistanceFromCenter(int value) {
return HugeStructureBlocksMod.NEW_STRUCTURE_SIZE;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.convallyria.hugestructureblocks.mixin.structure;

import net.minecraft.server.command.PlaceCommand;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.Constant;
import org.spongepowered.asm.mixin.injection.ModifyConstant;

@Mixin(value = PlaceCommand.class, priority = 999)
public class PlaceCommandUnlimit {

@ModifyConstant(method = "register", constant = @Constant(intValue = 7), require = 0)
private static int changeJigsawDepth(int value) {
return Integer.MAX_VALUE;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.convallyria.hugestructureblocks.mixin.structure;

import com.convallyria.hugestructureblocks.HugeStructureBlocksMod;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.render.block.entity.StructureBlockBlockEntityRenderer;
Expand All @@ -17,6 +18,6 @@ public class StructureBlockRenderMixin {
@ModifyConstant(method = "getRenderDistance", constant = @Constant(intValue = 96), require = 0)
@Environment(EnvType.CLIENT)
public int getRenderDistance(int value) {
return 256;
return HugeStructureBlocksMod.NEW_STRUCTURE_SIZE / 2;
}
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,58 @@
package com.convallyria.hugestructureblocks.mixin.structure;

import com.convallyria.hugestructureblocks.HugeStructureBlocksMod;
import net.minecraft.block.entity.StructureBlockBlockEntity;
import net.minecraft.block.enums.StructureBlockMode;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.injection.Constant;
import org.spongepowered.asm.mixin.injection.ModifyConstant;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Stream;

@Mixin(value = StructureBlockBlockEntity.class, priority = 999)
public class StructureBlockUnlimit {

@ModifyConstant(method = "readNbt", constant = @Constant(intValue = 48), require = 0)
public int readNbtUpper(int value) {
return 512;
return HugeStructureBlocksMod.NEW_STRUCTURE_SIZE;
}

@ModifyConstant(method = "readNbt", constant = @Constant(intValue = -48), require = 0)
public int readNbtLower(int value) {
return -512;
return -HugeStructureBlocksMod.NEW_STRUCTURE_SIZE;
}

/**
* @author SamB440
* @reason Optimise searching of structure blocks by searching from the structure block outwards instead of from min corner to max (and reduce streams).
*/
@Overwrite
private Stream<BlockPos> streamCornerPos(BlockPos min, BlockPos max) {
StructureBlockBlockEntity blockEntity = (StructureBlockBlockEntity) (Object) this;
final World level = blockEntity.getWorld();
if (level == null) return Stream.empty();
final BlockPos middle = blockEntity.getPos();
List<BlockPos> blocks = new ArrayList<>(2);
final int maxSearch = detectSize(-1) + 1;
BlockPos.findClosest(middle, maxSearch, Math.min(maxSearch, level.getHeight() + 1), pos -> {
if (level.getBlockEntity(pos) instanceof StructureBlockBlockEntity block) {
if (block.getMode() == StructureBlockMode.CORNER && Objects.equals(blockEntity.getTemplateName(), block.getTemplateName())) {
blocks.add(block.getPos());
}
}
return blocks.size() == 2;
});
return blocks.stream();
}

@ModifyConstant(method = "detectStructureSize", constant = @Constant(intValue = 80), require = 0)
public int detectSize(int value) {
return 256;
return HugeStructureBlocksMod.NEW_STRUCTURE_SIZE;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.convallyria.hugestructureblocks.mixin.structure.packet;

import com.convallyria.hugestructureblocks.HugeStructureBlocksMod;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.network.packet.c2s.play.UpdateStructureBlockC2SPacket;
import net.minecraft.util.math.BlockPos;
Expand Down Expand Up @@ -31,16 +32,17 @@ public class ClientUpdateStructureBlockUnlimit {

@Inject(method = "<init>(Lnet/minecraft/network/PacketByteBuf;)V", at = @At("RETURN"), require = 0)
public void readInts(PacketByteBuf buf, CallbackInfo ci) {
final int newStructureSize = HugeStructureBlocksMod.NEW_STRUCTURE_SIZE;
this.offset = new BlockPos(
MathHelper.clamp(buf.readInt(), -512, 512),
MathHelper.clamp(buf.readInt(), -512, 512),
MathHelper.clamp(buf.readInt(), -512, 512)
MathHelper.clamp(buf.readInt(), -newStructureSize, newStructureSize),
MathHelper.clamp(buf.readInt(), -newStructureSize, newStructureSize),
MathHelper.clamp(buf.readInt(), -newStructureSize, newStructureSize)
);

this.size = new BlockPos(
MathHelper.clamp(buf.readInt(), 0, 512),
MathHelper.clamp(buf.readInt(), 0, 512),
MathHelper.clamp(buf.readInt(), 0, 512)
MathHelper.clamp(buf.readInt(), 0, newStructureSize),
MathHelper.clamp(buf.readInt(), 0, newStructureSize),
MathHelper.clamp(buf.readInt(), 0, newStructureSize)
);
}

Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"sources": "https://github.com/SamB440/huge-structure-blocks",
"issues": "https://github.com/SamB440/huge-structure-blocks/issues"
},
"license": "LGPL-3.0",

"icon": "assets/hugestructureblocks/icon.png",

Expand All @@ -22,6 +23,7 @@
"com.convallyria.hugestructureblocks.HugeStructureBlocksMod"
]
},
"accessWidener" : "hugestructureblocks.accesswidener",
"mixins": [
"hugestructureblocks.mixins.json"
],
Expand Down
9 changes: 9 additions & 0 deletions src/main/resources/hugestructureblocks.accesswidener
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
accessWidener v2 named
accessible method net/minecraft/world/gen/structure/JigsawStructure validate (Lnet/minecraft/world/gen/structure/JigsawStructure;)Lcom/mojang/serialization/DataResult;
accessible field net/minecraft/world/gen/structure/JigsawStructure startPool Lnet/minecraft/registry/entry/RegistryEntry;
accessible field net/minecraft/world/gen/structure/JigsawStructure startJigsawName Ljava/util/Optional;
accessible field net/minecraft/world/gen/structure/JigsawStructure size I
accessible field net/minecraft/world/gen/structure/JigsawStructure startHeight Lnet/minecraft/world/gen/heightprovider/HeightProvider;
accessible field net/minecraft/world/gen/structure/JigsawStructure useExpansionHack Z
accessible field net/minecraft/world/gen/structure/JigsawStructure projectStartToHeightmap Ljava/util/Optional;
accessible field net/minecraft/world/gen/structure/JigsawStructure maxDistanceFromCenter I
3 changes: 3 additions & 0 deletions src/main/resources/hugestructureblocks.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
"package": "com.convallyria.hugestructureblocks.mixin",
"compatibilityLevel": "JAVA_17",
"mixins": [
"structure.JigsawPlacementUnlimit",
"structure.JigsawStructureUnlimit",
"structure.PlaceCommandUnlimit",
"structure.StructureBlockUnlimit",
"structure.packet.ClientUpdateStructureBlockUnlimit"
],
Expand Down

0 comments on commit 1fc7642

Please sign in to comment.