Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/main/java/com/ldtteam/structurize/Structurize.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.ldtteam.structurize.event.ClientLifecycleSubscriber;
import com.ldtteam.structurize.event.EventSubscriber;
import com.ldtteam.structurize.event.LifecycleSubscriber;
import com.ldtteam.structurize.index.packtypes.PackTypesRegistry;
import com.ldtteam.structurize.items.ModItemGroups;
import com.ldtteam.structurize.items.ModItems;
import com.ldtteam.structurize.blockentities.ModBlockEntities;
Expand Down Expand Up @@ -58,6 +59,7 @@ public Structurize(final FMLModContainer modContainer, final Dist dist)
ModItems.ITEMS.register(modBus);
ModBlockEntities.BLOCK_ENTITIES.register(modBus);
ModItemGroups.TAB_REG.register(modBus);
PackTypesRegistry.DEFERRED_REGISTER.register(modBus);

modBus.register(LifecycleSubscriber.class);
forgeBus.register(EventSubscriber.class);
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/com/ldtteam/structurize/api/Registries.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.ldtteam.structurize.api;

import com.ldtteam.structurize.api.constants.Constants;
import com.ldtteam.structurize.index.packtypes.models.PackType;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;

public class Registries
{
public static final ResourceKey<Registry<PackType>> SCHEMATIC_INDEX_PACK_TYPES =
ResourceKey.createRegistryKey(ResourceLocation.fromNamespaceAndPath(Constants.MOD_ID, ("schematic_index_pack_types")));
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,25 @@ public final class TranslationConstants
public static final String ANCHOR_POS_OUTSIDE_SCHEMATIC = "item.sceptersteel.badanchorpos";

@NonNls
public static final String GUI_SWITCH_PACK_AUTHORS = "com.ldtteam.structurize.gui.switchpack.authors";
public static final String GUI_SWITCH_PACK_AUTHORS = "com.ldtteam.structurize.gui.switchpack.authors";
@NonNls
public static final String GUI_SWITCH_PACK_DISABLED_TEXT = "com.ldtteam.structurize.gui.switchpack.pack_disabled.hover_text";

@NonNls
public static final String PACK_TYPE_VALIDATION_REQUIRED_SCHEMATIC = "com.ldtteam.structurize.pack_type.validation.missing_required_schematic";
@NonNls
public static final String PACK_TYPE_VALIDATION_OPTIONAL_SCHEMATIC = "com.ldtteam.structurize.pack_type.validation.missing_optional_schematic";
@NonNls
public static final String PACK_TYPE_VALIDATION_REQUIREMENT_PART_NAME = "com.ldtteam.structurize.pack_type.validation.requirement_part_name";
@NonNls
public static final String PACK_TYPE_VALIDATION_REQUIREMENT_PART_PATH = "com.ldtteam.structurize.pack_type.validation.requirement_part_path";
@NonNls
public static final String PACK_TYPE_VALIDATION_REQUIREMENT_PART_ANCHOR = "com.ldtteam.structurize.pack_type.validation.requirement_part_anchor";
@NonNls
public static final String PACK_TYPE_VALIDATION_REQUIREMENT_PART_AND = "com.ldtteam.structurize.pack_type.validation.requirement_part_and";
@NonNls
public static final String PACK_TYPE_VALIDATION_MISSING_LEVEL = "com.ldtteam.structurize.pack_type.validation.missing_level";

private TranslationConstants()
{
//empty default
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package com.ldtteam.structurize.blueprints.v1;

import net.minecraft.core.BlockPos;
import org.jetbrains.annotations.Nullable;

/**
* Provides the details required to create a {@link Blueprint} from a world region
* via {@link BlueprintUtil#createBlueprint(IBlueprintDetails, net.minecraft.server.level.ServerLevel)}.
*
* <p>Implemented by both {@link com.ldtteam.structurize.index.models.PackSchematic} (for validation
* of stored schematics) and scan GUI providers (for live scans via {@link ScanUtil}).
*/
public interface IBlueprintDetails
{
/**
* Returns one corner of the bounding box.
*
* @return the first corner position
*/
BlockPos getPos1();

/**
* Returns the opposite corner of the bounding box.
*
* @return the second corner position
*/
BlockPos getPos2();

/**
* Returns the relative folder path of the schematic, empty for root-level schematics.
*
* @return the schematic folder path, never {@code null}
*/
String getSchematicPath();

/**
* Returns the schematic file name without extension.
*
* @return the schematic name, never {@code null}
*/
String getSchematicName();

/**
* Returns the building level this schematic represents, or {@code null} if no level suffix
* should be appended to the file name.
*
* @return the schematic level, or {@code null}
*/
@Nullable
Integer getSchematicLevel();

/**
* Returns the full schematic path including the file name and optional level digit (without extension).
* For example: {@code "huts/miner2"} for level 2, or {@code "huts/miner"} when level is {@code null}.
*
* @return the full schematic path
*/
default String getFullSchematicPath()
{
final String path = getSchematicPath();
final Integer level = getSchematicLevel();
final String nameWithLevel = level != null ? getSchematicName() + level : getSchematicName();
return path.isEmpty() ? nameWithLevel : path + "/" + nameWithLevel;
}

/**
* Returns the world position of the anchor block, or {@code null} if none is set.
*
* @return the anchor position, or {@code null}
*/
@Nullable
BlockPos getAnchor();

}
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ public static void register(final CommandDispatcher<CommandSourceStack> dispatch
.addNode(UpdateSchematicsCommand::build, () -> CommandSelection.INTEGRATED)
.addNode(ScanCommand::build, AbstractCommand::getEnvironmentType)
.addNode(PasteCommand::build, AbstractCommand::getEnvironmentType)
.addNode(PasteFolderCommand::build, AbstractCommand::getEnvironmentType)
.addNode(PasteFolderCommand::build, AbstractCommand::getEnvironmentType)
.addNode(UpgradeCommand.ToDO::build, () -> CommandSelection.ALL)
.addNode(UpdateSchematicPackCommand::build, () -> CommandSelection.ALL);
.addNode(UpdateSchematicPackCommand::build, () -> CommandSelection.ALL)
// TODO: Remove before publication — debug command only
.addNode(PackIndexCommand::build, PackIndexCommand::getEnvironmentType);

structurizeRoot.register(dispatcher, environment);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// TODO: Remove before publication — debug command only
package com.ldtteam.structurize.commands;

import com.ldtteam.structurize.index.PackManager;
import com.ldtteam.structurize.index.models.PackSchematic;
import com.ldtteam.structurize.index.models.PackSchematicValidationState;
import com.ldtteam.structurize.index.packtypes.PackTypesRegistry;
import com.mojang.brigadier.arguments.IntegerArgumentType;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands.CommandSelection;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class PackIndexCommand extends AbstractCommand
{
private static final Logger LOGGER = LogManager.getLogger();

public static final String NAME = "packindex";

protected static CommandSelection getEnvironmentType()
{
return CommandSelection.ALL;
}

protected static LiteralArgumentBuilder<CommandSourceStack> build()
{
return newLiteral(NAME)
.then(newLiteral("add")
.then(newLiteral("pack")
.then(newArgument("packName", StringArgumentType.string())
.executes(ctx -> addPack(ctx.getSource(), StringArgumentType.getString(ctx, "packName"), ctx.getSource().getLevel()))))
.then(newLiteral("schematic")
.then(newArgument("packId", StringArgumentType.string())
.then(newArgument("schematicName", StringArgumentType.string())
.then(newArgument("path", StringArgumentType.string())
.then(newArgument("level", IntegerArgumentType.integer(0))
.executes(ctx -> addSchematic(
ctx.getSource(),
StringArgumentType.getString(ctx, "packId"),
StringArgumentType.getString(ctx, "schematicName"),
StringArgumentType.getString(ctx, "path"),
IntegerArgumentType.getInteger(ctx, "level")))))))));
}

private static int addPack(final CommandSourceStack source, final String packName, final ServerLevel level)
{
final String newId = PackManager.addPack(packName, PackTypesRegistry.DEFAULT_PACK_TYPE, level);

if (newId != null)
{
LOGGER.info("[PackIndex] Added pack '{}'", packName);
source.sendSuccess(() -> net.minecraft.network.chat.Component.literal("Added pack: " + packName), false);
}
else
{
LOGGER.info("[PackIndex] Pack not added: '{}', duplicate name", packName);
source.sendSuccess(() -> net.minecraft.network.chat.Component.literal("Couldn't add pack: " + packName + ", duplicate name"), false);
}
return 1;
}

private static int addSchematic(
final CommandSourceStack source,
final String packId,
final String schematicName,
final String path,
final int level)
{
if (PackManager.getPack(packId) == null)
{
source.sendFailure(net.minecraft.network.chat.Component.literal("Pack not found: " + packId));
return 0;
}

final PackSchematic schematic = new PackSchematic(path, schematicName, level, BlockPos.ZERO, BlockPos.ZERO, null, new PackSchematicValidationState());
PackManager.addSchematic(packId, schematic);

LOGGER.info("[PackIndex] Added schematic '{}' to pack '{}'", schematicName, packId);
source.sendSuccess(() -> net.minecraft.network.chat.Component.literal("Added schematic '" + schematicName + "' to pack '" + packId + "'"), false);
return 1;
}
}
21 changes: 21 additions & 0 deletions src/main/java/com/ldtteam/structurize/event/EventSubscriber.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package com.ldtteam.structurize.event;

import com.ldtteam.structurize.commands.EntryPoint;
import com.ldtteam.structurize.index.PackManager;
import com.ldtteam.structurize.management.Manager;
import com.ldtteam.structurize.util.BlockUtils;
import com.ldtteam.structurize.util.IOPool;
import net.minecraft.server.level.ServerLevel;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.neoforge.event.RegisterCommandsEvent;
import net.neoforged.neoforge.event.entity.player.PlayerEvent;
import net.neoforged.neoforge.event.level.LevelEvent;
import net.neoforged.neoforge.event.server.ServerStoppingEvent;
import net.neoforged.neoforge.event.tick.LevelTickEvent;
import org.jetbrains.annotations.NotNull;
Expand All @@ -31,6 +34,24 @@ private EventSubscriber()
*
* @param event event
*/
@SubscribeEvent
public static void onLevelLoad(final LevelEvent.Load event)
{
PackManager.onLevelLoad(event);
}

@SubscribeEvent
public static void onLevelUnload(final LevelEvent.Unload event)
{
PackManager.onLevelUnload(event);
}

@SubscribeEvent
public static void onPlayerJoin(final PlayerEvent.PlayerLoggedInEvent event)
{
PackManager.onPlayerJoin(event);
}

@SubscribeEvent
public static void onRegisterCommands(final RegisterCommandsEvent event)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.ldtteam.common.language.LanguageHandler;
import com.ldtteam.structurize.api.constants.Constants;
import com.ldtteam.structurize.network.messages.SyncPackManagerMessage;
import com.ldtteam.structurize.datagen.BlockEntityTagProvider;
import com.ldtteam.structurize.datagen.BlockTagProvider;
import com.ldtteam.structurize.datagen.EntityTagProvider;
Expand All @@ -16,8 +17,12 @@
import net.neoforged.neoforge.data.event.GatherDataEvent;
import net.neoforged.neoforge.network.event.RegisterPayloadHandlersEvent;
import net.neoforged.neoforge.network.registration.PayloadRegistrar;
import net.neoforged.neoforge.registries.NewRegistryEvent;
import net.neoforged.neoforge.registries.RegistryBuilder;
import org.jetbrains.annotations.NotNull;

import static com.ldtteam.structurize.api.Registries.SCHEMATIC_INDEX_PACK_TYPES;

public class LifecycleSubscriber
{
@SubscribeEvent
Expand All @@ -44,6 +49,7 @@ public static void onNetworkRegistry(final RegisterPayloadHandlersEvent event)
ScanToolTeleportMessage.TYPE.register(registry);
SetTagInTool.TYPE.register(registry);
ShowScanMessage.TYPE.register(registry);
SyncPackManagerMessage.TYPE.register(registry);
SyncPreviewCacheToClient.TYPE.register(registry);
SyncPreviewCacheToServer.TYPE.register(registry);
SyncSettingsToServer.TYPE.register(registry);
Expand Down Expand Up @@ -78,4 +84,10 @@ public static void onDatagen(@NotNull final GatherDataEvent event)
generator.addProvider(event.includeServer(), new BlockTagProvider(event.getGenerator().getPackOutput(), Registries.BLOCK, event.getLookupProvider(), event.getExistingFileHelper()));
generator.addProvider(event.includeClient(), new EntityTagProvider(event.getGenerator().getPackOutput(), Registries.ENTITY_TYPE, event.getLookupProvider(), event.getExistingFileHelper()));
}

@SubscribeEvent
public static void registerNewRegistries(final NewRegistryEvent event)
{
event.create(new RegistryBuilder<>(SCHEMATIC_INDEX_PACK_TYPES).sync(true));
}
}
Loading
Loading