Skip to content

Commit

Permalink
Fixed structures on server
Browse files Browse the repository at this point in the history
  • Loading branch information
LatvianModder committed Jun 18, 2021
1 parent b03c8a7 commit 84217ce
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 19 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ out
# gradle
build
.gradle
logs

# other
eclipse
run
.vscode

# Files from Forge MDK
forge*changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@

@Mod("structureexpansion")
public class StructureExpansion {
public static final int NEW_LIMIT = 512;
public static final int NEW_LIMIT_POS = NEW_LIMIT - 1;
public static final int NEW_LIMIT_NEG = -NEW_LIMIT_POS;
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,133 @@
package com.sunekaer.mods.structureexpansion.mixin;

import com.sunekaer.mods.structureexpansion.StructureExpansion;
import net.minecraft.network.PacketBuffer;
import net.minecraft.network.play.client.CUpdateStructureBlockPacket;
import net.minecraft.state.properties.StructureMode;
import net.minecraft.tileentity.StructureBlockTileEntity;
import net.minecraft.util.Mirror;
import net.minecraft.util.Rotation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.Constant;
import org.spongepowered.asm.mixin.injection.ModifyConstant;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;

import java.io.IOException;

@Mixin(CUpdateStructureBlockPacket.class)
public abstract class CUpdateStructureBlockPacketMixin {
@ModifyConstant(method = "readPacketData", constant = {@Constant(intValue = 48), @Constant(intValue = -48)})
private int getMaxSizePos(int value){
return value > 0 ? 255 : -256;
}
@Shadow
private BlockPos pos;

@Shadow
private StructureBlockTileEntity.UpdateCommand updateCommand;

@Shadow
private StructureMode mode;

@Shadow
private String name;

@Shadow
private BlockPos position;

@Shadow
private BlockPos size;

@Shadow
private Mirror mirror;

@Shadow
private Rotation rotation;

@Shadow
private String metaData;

@Shadow
private boolean ignoreEntities;

@Shadow
private boolean showAir;

@Shadow
private boolean showBoundingBox;

@Shadow
private float integrity;

@Shadow
private long seed;

/**
* @author LatvianModder
* @reason to fix 48 block limit
*/
@Overwrite
public void readPacketData(PacketBuffer buf) throws IOException {
pos = buf.readBlockPos();
updateCommand = buf.readEnumValue(StructureBlockTileEntity.UpdateCommand.class);
mode = buf.readEnumValue(StructureMode.class);
name = buf.readString(32767);

position = new BlockPos(
MathHelper.clamp(buf.readVarInt(), StructureExpansion.NEW_LIMIT_NEG, StructureExpansion.NEW_LIMIT_POS),
MathHelper.clamp(buf.readVarInt(), StructureExpansion.NEW_LIMIT_NEG, StructureExpansion.NEW_LIMIT_POS),
MathHelper.clamp(buf.readVarInt(), StructureExpansion.NEW_LIMIT_NEG, StructureExpansion.NEW_LIMIT_POS)
);

size = new BlockPos(
MathHelper.clamp(buf.readVarInt(), 0, StructureExpansion.NEW_LIMIT_POS),
MathHelper.clamp(buf.readVarInt(), 0, StructureExpansion.NEW_LIMIT_POS),
MathHelper.clamp(buf.readVarInt(), 0, StructureExpansion.NEW_LIMIT_POS)
);

mirror = buf.readEnumValue(Mirror.class);
rotation = buf.readEnumValue(Rotation.class);
metaData = buf.readString(12);
integrity = MathHelper.clamp(buf.readFloat(), 0.0F, 1.0F);
seed = buf.readVarLong();
int k = buf.readVarInt();
ignoreEntities = (k & 1) != 0;
showAir = (k & 2) != 0;
showBoundingBox = (k & 4) != 0;
}

/**
* @author LatvianModder
* @reason to fix 48 block limit
*/
@Overwrite
public void writePacketData(PacketBuffer buf) {
buf.writeBlockPos(pos);
buf.writeEnumValue(updateCommand);
buf.writeEnumValue(mode);
buf.writeString(name);
buf.writeVarInt(position.getX());
buf.writeVarInt(position.getY());
buf.writeVarInt(position.getZ());
buf.writeVarInt(size.getX());
buf.writeVarInt(size.getY());
buf.writeVarInt(size.getZ());
buf.writeEnumValue(mirror);
buf.writeEnumValue(rotation);
buf.writeString(metaData);
buf.writeFloat(integrity);
buf.writeVarLong(seed);

int i = 0;
if (ignoreEntities) {
i |= 1;
}

if (showAir) {
i |= 2;
}

if (showBoundingBox) {
i |= 4;
}

buf.writeVarInt(i);
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package com.sunekaer.mods.structureexpansion.mixin;

import com.sunekaer.mods.structureexpansion.StructureExpansion;
import net.minecraft.tileentity.StructureBlockTileEntity;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.Constant;
import org.spongepowered.asm.mixin.injection.ModifyConstant;

@Mixin(StructureBlockTileEntity.class)
public abstract class StructureBlockTileEntityMixin {
@ModifyConstant(method = "read", constant = {@Constant(intValue = 48), @Constant(intValue = -48)})
private int getMaxSizePos(int value){
return value > 0 ? 255 : -256;
}
@ModifyConstant(method = "read", constant = {@Constant(intValue = 48), @Constant(intValue = -48)})
private int getMaxSizePos(int value) {
return value > 0 ? StructureExpansion.NEW_LIMIT_POS : StructureExpansion.NEW_LIMIT_NEG;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,15 @@
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityType;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.Constant;
import org.spongepowered.asm.mixin.injection.ModifyConstant;

@Mixin(StructureBlockTileEntity.class)
public abstract class StructureBlockTileEntityRenderMixin extends TileEntity {
public StructureBlockTileEntityRenderMixin(TileEntityType<?> tileEntityType_1) {
super(tileEntityType_1);
}
public StructureBlockTileEntityRenderMixin(TileEntityType<?> tileEntityType_1) {
super(tileEntityType_1);
}

@Override
public double getMaxRenderDistanceSquared() {
return 288.0D;
}
@Override
public double getMaxRenderDistanceSquared() {
return 32767D;
}
}

0 comments on commit 84217ce

Please sign in to comment.