Implement autocrafting list and get command

This commit is contained in:
raoulvdberge
2020-09-05 21:38:35 +02:00
parent 494ac95737
commit 6768aa1bbf
8 changed files with 198 additions and 21 deletions

View File

@@ -6,6 +6,8 @@
- Added the `/refinedstorage disk list <player>` command (raoulvdberge)
- Added the `/refinedstorage network list <dimension>` command (raoulvdberge)
- Added the `/refinedstorage network get <dimension> <pos>` command (raoulvdberge)
- Added the `/refinedstorage network get <dimension> <pos> autocrafting list` command (raoulvdberge)
- Added the `/refinedstorage network get <dimension> <pos> autocrafting get <id>` command (raoulvdberge)
- Added JEI ghost ingredient dragging support (raoulvdberge)
- Fixed text field not being focused in amount specifying screens (raoulvdberge)

View File

@@ -1,40 +1,30 @@
package com.refinedmods.refinedstorage.command.network;
import com.mojang.brigadier.Command;
import com.mojang.brigadier.builder.ArgumentBuilder;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.refinedmods.refinedstorage.api.network.INetwork;
import com.refinedmods.refinedstorage.apiimpl.API;
import com.refinedmods.refinedstorage.command.network.autocrafting.GetAutocraftingCommand;
import com.refinedmods.refinedstorage.command.network.autocrafting.ListAutocraftingCommand;
import net.minecraft.command.CommandSource;
import net.minecraft.command.Commands;
import net.minecraft.command.arguments.BlockPosArgument;
import net.minecraft.command.arguments.DimensionArgument;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraft.world.server.ServerWorld;
public class GetNetworkCommand implements Command<CommandSource> {
public class GetNetworkCommand extends NetworkCommand {
public static ArgumentBuilder<CommandSource, ?> register() {
return Commands.literal("get")
.then(Commands.argument("dimension", DimensionArgument.getDimension())
.then(Commands.argument("pos", BlockPosArgument.blockPos())
.executes(new GetNetworkCommand())));
.then(Commands.argument("pos", BlockPosArgument.blockPos()).suggests(new NetworkPositionSuggestionProvider())
.executes(new GetNetworkCommand())
.then(Commands.literal("autocrafting")
.then(ListAutocraftingCommand.register())
.then(GetAutocraftingCommand.register())
)));
}
@Override
public int run(CommandContext<CommandSource> context) throws CommandSyntaxException {
ServerWorld world = DimensionArgument.getDimensionArgument(context, "dimension");
BlockPos pos = BlockPosArgument.getBlockPos(context, "pos");
INetwork network = API.instance().getNetworkManager(world).getNetwork(pos);
if (network == null) {
context.getSource().sendErrorMessage(new TranslationTextComponent("commands.refinedstorage.network.get.error.not_found"));
} else {
ListNetworkCommand.sendInfo(context, new ListNetworkCommand.NetworkInList(network), true);
}
protected int run(CommandContext<CommandSource> context, INetwork network) {
ListNetworkCommand.sendInfo(context, new ListNetworkCommand.NetworkInList(network), true);
return 0;
}
}

View File

@@ -0,0 +1,32 @@
package com.refinedmods.refinedstorage.command.network;
import com.mojang.brigadier.Command;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.refinedmods.refinedstorage.api.network.INetwork;
import com.refinedmods.refinedstorage.apiimpl.API;
import net.minecraft.command.CommandSource;
import net.minecraft.command.arguments.BlockPosArgument;
import net.minecraft.command.arguments.DimensionArgument;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraft.world.server.ServerWorld;
public abstract class NetworkCommand implements Command<CommandSource> {
@Override
public int run(CommandContext<CommandSource> context) throws CommandSyntaxException {
ServerWorld world = DimensionArgument.getDimensionArgument(context, "dimension");
BlockPos pos = BlockPosArgument.getBlockPos(context, "pos");
INetwork network = API.instance().getNetworkManager(world).getNetwork(pos);
if (network == null) {
context.getSource().sendErrorMessage(new TranslationTextComponent("commands.refinedstorage.network.get.error.not_found"));
return 0;
} else {
return run(context, network);
}
}
protected abstract int run(CommandContext<CommandSource> context, INetwork network) throws CommandSyntaxException;
}

View File

@@ -0,0 +1,24 @@
package com.refinedmods.refinedstorage.command.network;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.suggestion.SuggestionProvider;
import com.mojang.brigadier.suggestion.Suggestions;
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
import com.refinedmods.refinedstorage.apiimpl.API;
import net.minecraft.command.CommandSource;
import net.minecraft.command.arguments.DimensionArgument;
import net.minecraft.world.server.ServerWorld;
import java.util.concurrent.CompletableFuture;
public class NetworkPositionSuggestionProvider implements SuggestionProvider<CommandSource> {
@Override
public CompletableFuture<Suggestions> getSuggestions(CommandContext<CommandSource> context, SuggestionsBuilder builder) throws CommandSyntaxException {
ServerWorld world = DimensionArgument.getDimensionArgument(context, "dimension");
API.instance().getNetworkManager(world).all().forEach(network -> builder.suggest(network.getPosition().getX() + " " + network.getPosition().getY() + " " + network.getPosition().getZ()));
return builder.buildFuture();
}
}

View File

@@ -0,0 +1,31 @@
package com.refinedmods.refinedstorage.command.network.autocrafting;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.suggestion.SuggestionProvider;
import com.mojang.brigadier.suggestion.Suggestions;
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
import com.refinedmods.refinedstorage.api.network.INetwork;
import com.refinedmods.refinedstorage.apiimpl.API;
import net.minecraft.command.CommandSource;
import net.minecraft.command.arguments.BlockPosArgument;
import net.minecraft.command.arguments.DimensionArgument;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.server.ServerWorld;
import java.util.concurrent.CompletableFuture;
public class AutocraftingIdSuggestionProvider implements SuggestionProvider<CommandSource> {
@Override
public CompletableFuture<Suggestions> getSuggestions(CommandContext<CommandSource> context, SuggestionsBuilder builder) throws CommandSyntaxException {
ServerWorld world = DimensionArgument.getDimensionArgument(context, "dimension");
BlockPos pos = BlockPosArgument.getBlockPos(context, "pos");
INetwork network = API.instance().getNetworkManager(world).getNetwork(pos);
if (network != null) {
network.getCraftingManager().getTasks().forEach(task -> builder.suggest(task.getId().toString()));
}
return builder.buildFuture();
}
}

View File

@@ -0,0 +1,36 @@
package com.refinedmods.refinedstorage.command.network.autocrafting;
import com.mojang.brigadier.builder.ArgumentBuilder;
import com.mojang.brigadier.context.CommandContext;
import com.refinedmods.refinedstorage.api.autocrafting.task.ICraftingTask;
import com.refinedmods.refinedstorage.api.network.INetwork;
import com.refinedmods.refinedstorage.command.network.NetworkCommand;
import net.minecraft.command.CommandSource;
import net.minecraft.command.Commands;
import net.minecraft.command.arguments.UUIDArgument;
import net.minecraft.util.text.TranslationTextComponent;
import java.util.UUID;
public class GetAutocraftingCommand extends NetworkCommand {
public static ArgumentBuilder<CommandSource, ?> register() {
return Commands.literal("get").then(
Commands.argument("id", UUIDArgument.func_239194_a_()).suggests(new AutocraftingIdSuggestionProvider())
.executes(new GetAutocraftingCommand())
);
}
@Override
protected int run(CommandContext<CommandSource> context, INetwork network) {
UUID id = UUIDArgument.func_239195_a_(context, "id");
ICraftingTask task = network.getCraftingManager().getTask(id);
if (task == null) {
context.getSource().sendErrorMessage(new TranslationTextComponent("commands.refinedstorage.network.autocrafting.get.error.not_found"));
} else {
ListAutocraftingCommand.addInfo(context, task);
}
return 0;
}
}

View File

@@ -0,0 +1,61 @@
package com.refinedmods.refinedstorage.command.network.autocrafting;
import com.mojang.brigadier.builder.ArgumentBuilder;
import com.mojang.brigadier.context.CommandContext;
import com.refinedmods.refinedstorage.api.autocrafting.task.ICraftingRequestInfo;
import com.refinedmods.refinedstorage.api.autocrafting.task.ICraftingTask;
import com.refinedmods.refinedstorage.api.network.INetwork;
import com.refinedmods.refinedstorage.command.network.NetworkCommand;
import com.refinedmods.refinedstorage.render.Styles;
import net.minecraft.command.CommandSource;
import net.minecraft.command.Commands;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.StringTextComponent;
public class ListAutocraftingCommand extends NetworkCommand {
public static ArgumentBuilder<CommandSource, ?> register() {
return Commands.literal("list").executes(new ListAutocraftingCommand());
}
@Override
protected int run(CommandContext<CommandSource> context, INetwork network) {
network.getCraftingManager().getTasks().forEach(task -> addInfo(context, task));
return 0;
}
public static void addInfo(CommandContext<CommandSource> context, ICraftingTask task) {
context.getSource().sendFeedback(
new StringTextComponent(getAmount(task.getRequested()) + "x ")
.append(getName(task.getRequested()).deepCopy().setStyle(Styles.YELLOW))
.appendString(" ")
.appendString("(" + task.getCompletionPercentage() + "%)")
.appendString(" ")
.append(new StringTextComponent("[" + task.getId().toString() + "]").setStyle(Styles.GRAY)),
false
);
}
private static int getAmount(ICraftingRequestInfo info) {
if (info.getItem() != null) {
return info.getItem().getCount();
}
if (info.getFluid() != null) {
return info.getFluid().getAmount();
}
return 0;
}
private static ITextComponent getName(ICraftingRequestInfo info) {
if (info.getItem() != null) {
return info.getItem().getDisplayName();
}
if (info.getFluid() != null) {
return info.getFluid().getDisplayName();
}
return StringTextComponent.EMPTY;
}
}

View File

@@ -314,6 +314,7 @@
"commands.refinedstorage.network.list.nodes": "%s nodes",
"commands.refinedstorage.network.list.energy_usage": "Energy usage: %s",
"commands.refinedstorage.network.get.error.not_found": "Network not found.",
"commands.refinedstorage.network.autocrafting.get.error.not_found": "Task not found.",
"advancements.refinedstorage.controlling.description": "Craft a Controller",
"advancements.refinedstorage.connecting": "Connecting",
"advancements.refinedstorage.connecting.description": "You can place all the devices next to each other to connect them up, or, use Cable",