Skip to content

Commit d956232

Browse files
committed
Add first pass of configurable floor Y level.
1 parent 75a3fe6 commit d956232

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

src/main/java/com/robotgryphon/compactmachines/config/ServerConfig.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ public class ServerConfig {
1414
public static ForgeConfigSpec.EnumValue<EnumMachinePlayersBreakHandling> MACHINE_PLAYER_BREAK_HANDLING;
1515
public static ForgeConfigSpec.BooleanValue MACHINE_CHUNKLOADING;
1616

17+
public static ForgeConfigSpec.IntValue MACHINE_FLOOR_Y;
18+
1719
static {
1820
generateConfig();
1921
}
@@ -43,6 +45,10 @@ private static void generateConfig() {
4345
.comment("Allow machines to chunkload their insides when the machines are loaded.")
4446
.define("chunkloading", true);
4547

48+
MACHINE_FLOOR_Y = builder
49+
.comment("The Y-level to spawn machine floors at.")
50+
.defineInRange("floor", 40, 10, 200);
51+
4652
builder.pop();
4753

4854
CONFIG = builder.build();

src/main/java/com/robotgryphon/compactmachines/util/CompactMachineUtil.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.robotgryphon.compactmachines.CompactMachines;
44
import com.robotgryphon.compactmachines.block.tiles.CompactMachineTile;
5+
import com.robotgryphon.compactmachines.config.ServerConfig;
56
import com.robotgryphon.compactmachines.core.Registration;
67
import com.robotgryphon.compactmachines.data.CompactMachineServerData;
78
import 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

Comments
 (0)