command "/pocket log creation"
logs to chat whenever a SchematicGenerator generates a pocket
This commit is contained in:
parent
444bc184d1
commit
09b3f6f05c
4 changed files with 48 additions and 1 deletions
|
@ -18,6 +18,7 @@ import org.dimdev.dimdoors.block.door.DimensionalDoorBlockRegistrar;
|
||||||
import org.dimdev.dimdoors.block.door.data.condition.Condition;
|
import org.dimdev.dimdoors.block.door.data.condition.Condition;
|
||||||
import org.dimdev.dimdoors.block.entity.ModBlockEntityTypes;
|
import org.dimdev.dimdoors.block.entity.ModBlockEntityTypes;
|
||||||
import org.dimdev.dimdoors.command.ModCommands;
|
import org.dimdev.dimdoors.command.ModCommands;
|
||||||
|
import org.dimdev.dimdoors.command.PocketCommand;
|
||||||
import org.dimdev.dimdoors.enchantment.FrayedEnchantment;
|
import org.dimdev.dimdoors.enchantment.FrayedEnchantment;
|
||||||
import org.dimdev.dimdoors.enchantment.ModEnchants;
|
import org.dimdev.dimdoors.enchantment.ModEnchants;
|
||||||
import org.dimdev.dimdoors.entity.ModEntityTypes;
|
import org.dimdev.dimdoors.entity.ModEntityTypes;
|
||||||
|
@ -164,6 +165,7 @@ public class DimensionalDoorsInitializer implements ModInitializer {
|
||||||
|
|
||||||
ServerPlayConnectionEvents.DISCONNECT.register((handler, server) -> {
|
ServerPlayConnectionEvents.DISCONNECT.register((handler, server) -> {
|
||||||
((ExtendedServerPlayNetworkHandler) handler).getDimDoorsPacketHandler().unregister();
|
((ExtendedServerPlayNetworkHandler) handler).getDimDoorsPacketHandler().unregister();
|
||||||
|
PocketCommand.logSetting.remove(handler.getPlayer().getUuid());
|
||||||
});
|
});
|
||||||
|
|
||||||
ServerChunkEvents.CHUNK_LOAD.register(new ChunkLoadListener()); // lazy pocket gen
|
ServerChunkEvents.CHUNK_LOAD.register(new ChunkLoadListener()); // lazy pocket gen
|
||||||
|
|
|
@ -17,12 +17,19 @@ import net.minecraft.text.TranslatableText;
|
||||||
|
|
||||||
import net.fabricmc.loader.api.FabricLoader;
|
import net.fabricmc.loader.api.FabricLoader;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
import static net.minecraft.server.command.CommandManager.argument;
|
import static net.minecraft.server.command.CommandManager.argument;
|
||||||
import static net.minecraft.server.command.CommandManager.literal;
|
import static net.minecraft.server.command.CommandManager.literal;
|
||||||
|
|
||||||
public class PocketCommand {
|
public class PocketCommand {
|
||||||
private static final Logger LOGGER = LogManager.getLogger();
|
private static final Logger LOGGER = LogManager.getLogger();
|
||||||
|
|
||||||
|
// TODO: probably move somewhere else
|
||||||
|
public static final Map<UUID, ServerCommandSource> logSetting = new HashMap<>();
|
||||||
|
|
||||||
public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
|
public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
|
||||||
dispatcher.register(
|
dispatcher.register(
|
||||||
literal("pocket")
|
literal("pocket")
|
||||||
|
@ -49,6 +56,26 @@ public class PocketCommand {
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
.then(
|
||||||
|
literal("log")
|
||||||
|
// TODO: make command toggle logging of pocket creation to console if used from console
|
||||||
|
.then(literal("creation")
|
||||||
|
.requires(commandSource -> commandSource.getEntity() instanceof ServerPlayerEntity)
|
||||||
|
.executes(ctx -> {
|
||||||
|
ServerCommandSource commandSource = ctx.getSource();
|
||||||
|
UUID playerUUID = commandSource.getPlayer().getUuid();
|
||||||
|
if (logSetting.containsKey(playerUUID)) {
|
||||||
|
logSetting.remove(playerUUID);
|
||||||
|
commandSource.sendFeedback(new TranslatableText("commands.pocket.log.creation.off"), false);
|
||||||
|
} else {
|
||||||
|
logSetting.put(playerUUID, commandSource);
|
||||||
|
commandSource.sendFeedback(new TranslatableText("commands.pocket.log.creation.on"), false);
|
||||||
|
}
|
||||||
|
return Command.SINGLE_SUCCESS;
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,19 @@
|
||||||
package org.dimdev.dimdoors.pockets.generator;
|
package org.dimdev.dimdoors.pockets.generator;
|
||||||
|
|
||||||
|
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
|
||||||
import net.fabricmc.fabric.api.util.NbtType;
|
import net.fabricmc.fabric.api.util.NbtType;
|
||||||
|
import net.fabricmc.loader.api.FabricLoader;
|
||||||
|
import net.minecraft.client.network.PlayerListEntry;
|
||||||
|
import net.minecraft.client.network.ServerInfo;
|
||||||
import net.minecraft.nbt.NbtCompound;
|
import net.minecraft.nbt.NbtCompound;
|
||||||
|
import net.minecraft.server.MinecraftServer;
|
||||||
|
import net.minecraft.server.PlayerManager;
|
||||||
|
import net.minecraft.server.network.ServerPlayNetworkHandler;
|
||||||
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
|
import net.minecraft.server.network.ServerPlayerInteractionManager;
|
||||||
|
import net.minecraft.server.world.ServerEntityManager;
|
||||||
import net.minecraft.server.world.ServerWorld;
|
import net.minecraft.server.world.ServerWorld;
|
||||||
|
import net.minecraft.text.TranslatableText;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.Vec3i;
|
import net.minecraft.util.math.Vec3i;
|
||||||
|
@ -11,6 +22,7 @@ import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.dimdev.dimdoors.api.util.Path;
|
import org.dimdev.dimdoors.api.util.Path;
|
||||||
import org.dimdev.dimdoors.block.entity.RiftBlockEntity;
|
import org.dimdev.dimdoors.block.entity.RiftBlockEntity;
|
||||||
|
import org.dimdev.dimdoors.command.PocketCommand;
|
||||||
import org.dimdev.dimdoors.pockets.PocketLoader;
|
import org.dimdev.dimdoors.pockets.PocketLoader;
|
||||||
import org.dimdev.dimdoors.pockets.PocketTemplate;
|
import org.dimdev.dimdoors.pockets.PocketTemplate;
|
||||||
import org.dimdev.dimdoors.pockets.modifier.AbsoluteRiftBlockEntityModifier;
|
import org.dimdev.dimdoors.pockets.modifier.AbsoluteRiftBlockEntityModifier;
|
||||||
|
@ -144,7 +156,10 @@ public class SchematicGenerator extends LazyPocketGenerator{
|
||||||
if (template == null) throw new RuntimeException("Pocket template of id " + templateID + " not found!");
|
if (template == null) throw new RuntimeException("Pocket template of id " + templateID + " not found!");
|
||||||
|
|
||||||
Pocket pocket = DimensionalRegistry.getPocketDirectory(world.getRegistryKey()).newPocket(builder);
|
Pocket pocket = DimensionalRegistry.getPocketDirectory(world.getRegistryKey()).newPocket(builder);
|
||||||
LOGGER.info("Generating pocket from template " + templateID + " at location " + pocket.getOrigin());
|
BlockPos origin = pocket.getOrigin();
|
||||||
|
LOGGER.info("Generating pocket from template " + templateID + " at location " + origin);
|
||||||
|
PocketCommand.logSetting.values().forEach(commandSource -> commandSource.sendFeedback(new TranslatableText("commands.pocket.log.creation.generating", templateID, origin.getX(), origin.getY(), origin.getZ()), false));
|
||||||
|
|
||||||
|
|
||||||
if (pocket instanceof LazyGenerationPocket) {
|
if (pocket instanceof LazyGenerationPocket) {
|
||||||
Map<BlockPos, RiftBlockEntity> absoluteRifts = template.getAbsoluteRifts(pocket);
|
Map<BlockPos, RiftBlockEntity> absoluteRifts = template.getAbsoluteRifts(pocket);
|
||||||
|
|
|
@ -160,6 +160,9 @@
|
||||||
"commands.pocket.unknownPocketTemplate": "Unknown Pocket Template '%s'",
|
"commands.pocket.unknownPocketTemplate": "Unknown Pocket Template '%s'",
|
||||||
"commands.pocket.placedSchem": "Placed schematic %s at %s in world %s",
|
"commands.pocket.placedSchem": "Placed schematic %s at %s in world %s",
|
||||||
"commands.pocket.loadedSchem": "Loaded schematic %s to clipboard. Paste it using //paste",
|
"commands.pocket.loadedSchem": "Loaded schematic %s to clipboard. Paste it using //paste",
|
||||||
|
"commands.pocket.log.creation.off": "Toggled logging of pocket creation off.",
|
||||||
|
"commands.pocket.log.creation.on": "Toggled logging of pocket creation on.",
|
||||||
|
"commands.pocket.log.creation.generating": "Generating pocket from template '%s' at location %s %s %s",
|
||||||
|
|
||||||
"rifts.unlinked1": "This rift doesn't lead anywhere",
|
"rifts.unlinked1": "This rift doesn't lead anywhere",
|
||||||
"rifts.unlinked2": "This rift has closed",
|
"rifts.unlinked2": "This rift has closed",
|
||||||
|
|
Loading…
Reference in a new issue