Added network commands.
This commit is contained in:
@@ -4,6 +4,8 @@
|
||||
- Re-added the `/refinedstorage disk create <player> <id>` command (raoulvdberge)
|
||||
- Added the `/refinedstorage disk list` command (raoulvdberge)
|
||||
- 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 JEI ghost ingredient dragging support (raoulvdberge)
|
||||
- Fixed text field not being focused in amount specifying screens (raoulvdberge)
|
||||
|
||||
|
||||
@@ -262,6 +262,11 @@ public interface INetwork {
|
||||
*/
|
||||
CompoundNBT writeToNbt(CompoundNBT tag);
|
||||
|
||||
/**
|
||||
* @return sampled tick times
|
||||
*/
|
||||
long[] getTickTimes();
|
||||
|
||||
/**
|
||||
* Marks the network dirty.
|
||||
*/
|
||||
|
||||
@@ -38,6 +38,7 @@ import net.minecraft.block.BlockState;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.Util;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.server.ServerWorld;
|
||||
@@ -87,6 +88,8 @@ public class Network implements INetwork, IRedstoneConfigurable {
|
||||
private boolean couldRun;
|
||||
private int ticksSinceUpdateChanged;
|
||||
private int ticks;
|
||||
private long[] tickTimes = new long[100];
|
||||
private int tickCounter = 0;
|
||||
|
||||
public Network(World world, BlockPos pos, NetworkType type) {
|
||||
this.pos = pos;
|
||||
@@ -142,6 +145,8 @@ public class Network implements INetwork, IRedstoneConfigurable {
|
||||
@Override
|
||||
public void update() {
|
||||
if (!world.isRemote) {
|
||||
long tickStart = Util.nanoTime();
|
||||
|
||||
if (ticks == 0) {
|
||||
redstonePowered = world.isBlockPowered(pos);
|
||||
}
|
||||
@@ -199,6 +204,9 @@ public class Network implements INetwork, IRedstoneConfigurable {
|
||||
world.setBlockState(pos, state.with(ControllerBlock.ENERGY_TYPE, energyType));
|
||||
}
|
||||
}
|
||||
|
||||
tickTimes[tickCounter % tickTimes.length] = Util.nanoTime() - tickStart;
|
||||
tickCounter++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -500,6 +508,11 @@ public class Network implements INetwork, IRedstoneConfigurable {
|
||||
return tag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long[] getTickTimes() {
|
||||
return tickTimes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty() {
|
||||
API.instance().getNetworkManager((ServerWorld) world).markForSaving();
|
||||
|
||||
@@ -41,7 +41,7 @@ public class CreateDiskCommand implements Command<CommandSource> {
|
||||
|
||||
IStorageDisk<?> disk = API.instance().getStorageDiskManager(context.getSource().getWorld()).get(id);
|
||||
if (disk == null) {
|
||||
context.getSource().sendErrorMessage(new TranslationTextComponent("commands.refinedstorage.createdisk.error.diskNotFound", id));
|
||||
context.getSource().sendErrorMessage(new TranslationTextComponent("commands.refinedstorage.disk.create.error.disk_not_found", id));
|
||||
} else {
|
||||
IStorageDiskFactory factory = API.instance().getStorageDiskRegistry().get(disk.getFactoryId());
|
||||
|
||||
@@ -69,7 +69,7 @@ public class CreateDiskCommand implements Command<CommandSource> {
|
||||
}
|
||||
|
||||
context.getSource().sendFeedback(new TranslationTextComponent(
|
||||
"commands.refinedstorage.createdisk.success",
|
||||
"commands.refinedstorage.disk.create.success",
|
||||
new StringTextComponent(id.toString()).setStyle(Styles.YELLOW),
|
||||
context.getSource().getDisplayName().deepCopy().setStyle(Styles.YELLOW)
|
||||
), false);
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
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 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 static ArgumentBuilder<CommandSource, ?> register() {
|
||||
return Commands.literal("get")
|
||||
.then(Commands.argument("dimension", DimensionArgument.getDimension())
|
||||
.then(Commands.argument("pos", BlockPosArgument.blockPos())
|
||||
.executes(new GetNetworkCommand())));
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
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.render.Styles;
|
||||
import net.minecraft.command.CommandSource;
|
||||
import net.minecraft.command.Commands;
|
||||
import net.minecraft.command.arguments.DimensionArgument;
|
||||
import net.minecraft.util.text.StringTextComponent;
|
||||
import net.minecraft.util.text.TranslationTextComponent;
|
||||
import net.minecraft.world.server.ServerWorld;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
|
||||
public class ListNetworkCommand implements Command<CommandSource> {
|
||||
private static final DecimalFormat TIME_FORMATTER = new DecimalFormat("########0.000");
|
||||
|
||||
public static ArgumentBuilder<CommandSource, ?> register() {
|
||||
return Commands.literal("list")
|
||||
.then(Commands.argument("dimension", DimensionArgument.getDimension())
|
||||
.executes(new ListNetworkCommand()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int run(CommandContext<CommandSource> context) throws CommandSyntaxException {
|
||||
ServerWorld world = DimensionArgument.getDimensionArgument(context, "dimension");
|
||||
|
||||
API.instance().getNetworkManager(world)
|
||||
.all()
|
||||
.stream()
|
||||
.map(NetworkInList::new)
|
||||
.sorted((a, b) -> Double.compare(b.tickTime, a.tickTime))
|
||||
.forEach(listItem -> sendInfo(context, listItem, false));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static class NetworkInList {
|
||||
private final double tickTime;
|
||||
private final double tps;
|
||||
private final INetwork network;
|
||||
|
||||
public NetworkInList(INetwork network) {
|
||||
this.network = network;
|
||||
// @Volatile: From CommandTps
|
||||
this.tickTime = mean(network.getTickTimes()) * 1.0E-6D;
|
||||
this.tps = Math.min(1000.0 / tickTime, 20);
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendInfo(CommandContext<CommandSource> context, NetworkInList listItem, boolean detailed) {
|
||||
context.getSource().sendFeedback(
|
||||
new TranslationTextComponent(
|
||||
"commands.refinedstorage.network.list.pos",
|
||||
listItem.network.getPosition().getX(),
|
||||
listItem.network.getPosition().getY(),
|
||||
listItem.network.getPosition().getZ()
|
||||
)
|
||||
.appendString(" [")
|
||||
.append(new TranslationTextComponent(
|
||||
"commands.refinedstorage.network.list.tick_times",
|
||||
new StringTextComponent(TIME_FORMATTER.format(listItem.tickTime)).setStyle(Styles.YELLOW),
|
||||
new StringTextComponent(TIME_FORMATTER.format(listItem.tps)).setStyle(Styles.YELLOW)
|
||||
))
|
||||
.appendString("]"), false);
|
||||
|
||||
if (detailed) {
|
||||
context.getSource().sendFeedback(new TranslationTextComponent("commands.refinedstorage.network.list.autocrafting_tasks",
|
||||
new StringTextComponent(listItem.network.getCraftingManager().getTasks().size() + "").setStyle(Styles.YELLOW)
|
||||
), false);
|
||||
|
||||
context.getSource().sendFeedback(new TranslationTextComponent("commands.refinedstorage.network.list.nodes",
|
||||
new StringTextComponent(listItem.network.getNodeGraph().all().size() + "").setStyle(Styles.YELLOW)
|
||||
), false);
|
||||
|
||||
context.getSource().sendFeedback(new TranslationTextComponent("commands.refinedstorage.network.list.energy_usage",
|
||||
new StringTextComponent(listItem.network.getEnergyUsage() + "").setStyle(Styles.YELLOW)
|
||||
), false);
|
||||
}
|
||||
}
|
||||
|
||||
private static long mean(long[] values) {
|
||||
long sum = 0L;
|
||||
for (long v : values) {
|
||||
sum += v;
|
||||
}
|
||||
return sum / values.length;
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,8 @@ package com.refinedmods.refinedstorage.setup;
|
||||
import com.refinedmods.refinedstorage.RS;
|
||||
import com.refinedmods.refinedstorage.command.disk.CreateDiskCommand;
|
||||
import com.refinedmods.refinedstorage.command.disk.ListDiskCommand;
|
||||
import com.refinedmods.refinedstorage.command.network.GetNetworkCommand;
|
||||
import com.refinedmods.refinedstorage.command.network.ListNetworkCommand;
|
||||
import com.refinedmods.refinedstorage.command.pattern.PatternDumpCommand;
|
||||
import net.minecraft.command.Commands;
|
||||
import net.minecraftforge.event.RegisterCommandsEvent;
|
||||
@@ -11,9 +13,14 @@ import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
public class ServerSetup {
|
||||
@SubscribeEvent
|
||||
public void onRegisterCommands(RegisterCommandsEvent e) {
|
||||
e.getDispatcher().register(Commands.literal(RS.ID).then(Commands.literal("pattern").then(PatternDumpCommand.register())));
|
||||
e.getDispatcher().register(Commands.literal(RS.ID).then(Commands.literal("disk")
|
||||
.then(CreateDiskCommand.register())
|
||||
.then(ListDiskCommand.register())));
|
||||
e.getDispatcher().register(Commands.literal(RS.ID)
|
||||
.then(Commands.literal("pattern")
|
||||
.then(PatternDumpCommand.register()))
|
||||
.then(Commands.literal("disk")
|
||||
.then(CreateDiskCommand.register())
|
||||
.then(ListDiskCommand.register()))
|
||||
.then(Commands.literal("network")
|
||||
.then(GetNetworkCommand.register())
|
||||
.then(ListNetworkCommand.register())));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -280,10 +280,8 @@
|
||||
"item.refinedstorage.security_card": "Sicherheitskarte",
|
||||
"item.refinedstorage.security_card.owner": "Besitzer: %s",
|
||||
"item.refinedstorage.processor_binding": "Prozessor Rohmaterial",
|
||||
|
||||
"commands.refinedstorage.createdisk.error.diskNotFound": "Speicherzelle %s konnte nicht gefunden werden.",
|
||||
"commands.refinedstorage.createdisk.success": "Speicherzelle %s erfolgreich an %s gegeben.",
|
||||
|
||||
"commands.refinedstorage.disk.create.error.disk_not_found": "Speicherzelle %s konnte nicht gefunden werden.",
|
||||
"commands.refinedstorage.disk.create.success": "Speicherzelle %s erfolgreich an %s gegeben.",
|
||||
"advancements.refinedstorage.controlling.description": "Stelle einen Kontrollblock her",
|
||||
"advancements.refinedstorage.connecting": "Verbinden",
|
||||
"advancements.refinedstorage.connecting.description": "Platziere zwei Geräte nebeneinander oder verwende ein Kabel um sie zu verbinden",
|
||||
|
||||
@@ -306,10 +306,14 @@
|
||||
"item.refinedstorage.security_card": "Security Card",
|
||||
"item.refinedstorage.security_card.owner": "Bound to: %s",
|
||||
"item.refinedstorage.processor_binding": "Processor Binding",
|
||||
|
||||
"commands.refinedstorage.createdisk.error.diskNotFound": "Disk %s was not found.",
|
||||
"commands.refinedstorage.createdisk.success": "Successfully gave disk %s to %s.",
|
||||
|
||||
"commands.refinedstorage.disk.create.error.disk_not_found": "Disk %s was not found.",
|
||||
"commands.refinedstorage.disk.create.success": "Successfully gave disk %s to %s.",
|
||||
"commands.refinedstorage.network.list.pos": "Network at X: %d, Y: %d, Z: %d",
|
||||
"commands.refinedstorage.network.list.tick_times": "Mean tick time: %s ms. Mean TPS: %s",
|
||||
"commands.refinedstorage.network.list.autocrafting_tasks": "%s tasks",
|
||||
"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.",
|
||||
"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",
|
||||
|
||||
@@ -306,10 +306,8 @@
|
||||
"item.refinedstorage.security_card": "セキュリティカード",
|
||||
"item.refinedstorage.security_card.owner": "所有者: %s",
|
||||
"item.refinedstorage.processor_binding": "プロセッサ接合材",
|
||||
|
||||
"commands.refinedstorage.createdisk.error.diskNotFound": "ディスク%sが見つかりません",
|
||||
"commands.refinedstorage.createdisk.success": "ディスク%sを%sに割り当てました",
|
||||
|
||||
"commands.refinedstorage.disk.create.error.disk_not_found": "ディスク%sが見つかりません",
|
||||
"commands.refinedstorage.disk.create.success": "ディスク%sを%sに割り当てました",
|
||||
"advancements.refinedstorage.controlling.description": "コントローラーを作る",
|
||||
"advancements.refinedstorage.connecting": "接続",
|
||||
"advancements.refinedstorage.connecting.description": "装置を隣接させて設置する他、ケーブルを使用することもできます",
|
||||
|
||||
@@ -305,10 +305,8 @@
|
||||
"item.refinedstorage.security_card": "Карта безопасности",
|
||||
"item.refinedstorage.security_card.owner": "Привязана к %s",
|
||||
"item.refinedstorage.processor_binding": "Связующий процессорный компонент",
|
||||
|
||||
"commands.refinedstorage.createdisk.error.diskNotFound": "Диск %s не был найден.",
|
||||
"commands.refinedstorage.createdisk.success": "Диск %s успешно выдан %s.",
|
||||
|
||||
"commands.refinedstorage.disk.create.error.disk_not_found": "Диск %s не был найден.",
|
||||
"commands.refinedstorage.disk.create.success": "Диск %s успешно выдан %s.",
|
||||
"advancements.refinedstorage.controlling.description": "Создайте контроллер",
|
||||
"advancements.refinedstorage.connecting": "Соединение",
|
||||
"advancements.refinedstorage.connecting.description": "Вы можете разместить все устройства вплотную друг с другом или использовать кабели, чтобы соединить их",
|
||||
|
||||
@@ -300,10 +300,8 @@
|
||||
"item.refinedstorage.cover": "伪装板",
|
||||
"item.refinedstorage.hollow_cover": "空心伪装板",
|
||||
"item.refinedstorage.processor_binding": "处理器粘合物",
|
||||
|
||||
"commands.refinedstorage.createdisk.error.diskNotFound": "磁盘 %s 未找到.",
|
||||
"commands.refinedstorage.createdisk.success": "成功把磁盘 %s 给了 %s.",
|
||||
|
||||
"commands.refinedstorage.disk.create.error.disk_not_found": "磁盘 %s 未找到.",
|
||||
"commands.refinedstorage.disk.create.success": "成功把磁盘 %s 给了 %s.",
|
||||
"advancements.refinedstorage.controlling.description": "合成了控制器",
|
||||
"advancements.refinedstorage.connecting": "连接",
|
||||
"advancements.refinedstorage.connecting.description": "您可以将所有设备放在一起或者使用【线缆】以将它们连接起来",
|
||||
|
||||
@@ -306,10 +306,8 @@
|
||||
"item.refinedstorage.security_card": "安全卡",
|
||||
"item.refinedstorage.security_card.owner": "綁定至: %s",
|
||||
"item.refinedstorage.processor_binding": "處理器黏合物",
|
||||
|
||||
"commands.refinedstorage.createdisk.error.diskNotFound": "磁碟 %s 未找到.",
|
||||
"commands.refinedstorage.createdisk.success": "成功把磁碟 %s 給了 %s.",
|
||||
|
||||
"commands.refinedstorage.disk.create.error.disk_not_found": "磁碟 %s 未找到.",
|
||||
"commands.refinedstorage.disk.create.success": "成功把磁碟 %s 給了 %s.",
|
||||
"advancements.refinedstorage.controlling.description": "合成一個控制器",
|
||||
"advancements.refinedstorage.connecting": "連接",
|
||||
"advancements.refinedstorage.connecting.description": "你可以將所有設備放在一起或者使用線纜以將它們連接起來",
|
||||
|
||||
Reference in New Issue
Block a user