mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2026-07-11 22:02:45 +00:00
Add button to view computer's folder
Implementation is a little awkward, as we can't send OPEN_FILE links from the server, so we ensure the client runs a /computercraft open-computer ID command instead. We then intercept this on the client side and use that to open the folder.
This commit is contained in:
@@ -21,6 +21,7 @@ import dan200.computercraft.shared.computer.core.ComputerFamily;
|
||||
import dan200.computercraft.shared.computer.core.ServerComputer;
|
||||
import dan200.computercraft.shared.computer.inventory.ContainerViewComputer;
|
||||
import dan200.computercraft.shared.network.container.ViewComputerContainerData;
|
||||
import dan200.computercraft.shared.util.IDAssigner;
|
||||
import net.minecraft.command.CommandSource;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
@@ -37,6 +38,7 @@ import net.minecraft.world.World;
|
||||
import net.minecraft.world.server.ServerWorld;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
|
||||
import static dan200.computercraft.shared.command.CommandUtils.isPlayer;
|
||||
@@ -320,6 +322,12 @@ public final class CommandComputerCraft
|
||||
) );
|
||||
}
|
||||
|
||||
if( UserLevel.OWNER.test( source ) && isPlayer( source ) )
|
||||
{
|
||||
ITextComponent linkPath = linkStorage( computerId );
|
||||
if( linkPath != null ) out.append( " " ).append( linkPath );
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
@@ -339,6 +347,18 @@ public final class CommandComputerCraft
|
||||
}
|
||||
}
|
||||
|
||||
private static ITextComponent linkStorage( int id )
|
||||
{
|
||||
File file = new File( IDAssigner.getDir(), "computer/" + id );
|
||||
if( !file.isDirectory() ) return null;
|
||||
|
||||
return link(
|
||||
text( "\u270E" ),
|
||||
ClientCommands.OPEN_COMPUTER + id,
|
||||
translate( "commands.computercraft.dump.open_path" )
|
||||
);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
private static TrackingContext getTimingContext( CommandSource source )
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user