-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e33337c
commit b0fc5ec
Showing
34 changed files
with
2,235 additions
and
2,095 deletions.
There are no files selected for viewing
212 changes: 115 additions & 97 deletions
212
core-api/src/main/java/dev/compactmods/machines/api/CompactMachines.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,97 +1,115 @@ | ||
package dev.compactmods.machines.api; | ||
|
||
import dev.compactmods.machines.api.dimension.CompactDimension; | ||
import dev.compactmods.machines.api.dimension.MissingDimensionException; | ||
import dev.compactmods.machines.api.room.CompactRoomGenerator; | ||
import dev.compactmods.machines.api.room.IRoomApi; | ||
import dev.compactmods.machines.api.room.RoomInstance; | ||
import dev.compactmods.machines.api.room.RoomTemplate; | ||
import dev.compactmods.machines.api.room.data.IRoomDataAttachmentAccessor; | ||
import dev.compactmods.machines.api.room.history.IPlayerHistoryApi; | ||
import dev.compactmods.machines.api.room.upgrade.RoomUpgradeDefinition; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.server.MinecraftServer; | ||
import net.neoforged.neoforge.attachment.AttachmentHolder; | ||
import net.neoforged.neoforge.attachment.IAttachmentHolder; | ||
import net.neoforged.neoforge.registries.DeferredRegister; | ||
import org.jetbrains.annotations.ApiStatus; | ||
|
||
import java.util.Optional; | ||
import java.util.UUID; | ||
|
||
public class CompactMachines { | ||
public final static String MOD_ID = "compactmachines"; | ||
|
||
public static String id(String path) { | ||
return ResourceLocation.isValidPath(path) ? (MOD_ID + ":" + path) : MOD_ID + ":invalid"; | ||
} | ||
|
||
public static ResourceLocation modRL(String path) { | ||
return ResourceLocation.fromNamespaceAndPath(MOD_ID, path); | ||
} | ||
|
||
public static DeferredRegister<RoomUpgradeDefinition<?>> roomUpgradeDR(String namespace) { | ||
return DeferredRegister.create(RoomUpgradeDefinition.REG_KEY, namespace); | ||
} | ||
|
||
public static IRoomApi roomApi() { | ||
return Internal.ROOM_API; | ||
} | ||
|
||
public static IPlayerHistoryApi playerHistoryApi() { | ||
return Internal.PLAYER_HISTORY_API; | ||
} | ||
|
||
public static Optional<RoomInstance> room(String roomCode) { | ||
return Internal.ROOM_API.registrar().get(roomCode); | ||
} | ||
|
||
/** | ||
* Registers a new room instance and generates the structure in the compact world. | ||
* | ||
* @param server Server to generate room on. | ||
* @param template | ||
* @param owner | ||
* @return | ||
*/ | ||
public static RoomInstance newRoom(MinecraftServer server, RoomTemplate template, UUID owner) throws MissingDimensionException { | ||
final var instance = CompactMachines.roomApi().registrar().createNew(template, owner); | ||
final var compactDim = CompactDimension.forServer(server); | ||
CompactRoomGenerator.generateRoom(compactDim, instance.boundaries().outerBounds()); | ||
|
||
if(!template.structures().isEmpty()) { | ||
for(var struct : template.structures()) { | ||
CompactRoomGenerator.populateStructure(compactDim, struct.template(), instance.boundaries().innerBounds(), struct.placement()); | ||
} | ||
} | ||
|
||
return instance; | ||
} | ||
|
||
public static boolean isValidRoomCode(String roomCode) { | ||
return Internal.ROOM_API.roomCodeValidator().test(roomCode); | ||
} | ||
|
||
public static Optional<? extends IAttachmentHolder> existingRoomData(String code) { | ||
return Internal.ROOM_DATA_ACCESSOR.get(code); | ||
} | ||
|
||
public static IAttachmentHolder roomData(String code) { | ||
return Internal.ROOM_DATA_ACCESSOR.getOrCreate(code); | ||
} | ||
|
||
|
||
/** | ||
* Set up when the server or single-player instance changes. | ||
* NOT for API consumers to use! Use the methods provided here for safety. | ||
* | ||
* @since 6.0.0 | ||
*/ | ||
@ApiStatus.Internal | ||
@Deprecated | ||
public final class Internal { | ||
public static IRoomApi ROOM_API; | ||
public static IRoomDataAttachmentAccessor ROOM_DATA_ACCESSOR; | ||
public static IPlayerHistoryApi PLAYER_HISTORY_API; | ||
} | ||
} | ||
package dev.compactmods.machines.api; | ||
|
||
import dev.compactmods.machines.api.dimension.CompactDimension; | ||
import dev.compactmods.machines.api.dimension.MissingDimensionException; | ||
import dev.compactmods.machines.api.room.CompactRoomGenerator; | ||
import dev.compactmods.machines.api.room.IRoomApi; | ||
import dev.compactmods.machines.api.room.RoomInstance; | ||
import dev.compactmods.machines.api.room.template.RoomTemplate; | ||
import dev.compactmods.machines.api.room.data.IRoomDataAttachmentAccessor; | ||
import dev.compactmods.machines.api.room.history.IPlayerHistoryApi; | ||
import dev.compactmods.machines.api.room.upgrade.RoomUpgradeDefinition; | ||
import dev.compactmods.machines.api.util.BlockSpaceUtil; | ||
import net.minecraft.core.Direction; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.server.MinecraftServer; | ||
import net.minecraft.world.level.block.Block; | ||
import net.minecraft.world.phys.AABB; | ||
import net.minecraft.world.phys.Vec2; | ||
import net.neoforged.neoforge.attachment.IAttachmentHolder; | ||
import net.neoforged.neoforge.registries.DeferredRegister; | ||
import org.jetbrains.annotations.ApiStatus; | ||
|
||
import java.util.Optional; | ||
import java.util.UUID; | ||
|
||
public class CompactMachines { | ||
public final static String MOD_ID = "compactmachines"; | ||
|
||
public static String id(String path) { | ||
return ResourceLocation.isValidPath(path) ? (MOD_ID + ":" + path) : MOD_ID + ":invalid"; | ||
} | ||
|
||
public static ResourceLocation modRL(String path) { | ||
return ResourceLocation.fromNamespaceAndPath(MOD_ID, path); | ||
} | ||
|
||
public static DeferredRegister<RoomUpgradeDefinition<?>> roomUpgradeDR(String namespace) { | ||
return DeferredRegister.create(RoomUpgradeDefinition.REG_KEY, namespace); | ||
} | ||
|
||
public static IRoomApi roomApi() { | ||
return Internal.ROOM_API; | ||
} | ||
|
||
public static IPlayerHistoryApi playerHistoryApi() { | ||
return Internal.PLAYER_HISTORY_API; | ||
} | ||
|
||
public static Optional<RoomInstance> room(String roomCode) { | ||
return Internal.ROOM_API.registrar().get(roomCode); | ||
} | ||
|
||
/** | ||
* Registers a new room instance and generates the structure in the compact world. | ||
* | ||
* @param server Server to generate room on. | ||
* @param template | ||
* @param owner | ||
* @return | ||
*/ | ||
public static RoomInstance newRoom(MinecraftServer server, RoomTemplate template, UUID owner) throws MissingDimensionException { | ||
final var instance = CompactMachines.roomApi().registrar().createNew(template, owner); | ||
final var compactDim = CompactDimension.forServer(server); | ||
CompactRoomGenerator.generateRoom(compactDim, instance.boundaries().outerBounds()); | ||
|
||
if (!template.structures().isEmpty()) { | ||
for (var struct : template.structures()) { | ||
CompactRoomGenerator.populateStructure(compactDim, struct.template(), instance.boundaries().innerBounds(), struct.placement()); | ||
} | ||
} | ||
|
||
final var spawnManager = CompactMachines.roomApi().spawnManager(instance.code()); | ||
template.optionalFloor().ifPresent(floorState -> { | ||
var fixedSpawn = instance.boundaries() | ||
.defaultSpawn() | ||
.add(0, 1, 0); | ||
|
||
spawnManager.setDefaultSpawn(fixedSpawn, Vec2.ZERO); | ||
|
||
AABB floorBounds = BlockSpaceUtil.getWallBounds(instance.boundaries().innerBounds(), Direction.DOWN); | ||
BlockSpaceUtil.blocksInside(floorBounds).forEach(floorBlockPos -> { | ||
compactDim.setBlock(floorBlockPos, floorState, Block.UPDATE_ALL); | ||
}); | ||
}); | ||
|
||
return instance; | ||
} | ||
|
||
public static boolean isValidRoomCode(String roomCode) { | ||
return Internal.ROOM_API.roomCodeValidator().test(roomCode); | ||
} | ||
|
||
public static Optional<? extends IAttachmentHolder> existingRoomData(String code) { | ||
return Internal.ROOM_DATA_ACCESSOR.get(code); | ||
} | ||
|
||
public static IAttachmentHolder roomData(String code) { | ||
return Internal.ROOM_DATA_ACCESSOR.getOrCreate(code); | ||
} | ||
|
||
|
||
/** | ||
* Set up when the server or single-player instance changes. | ||
* NOT for API consumers to use! Use the methods provided here for safety. | ||
* | ||
* @since 6.0.0 | ||
*/ | ||
@ApiStatus.Internal | ||
@Deprecated | ||
public final class Internal { | ||
public static IRoomApi ROOM_API; | ||
public static IRoomDataAttachmentAccessor ROOM_DATA_ACCESSOR; | ||
public static IPlayerHistoryApi PLAYER_HISTORY_API; | ||
} | ||
} |
13 changes: 0 additions & 13 deletions
13
core-api/src/main/java/dev/compactmods/machines/api/room/RoomComponents.java
This file was deleted.
Oops, something went wrong.
46 changes: 21 additions & 25 deletions
46
core-api/src/main/java/dev/compactmods/machines/api/room/data/CMRoomDataLocations.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,21 @@ | ||
package dev.compactmods.machines.api.room.data; | ||
|
||
import dev.compactmods.machines.api.CompactMachines; | ||
import net.minecraft.server.MinecraftServer; | ||
import net.minecraft.world.level.storage.LevelResource; | ||
|
||
import java.nio.file.Path; | ||
import java.util.function.Function; | ||
|
||
public interface CMRoomDataLocations { | ||
|
||
Function<MinecraftServer, Path> REGISTRATION_DATA = (server) -> server.getWorldPath(LevelResource.ROOT) | ||
.resolve(CompactMachines.MOD_ID) | ||
.resolve("data"); | ||
|
||
Function<MinecraftServer, Path> SPAWN_DATA = (server) -> server.getWorldPath(LevelResource.ROOT) | ||
.resolve(CompactMachines.MOD_ID) | ||
.resolve("data") | ||
.resolve("spawn_data"); | ||
|
||
Function<MinecraftServer, Path> ROOM_DATA_ATTACHMENTS = (server) -> server.getWorldPath(LevelResource.ROOT) | ||
.resolve(CompactMachines.MOD_ID) | ||
.resolve("data") | ||
.resolve("room_data"); | ||
} | ||
package dev.compactmods.machines.api.room.data; | ||
|
||
import dev.compactmods.machines.api.CompactMachines; | ||
import net.minecraft.server.MinecraftServer; | ||
import net.minecraft.world.level.storage.LevelResource; | ||
|
||
import java.nio.file.Path; | ||
import java.util.function.Function; | ||
|
||
public interface CMRoomDataLocations { | ||
|
||
Function<MinecraftServer, Path> DATA_ROOT = (server) -> server.getWorldPath(LevelResource.ROOT) | ||
.resolve(CompactMachines.MOD_ID); | ||
|
||
Function<MinecraftServer, Path> PLAYER_SPAWNS = (server) -> DATA_ROOT.apply(server) | ||
.resolve("player_spawns"); | ||
|
||
Function<MinecraftServer, Path> ROOM_DATA_ATTACHMENTS = (server) -> DATA_ROOT.apply(server) | ||
.resolve("room_data"); | ||
|
||
} |
85 changes: 42 additions & 43 deletions
85
core-api/src/main/java/dev/compactmods/machines/api/room/registration/IRoomRegistrar.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,42 @@ | ||
package dev.compactmods.machines.api.room.registration; | ||
|
||
import dev.compactmods.machines.api.room.RoomInstance; | ||
import dev.compactmods.machines.api.room.RoomTemplate; | ||
import dev.compactmods.machines.api.room.registration.IRoomBuilder; | ||
import net.minecraft.world.phys.AABB; | ||
|
||
import java.util.Optional; | ||
import java.util.UUID; | ||
import java.util.function.Consumer; | ||
import java.util.stream.Stream; | ||
|
||
public interface IRoomRegistrar { | ||
|
||
AABB getNextBoundaries(RoomTemplate template); | ||
|
||
IRoomBuilder builder(); | ||
|
||
default RoomInstance createNew(RoomTemplate template, UUID owner) { | ||
return createNew(template, owner, override -> {}); | ||
} | ||
|
||
default RoomInstance createNew(RoomTemplate template, UUID owner, Consumer<IRoomBuilder> override) { | ||
final Consumer<IRoomBuilder> preOverride = builder -> builder.defaultMachineColor(template.defaultMachineColor()) | ||
.owner(owner) | ||
.boundaries(getNextBoundaries(template)); | ||
|
||
// Make builder, set template defaults, then allow overrides | ||
final var b = builder(); | ||
preOverride.andThen(override).accept(b); | ||
return b.build(); | ||
} | ||
|
||
boolean isRegistered(String room); | ||
|
||
Optional<RoomInstance> get(String room); | ||
|
||
long count(); | ||
|
||
Stream<String> allRoomCodes(); | ||
|
||
Stream<RoomInstance> allRooms(); | ||
} | ||
package dev.compactmods.machines.api.room.registration; | ||
|
||
import dev.compactmods.machines.api.room.RoomInstance; | ||
import dev.compactmods.machines.api.room.template.RoomTemplate; | ||
import net.minecraft.world.phys.AABB; | ||
|
||
import java.util.Optional; | ||
import java.util.UUID; | ||
import java.util.function.Consumer; | ||
import java.util.stream.Stream; | ||
|
||
public interface IRoomRegistrar { | ||
|
||
AABB getNextBoundaries(RoomTemplate template); | ||
|
||
IRoomBuilder builder(); | ||
|
||
default RoomInstance createNew(RoomTemplate template, UUID owner) { | ||
return createNew(template, owner, override -> {}); | ||
} | ||
|
||
default RoomInstance createNew(RoomTemplate template, UUID owner, Consumer<IRoomBuilder> override) { | ||
final Consumer<IRoomBuilder> preOverride = builder -> builder.defaultMachineColor(template.defaultMachineColor()) | ||
.owner(owner) | ||
.boundaries(getNextBoundaries(template)); | ||
|
||
// Make builder, set template defaults, then allow overrides | ||
final var b = builder(); | ||
preOverride.andThen(override).accept(b); | ||
return b.build(); | ||
} | ||
|
||
boolean isRegistered(String room); | ||
|
||
Optional<RoomInstance> get(String room); | ||
|
||
long count(); | ||
|
||
Stream<String> allRoomCodes(); | ||
|
||
Stream<RoomInstance> allRooms(); | ||
} |
Oops, something went wrong.