mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-10-23 18:07:39 +00:00
Use client-side commands for opening computer folders
Forge doesn't run client-side commands from sendUnsignedCommand, so we still require a mixin there. We do need to change the command name, as Fabric doesn't properly merge the two command trees.
This commit is contained in:
@@ -106,10 +106,8 @@ minecraft {
|
||||
}
|
||||
|
||||
mixin {
|
||||
add(sourceSets.main.get(), "computercraft.refmap.json")
|
||||
add(sourceSets.client.get(), "client-computercraft.refmap.json")
|
||||
|
||||
config("computercraft-client.mixins.json")
|
||||
config("computercraft-client.forge.mixins.json")
|
||||
}
|
||||
|
||||
|
@@ -6,11 +6,9 @@ package dan200.computercraft.client;
|
||||
|
||||
import dan200.computercraft.api.ComputerCraftAPI;
|
||||
import dan200.computercraft.client.sound.SpeakerSound;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.client.event.CustomizeGuiOverlayEvent;
|
||||
import net.minecraftforge.client.event.RenderHandEvent;
|
||||
import net.minecraftforge.client.event.RenderHighlightEvent;
|
||||
import net.minecraftforge.client.event.RenderItemInFrameEvent;
|
||||
import net.minecraftforge.client.event.*;
|
||||
import net.minecraftforge.client.event.sound.PlayStreamingSourceEvent;
|
||||
import net.minecraftforge.event.TickEvent;
|
||||
import net.minecraftforge.event.level.LevelEvent;
|
||||
@@ -78,4 +76,9 @@ public final class ForgeClientHooks {
|
||||
if (!(event.getSound() instanceof SpeakerSound sound) || sound.getStream() == null) return;
|
||||
ClientHooks.onPlayStreaming(event.getEngine(), event.getChannel(), sound.getStream());
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void registerClientCommands(RegisterClientCommandsEvent event) {
|
||||
ClientRegistry.registerClientCommands(event.getDispatcher(), CommandSourceStack::sendFailure);
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,26 @@
|
||||
// SPDX-FileCopyrightText: 2022 The CC: Tweaked Developers
|
||||
//
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
package dan200.computercraft.mixin.client;
|
||||
|
||||
import dan200.computercraft.shared.command.CommandComputerCraft;
|
||||
import net.minecraft.client.multiplayer.ClientPacketListener;
|
||||
import net.minecraftforge.client.ClientCommandHandler;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
/**
|
||||
* Allows triggering ComputerCraft's client commands from chat components events.
|
||||
*/
|
||||
@Mixin(ClientPacketListener.class)
|
||||
class ClientPacketListenerMixin {
|
||||
@Inject(method = "sendUnsignedCommand", at = @At("HEAD"), cancellable = true)
|
||||
void commandUnsigned(String command, CallbackInfoReturnable<Boolean> ci) {
|
||||
if (command.startsWith(CommandComputerCraft.CLIENT_OPEN_FOLDER) && ClientCommandHandler.runCommand(command)) {
|
||||
ci.setReturnValue(true);
|
||||
}
|
||||
}
|
||||
}
|
@@ -7,7 +7,8 @@
|
||||
"defaultRequire": 1
|
||||
},
|
||||
"client": [
|
||||
"BlockRenderDispatcherMixin"
|
||||
"BlockRenderDispatcherMixin",
|
||||
"ClientPacketListenerMixin"
|
||||
],
|
||||
"refmap": "client-computercraft.refmap.json"
|
||||
}
|
||||
|
Reference in New Issue
Block a user