generated from FabricMC/fabric-example-mod
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1.20.2 bump, optimise search algorithm and increase search radius fro…
…m 256 -> 512. Implement #2.
- Loading branch information
Showing
17 changed files
with
356 additions
and
694 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
Binary file not shown.
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 |
---|---|---|
@@ -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 |
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
16 changes: 16 additions & 0 deletions
16
...main/java/com/convallyria/hugestructureblocks/mixin/structure/JigsawPlacementUnlimit.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,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; | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
...main/java/com/convallyria/hugestructureblocks/mixin/structure/JigsawStructureUnlimit.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,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; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/convallyria/hugestructureblocks/mixin/structure/PlaceCommandUnlimit.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.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; | ||
} | ||
} |
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
39 changes: 36 additions & 3 deletions
39
src/main/java/com/convallyria/hugestructureblocks/mixin/structure/StructureBlockUnlimit.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 |
---|---|---|
@@ -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; | ||
} | ||
} |
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,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 |
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