22
33import com .robotgryphon .compactmachines .CompactMachines ;
44import com .robotgryphon .compactmachines .block .tiles .CompactMachineTile ;
5+ import com .robotgryphon .compactmachines .config .ServerConfig ;
56import com .robotgryphon .compactmachines .core .Registration ;
67import com .robotgryphon .compactmachines .data .CompactMachineServerData ;
78import com .robotgryphon .compactmachines .data .SavedMachineData ;
@@ -57,10 +58,7 @@ public static void teleportInto(ServerPlayerEntity serverPlayer, BlockPos machin
5758 if (tile .machineId == -1 ) {
5859 int nextID = serverData .getNextMachineId ();
5960
60- BlockPos center = getCenterOfMachineById (nextID );
61-
62- // Bump the center up a bit so the floor is Y = 60
63- center = center .offset (Direction .UP , size .getInternalSize () / 2 );
61+ BlockPos center = getCenterForNewMachine (nextID , size );
6462
6563 CompactStructureGenerator .generateCompactStructure (compactWorld , size , center );
6664
@@ -72,7 +70,7 @@ public static void teleportInto(ServerPlayerEntity serverPlayer, BlockPos machin
7270 machineData .markDirty ();
7371
7472 BlockPos .Mutable spawn = center .toMutable ();
75- spawn .setY (62 );
73+ spawn .setY (ServerConfig . MACHINE_FLOOR_Y . get () );
7674
7775 spawnPoint = spawn .toImmutable ();
7876 } else {
@@ -89,10 +87,10 @@ public static void teleportInto(ServerPlayerEntity serverPlayer, BlockPos machin
8987 }
9088
9189 CompactMachineRegistrationData data = info .get ();
92- BlockPos .Mutable center = data .getCenter ().toMutable ();
93- center .setY (62 );
90+ BlockPos .Mutable spawn = data .getCenter ().toMutable ();
91+ spawn .setY (spawn . getY () - ( size . getInternalSize () / 2 ) );
9492
95- spawnPoint = data .getSpawnPoint ().orElse (center );
93+ spawnPoint = data .getSpawnPoint ().orElse (spawn );
9694 }
9795
9896 try {
@@ -170,9 +168,10 @@ public static Item getMachineBlockItemBySize(EnumMachineSize size) {
170168 return Registration .MACHINE_BLOCK_ITEM_NORMAL .get ();
171169 }
172170
173- public static BlockPos getCenterOfMachineById (int id ) {
171+ public static BlockPos getCenterForNewMachine (int id , EnumMachineSize size ) {
174172 Vector3i location = MathUtil .getRegionPositionByIndex (id );
175- return new BlockPos ((location .getX () * 1024 ) + 8 , 60 , (location .getZ () * 1024 ) + 8 );
173+ int centerY = ServerConfig .MACHINE_FLOOR_Y .get () + (size .getInternalSize () / 2 );
174+ return new BlockPos ((location .getX () * 1024 ) + 8 , centerY , (location .getZ () * 1024 ) + 8 );
176175 }
177176
178177 public static void setMachineSpawn (MinecraftServer server , BlockPos position ) {
0 commit comments