mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-08-30 00:57:55 +00:00
Store command computers in a separate folder
- Remove the /computercraft-computer-folder client command, and replace it with OPEN_FILE on NeoForge, or a /computercraft-open-folder command on Fabric (which now accepts a path, rather than an id). - Store command computer files in "computercraft/command_computer/<id>". Fixes #1581.
This commit is contained in:
@@ -4,11 +4,15 @@
|
||||
|
||||
package dan200.computercraft.client;
|
||||
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
||||
import dan200.computercraft.api.ComputerCraftAPI;
|
||||
import dan200.computercraft.api.client.FabricComputerCraftAPIClient;
|
||||
import dan200.computercraft.client.model.ExtraModels;
|
||||
import dan200.computercraft.core.util.Nullability;
|
||||
import dan200.computercraft.impl.Services;
|
||||
import dan200.computercraft.shared.ComputerCraft;
|
||||
import dan200.computercraft.shared.ModRegistry;
|
||||
import dan200.computercraft.shared.config.ConfigSpec;
|
||||
import dan200.computercraft.shared.network.NetworkMessages;
|
||||
@@ -22,6 +26,7 @@ import net.fabricmc.fabric.api.client.model.loading.v1.PreparableModelLoadingPlu
|
||||
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
|
||||
import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderEvents;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.color.item.ItemTintSources;
|
||||
import net.minecraft.client.gui.screens.MenuScreens;
|
||||
@@ -31,6 +36,8 @@ import net.minecraft.client.renderer.item.properties.conditional.ConditionalItem
|
||||
import net.minecraft.client.renderer.item.properties.select.SelectItemModelProperties;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import static dan200.computercraft.core.util.Nullability.assertNonNull;
|
||||
@@ -75,9 +82,17 @@ public class ComputerCraftClient {
|
||||
}
|
||||
});
|
||||
|
||||
ClientCommandRegistrationCallback.EVENT.register(
|
||||
(dispatcher, registryAccess) -> ClientRegistry.registerClientCommands(dispatcher, FabricClientCommandSource::sendError)
|
||||
);
|
||||
// Register our open folder command
|
||||
ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) ->
|
||||
dispatcher.register(LiteralArgumentBuilder.<FabricClientCommandSource>literal(ComputerCraft.CLIENT_OPEN_FOLDER)
|
||||
.requires(x -> Minecraft.getInstance().getSingleplayerServer() != null)
|
||||
.then(RequiredArgumentBuilder.<FabricClientCommandSource, String>argument("path", StringArgumentType.string())
|
||||
.executes(c -> {
|
||||
var file = Path.of(c.getArgument("path", String.class));
|
||||
if (Files.isDirectory(file)) Util.getPlatform().openFile(file.toFile());
|
||||
return 0;
|
||||
})
|
||||
)));
|
||||
|
||||
((FabricConfigFile) ConfigSpec.clientSpec).load(FabricLoader.getInstance().getConfigDir().resolve(ComputerCraftAPI.MOD_ID + "-client.toml"));
|
||||
}
|
||||
|
@@ -64,6 +64,12 @@ import java.util.function.BiFunction;
|
||||
public class ComputerCraft {
|
||||
private static final LevelResource SERVERCONFIG = new LevelResource("serverconfig");
|
||||
|
||||
/**
|
||||
* The client-side command to open a folder. Ideally this would live under the main {@code computercraft}
|
||||
* namespace, but unfortunately that overrides commands, rather than merging them.
|
||||
*/
|
||||
public static final String CLIENT_OPEN_FOLDER = "computercraft-open-folder";
|
||||
|
||||
public static void init() {
|
||||
for (var type : NetworkMessages.getServerbound()) registerPayloadType(PayloadTypeRegistry.playC2S(), type);
|
||||
for (var type : NetworkMessages.getClientbound()) registerPayloadType(PayloadTypeRegistry.playS2C(), type);
|
||||
|
@@ -7,6 +7,7 @@ package dan200.computercraft.shared.platform;
|
||||
import com.google.auto.service.AutoService;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.brigadier.arguments.ArgumentType;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import dan200.computercraft.api.ComputerCraftAPI;
|
||||
import dan200.computercraft.api.media.IMedia;
|
||||
import dan200.computercraft.api.media.MediaLookup;
|
||||
@@ -16,6 +17,7 @@ import dan200.computercraft.api.peripheral.IPeripheral;
|
||||
import dan200.computercraft.api.peripheral.PeripheralLookup;
|
||||
import dan200.computercraft.impl.Peripherals;
|
||||
import dan200.computercraft.mixin.ArgumentTypeInfosAccessor;
|
||||
import dan200.computercraft.shared.ComputerCraft;
|
||||
import dan200.computercraft.shared.config.ConfigFile;
|
||||
import dan200.computercraft.shared.network.container.ContainerData;
|
||||
import dan200.computercraft.shared.util.InventoryUtil;
|
||||
@@ -37,6 +39,7 @@ import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.network.RegistryFriendlyByteBuf;
|
||||
import net.minecraft.network.chat.ClickEvent;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.codec.StreamCodec;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
@@ -64,6 +67,7 @@ import net.minecraft.world.phys.EntityHitResult;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
@@ -235,6 +239,14 @@ public class PlatformHelperImpl implements PlatformHelper {
|
||||
return MediaLookup.get().find(stack, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClickEvent createOpenFolderAction(Path path) {
|
||||
return new ClickEvent(
|
||||
ClickEvent.Action.RUN_COMMAND,
|
||||
"/" + ComputerCraft.CLIENT_OPEN_FOLDER + " " + StringArgumentType.escapeIfRequired(path.toAbsolutePath().toString())
|
||||
);
|
||||
}
|
||||
|
||||
private static final class RegistrationHelperImpl<T> implements RegistrationHelper<T> {
|
||||
private final Registry<T> registry;
|
||||
private final List<RegistryEntryImpl<? extends T>> entries = new ArrayList<>();
|
||||
|
Reference in New Issue
Block a user