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:
authored and GitHub committed 2021-01-22 23:38:10 -04:00
1 parent 695b4a0e3a
commit e32b37dcf1
5 files changed
+194 -42

No files matched your search

@@ -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());
}
}