Add three Structure Block related settings (#664)
* Added structureBlockOutlineDistance * Added structureBlockIgnored * Added structureBlockLimit * Made structureBlockLimit work on dedicated server * Correct packet contents check and fix mixin list * Add limits to structure block settings, slight optimisation to ignored block * Fixed the `structureBlockLimit` limit * Update src/main/java/carpet/CarpetSettings.java Co-authored-by: altrisi <altrisi.trillosierra@gmail.com> * Fix missing imports and a typo * Update src/main/java/carpet/CarpetSettings.java Co-authored-by: gnembon <41132274+gnembon@users.noreply.github.com> Co-authored-by: altrisi <altrisi.trillosierra@gmail.com>
This commit is contained in:
5 files changed
+194
-42
No files matched your search
@@ -7,20 +7,25 @@ import carpet.settings.Validator;
|
||||
import carpet.utils.Translations;
|
||||
import carpet.utils.Messenger;
|
||||
import carpet.utils.SpawnChunks;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
import net.minecraft.server.dedicated.DedicatedServer;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Box;
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.world.World;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Locale;
|
||||
import java.util.Optional;
|
||||
|
||||
import static carpet.settings.RuleCategory.BUGFIX;
|
||||
import static carpet.settings.RuleCategory.COMMAND;
|
||||
@@ -46,6 +51,7 @@ public class CarpetSettings
|
||||
public static int runPermissionLevel = 2;
|
||||
public static boolean doChainStone = false;
|
||||
public static boolean chainStoneStickToAll = false;
|
||||
public static Block structureBlockIgnoredBlock = Blocks.STRUCTURE_VOID;
|
||||
|
||||
private static class LanguageValidator extends Validator<String> {
|
||||
@Override public String validate(ServerCommandSource source, ParsedRule<String> currentRule, String newValue, String string) {
|
||||
@@ -792,4 +798,62 @@ public class CarpetSettings
|
||||
category = {SURVIVAL, CLIENT}
|
||||
)
|
||||
public static boolean cleanLogs = false;
|
||||
|
||||
public static class StructureBlockLimitValidator extends Validator<Integer> {
|
||||
|
||||
@Override public Integer validate(ServerCommandSource source, ParsedRule<Integer> currentRule, Integer newValue, String string) {
|
||||
return (newValue >= 48) ? newValue : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String description() {
|
||||
return "You have to choose a value greater or equal to 48";
|
||||
}
|
||||
}
|
||||
@Rule(
|
||||
desc = "Customizable structure block limit of each axis",
|
||||
extra = {"WARNING: Needs to be permanent for correct loading.",
|
||||
"Setting 'structureBlockIgnored' to air is recommended",
|
||||
"when saving massive structures.",
|
||||
"Required on client of player editing the Structure Block.",
|
||||
"'structureBlockOutlineDistance' may be required for",
|
||||
"correct rendering of long structures."},
|
||||
options = {"48", "96", "192", "256"},
|
||||
category = {CREATIVE, CLIENT},
|
||||
validate = StructureBlockLimitValidator.class,
|
||||
strict = false
|
||||
)
|
||||
public static int structureBlockLimit = 48;
|
||||
|
||||
public static class StructureBlockIgnoredValidator extends Validator<String> {
|
||||
|
||||
@Override
|
||||
public String validate(ServerCommandSource source, ParsedRule<String> currentRule, String newValue, String string) {
|
||||
Optional<Block> ignoredBlock = Registry.BLOCK.getOrEmpty(Identifier.tryParse(newValue));
|
||||
if (!ignoredBlock.isPresent()) {
|
||||
Messenger.m(source, "r Unknown block '" + newValue + "'.");
|
||||
return null;
|
||||
}
|
||||
structureBlockIgnoredBlock = ignoredBlock.get();
|
||||
return newValue;
|
||||
}
|
||||
}
|
||||
@Rule(
|
||||
desc = "Changes the block ignored by the Structure Block",
|
||||
options = {"minecraft:structure_void", "minecraft:air"},
|
||||
category = CREATIVE,
|
||||
validate = StructureBlockIgnoredValidator.class,
|
||||
strict = false
|
||||
)
|
||||
public static String structureBlockIgnored = "minecraft:structure_void";
|
||||
|
||||
@Rule(
|
||||
desc = "Customizable Structure Block outline render distance",
|
||||
extra = "Required on client to work properly",
|
||||
options = {"96", "192", "2048"},
|
||||
category = {CREATIVE, CLIENT},
|
||||
strict = false,
|
||||
validate = Validator.NONNEGATIVE_NUMBER.class
|
||||
)
|
||||
public static double structureBlockOutlineDistance = 96d;
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
package carpet.mixins;
|
||||
|
||||
import carpet.CarpetSettings;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.entity.StructureBlockBlockEntity;
|
||||
import net.minecraft.structure.Structure;
|
||||
import net.minecraft.structure.StructurePlacementData;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.world.ServerWorldAccess;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.*;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
@Mixin(StructureBlockBlockEntity.class)
|
||||
public abstract class StructureBlockBlockEntityMixin
|
||||
{
|
||||
@Redirect(method = "place", at = @At(
|
||||
value = "INVOKE",
|
||||
target = "Lnet/minecraft/structure/Structure;place(Lnet/minecraft/world/ServerWorldAccess;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/structure/StructurePlacementData;Ljava/util/Random;)V"
|
||||
))
|
||||
private void onStructurePlacen(Structure structure, ServerWorldAccess serverWorldAccess, BlockPos pos, StructurePlacementData placementData, Random random)
|
||||
{
|
||||
if(!CarpetSettings.fillUpdates)
|
||||
CarpetSettings.impendingFillSkipUpdates = true;
|
||||
try
|
||||
{
|
||||
structure.place(serverWorldAccess, pos, placementData, random);
|
||||
}
|
||||
finally
|
||||
{
|
||||
CarpetSettings.impendingFillSkipUpdates = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ModifyConstant(
|
||||
method = "fromTag",
|
||||
constant = @Constant(intValue = 48)
|
||||
)
|
||||
private int positiveLimit(int original) {
|
||||
return CarpetSettings.structureBlockLimit;
|
||||
}
|
||||
|
||||
@ModifyConstant(
|
||||
method = "fromTag",
|
||||
constant = @Constant(intValue = -48)
|
||||
)
|
||||
private int negativeLimit(int original) {
|
||||
return -CarpetSettings.structureBlockLimit;
|
||||
}
|
||||
|
||||
@ModifyArg(
|
||||
method = "saveStructure(Z)Z",
|
||||
at = @At(
|
||||
value = "INVOKE",
|
||||
target = "Lnet/minecraft/structure/Structure;saveFromWorld(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/util/math/BlockPos;ZLnet/minecraft/block/Block;)V"
|
||||
),
|
||||
index = 4
|
||||
)
|
||||
private Block ignoredBlock(Block original) {
|
||||
return CarpetSettings.structureBlockIgnoredBlock;
|
||||
}
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
@ModifyConstant(
|
||||
method = "getSquaredRenderDistance",
|
||||
constant = @Constant(doubleValue = 96d)
|
||||
)
|
||||
private double outlineRenderDistanceLimit(double original) {
|
||||
return CarpetSettings.structureBlockOutlineDistance;
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
package carpet.mixins;
|
||||
|
||||
import carpet.CarpetSettings;
|
||||
import net.minecraft.block.entity.StructureBlockBlockEntity;
|
||||
import net.minecraft.structure.Structure;
|
||||
import net.minecraft.structure.StructurePlacementData;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.ServerWorldAccess;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
@Mixin(StructureBlockBlockEntity.class)
|
||||
public abstract class StructureBlockBlockEntity_fillUpdatesMixin
|
||||
{
|
||||
@Redirect(method = "place", at = @At(
|
||||
value = "INVOKE",
|
||||
target = "Lnet/minecraft/structure/Structure;place(Lnet/minecraft/world/ServerWorldAccess;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/structure/StructurePlacementData;Ljava/util/Random;)V"
|
||||
))
|
||||
private void onStructurePlacen(Structure structure, ServerWorldAccess serverWorldAccess, BlockPos pos, StructurePlacementData placementData, Random random)
|
||||
{
|
||||
if(!CarpetSettings.fillUpdates)
|
||||
CarpetSettings.impendingFillSkipUpdates = true;
|
||||
try
|
||||
{
|
||||
structure.place(serverWorldAccess, pos, placementData, random);
|
||||
}
|
||||
finally
|
||||
{
|
||||
CarpetSettings.impendingFillSkipUpdates = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package carpet.mixins;
|
||||
|
||||
import carpet.CarpetSettings;
|
||||
import net.minecraft.network.PacketByteBuf;
|
||||
import net.minecraft.network.packet.c2s.play.UpdateStructureBlockC2SPacket;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
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.CallbackInfo;
|
||||
|
||||
@Mixin(UpdateStructureBlockC2SPacket.class)
|
||||
public class UpdateStructureBlockC2SPacketMixin {
|
||||
@Shadow
|
||||
private BlockPos offset;
|
||||
@Shadow
|
||||
private BlockPos size;
|
||||
|
||||
@Inject(
|
||||
method = "read",
|
||||
at = @At("TAIL")
|
||||
)
|
||||
private void structureBlockLimitsRead(PacketByteBuf buf, CallbackInfo ci) {
|
||||
if (buf.readableBytes() > 0) {
|
||||
// This will throw an exception if carpet is not installed on client
|
||||
offset = new BlockPos(MathHelper.clamp(buf.readInt(), -CarpetSettings.structureBlockLimit, CarpetSettings.structureBlockLimit), MathHelper.clamp(buf.readInt(), -CarpetSettings.structureBlockLimit, CarpetSettings.structureBlockLimit), MathHelper.clamp(buf.readInt(), -CarpetSettings.structureBlockLimit, CarpetSettings.structureBlockLimit));
|
||||
size = new BlockPos(MathHelper.clamp(buf.readInt(), 0, CarpetSettings.structureBlockLimit), MathHelper.clamp(buf.readInt(), 0, CarpetSettings.structureBlockLimit), MathHelper.clamp(buf.readInt(), 0, CarpetSettings.structureBlockLimit));
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(
|
||||
method = "write",
|
||||
at = @At("TAIL")
|
||||
)
|
||||
private void structureBlockLimitsWrite(PacketByteBuf buf, CallbackInfo ci) {
|
||||
buf.writeInt(this.offset.getX());
|
||||
buf.writeInt(this.offset.getY());
|
||||
buf.writeInt(this.offset.getZ());
|
||||
buf.writeInt(this.size.getX());
|
||||
buf.writeInt(this.size.getY());
|
||||
buf.writeInt(this.size.getZ());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user