Skip to content

Commit

Permalink
Merge pull request #1 from EpimorphicPioneers/dancingsnow-dev
Browse files Browse the repository at this point in the history
让网络终端堆叠为1,添加几个网络修改的基础命令
  • Loading branch information
qwer523 authored May 25, 2024
2 parents 5e458d9 + c4ebd10 commit 9d36bc7
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 9 deletions.
7 changes: 6 additions & 1 deletion src/generated/resources/assets/eunetwork/lang/en_ud.json
Original file line number Diff line number Diff line change
Expand Up @@ -247,5 +247,10 @@
"block.eunetwork.zpm_wireless_energy_output_hatch_4a": "ɥɔʇɐH oɯɐuʎᗡ ssǝןǝɹıM Ɐㄣɹ§ WԀZɔ§",
"block.eunetwork.zpm_wireless_energy_output_hatch_64a": "ɥɔʇɐH oɯɐuʎᗡ ssǝןǝɹıM Ɐㄣ9ɹ§ WԀZɔ§",
"block.eunetwork.zpm_wireless_energy_output_hatch_65536a": "ɥɔʇɐH oɯɐuʎᗡ ssǝןǝɹıM Ɐ9Ɛϛϛ9ɹ§ WԀZɔ§",
"item.eunetwork.eunetwork_terminal": "ןɐuıɯɹǝ⟘ ʞɹoʍʇǝN∩Ǝ"
"item.eunetwork.eunetwork_terminal": "ןɐuıɯɹǝ⟘ ʞɹoʍʇǝN∩Ǝ",
"message.eunetwork.add_successed": "%s :pǝppɐ 'ʎןןnɟssǝɔɔns pǝppɐ ʎbɹǝuƎ %d ʞɹoʍʇǝN",
"message.eunetwork.invalid_network": "%d :ʞɹoʍʇǝN pıןɐʌuI",
"message.eunetwork.invalid_number": "%s :ɹǝqɯnu pıןɐʌuI",
"message.eunetwork.network_id": "%d :ᗡI ʞɹoʍʇǝN",
"message.eunetwork.network_storage": "∩Ǝ %s :ǝbɐɹoʇS"
}
7 changes: 6 additions & 1 deletion src/generated/resources/assets/eunetwork/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -247,5 +247,10 @@
"block.eunetwork.zpm_wireless_energy_output_hatch_4a": "§cZPM §r4A Wireless Dynamo Hatch",
"block.eunetwork.zpm_wireless_energy_output_hatch_64a": "§cZPM §r64A Wireless Dynamo Hatch",
"block.eunetwork.zpm_wireless_energy_output_hatch_65536a": "§cZPM §r65536A Wireless Dynamo Hatch",
"item.eunetwork.eunetwork_terminal": "EUNetwork Terminal"
"item.eunetwork.eunetwork_terminal": "EUNetwork Terminal",
"message.eunetwork.add_successed": "Network %d Energy added successfully, added: %s",
"message.eunetwork.invalid_network": "Invalid Network: %d",
"message.eunetwork.invalid_number": "Invalid number: %s",
"message.eunetwork.network_id": "Network ID: %d",
"message.eunetwork.network_storage": "Storage: %s EU"
}
7 changes: 6 additions & 1 deletion src/generated/resources/assets/eunetwork/lang/zh_cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -247,5 +247,10 @@
"block.eunetwork.zpm_wireless_energy_output_hatch_4a": "4安§cZPM§r无线动力仓",
"block.eunetwork.zpm_wireless_energy_output_hatch_64a": "64安§cZPM§r无线动力仓",
"block.eunetwork.zpm_wireless_energy_output_hatch_65536a": "65536安§cZPM§r无线动力仓",
"item.eunetwork.eunetwork_terminal": "无线电网终端"
"item.eunetwork.eunetwork_terminal": "无线电网终端",
"message.eunetwork.add_successed": "网络 %d 能量添加成功,已添加:%s",
"message.eunetwork.invalid_network": "无效的网络:%d",
"message.eunetwork.invalid_number": "无效的数字:%s",
"message.eunetwork.network_id": "网络 ID:%d",
"message.eunetwork.network_storage": "已存储:%s EU"
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package com.epimorphismmc.eunetwork.common;

import com.epimorphismmc.eunetwork.EUNet;
import net.minecraftforge.event.TickEvent;
import com.epimorphismmc.eunetwork.common.data.EUNetCommands;
import net.minecraftforge.event.RegisterCommandsEvent;
import net.minecraftforge.event.server.ServerStoppedEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;

import javax.annotation.Nonnull;

@Mod.EventBusSubscriber(modid = EUNet.MODID, bus = Mod.EventBusSubscriber.Bus.FORGE)
public class ForgeCommonEventHandler {

Expand All @@ -17,6 +16,11 @@ public static void onServerStopped(ServerStoppedEvent event) {
EUNetworkData.release();
}

@SubscribeEvent
public static void onCommandRegister(RegisterCommandsEvent event) {
EUNetCommands.init(event.getDispatcher());
}

// @SubscribeEvent
// public static void onServerTick(@Nonnull TickEvent.ServerTickEvent event) {
// if (event.phase == TickEvent.Phase.END) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package com.epimorphismmc.eunetwork.common.data;

import com.epimorphismmc.eunetwork.EUNet;
import com.epimorphismmc.eunetwork.common.EUNetworkBase;
import com.epimorphismmc.eunetwork.common.EUNetworkData;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.IntegerArgumentType;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerPlayer;

import java.math.BigInteger;
import java.text.NumberFormat;

public class EUNetCommands {
private static final NumberFormat nf = NumberFormat.getInstance();

private static final RequiredArgumentBuilder<CommandSourceStack, Integer> NETWORK_ARGUMENT =
Commands.argument("id", IntegerArgumentType.integer())
.suggests((ctx, builder) -> {
EUNetworkData.getAllNetworks().forEach(n -> builder.suggest(n.getId()));
return builder.buildFuture();
});

private static final LiteralArgumentBuilder<CommandSourceStack> root = Commands.literal(EUNet.MODID)
.requires(src -> src.hasPermission(2))
.then(Commands.literal("get")
.executes(src -> {
ServerPlayer player = src.getSource().getPlayerOrException();
for (EUNetworkBase network : EUNetworkData.getAllNetworks()) {
if (network.canPlayerAccess(player)) {
src.getSource().sendSuccess(
() -> Component.translatable("message.eunetwork.network_id", network.getId()),
true
);
src.getSource().sendSuccess(
() -> Component.translatable("message.eunetwork.network_storage", nf.format(network.getStorage())),
true
);
}
}
return 1;
})
.then(NETWORK_ARGUMENT
.executes(src -> {
int id = IntegerArgumentType.getInteger(src, "id");
EUNetworkBase network = EUNetworkData.getNetwork(id);
if (network == null) {
src.getSource().sendFailure(Component.translatable("message.eunetwork.invalid_network", id));
} else {
src.getSource().sendSuccess(
() -> Component.translatable("message.eunetwork.network_id", network.getId()),
true
);
src.getSource().sendSuccess(
() -> Component.translatable("message.eunetwork.network_storage", nf.format(network.getStorage())),
true
);
}
return 1;
})))
.then(Commands.literal("add")
.then(NETWORK_ARGUMENT
.then(Commands.argument("value", StringArgumentType.string())
.executes(src -> {
int id = IntegerArgumentType.getInteger(src, "id");
String valueString = StringArgumentType.getString(src, "value");
BigInteger value;
try {
value = new BigInteger(valueString);
} catch (NumberFormatException e) {
src.getSource().sendFailure(Component.translatable("message.eunetwork.invalid_number", valueString));
return 0;
}
EUNetworkBase network = EUNetworkData.getNetwork(id);
if (network == null) {
src.getSource().sendFailure(Component.translatable("message.eunetwork.invalid_network", id));
} else {
BigInteger inserted = network.addEnergy(value);
src.getSource().sendSuccess(
() -> Component.translatable("message.eunetwork.add_successed", id, nf.format(inserted)),
true
);
}
return 1;
})))
);

public static void init(CommandDispatcher<CommandSourceStack> dispatcher) {
dispatcher.register(root);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
public class EUNetItems {

public final static ItemEntry<ComponentItem> EUNETWORK_TERMINAL = registrate().item("eunetwork_terminal", ComponentItem::create)
.tab(GTCreativeModeTabs.ITEM.getKey())
.onRegister(attach(new NetworkTerminalBehavior()))
.register();
.properties(p -> p.stacksTo(1))
.tab(GTCreativeModeTabs.ITEM.getKey())
.onRegister(attach(new NetworkTerminalBehavior()))
.register();

public static void init() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ public static void init(MOLangProvider provider) {
addWirelessEnergyHatchName(provider, 65536, false, MULTI_HATCH_TIERS);
addWirelessEnergyHatchName(provider, 262144, false, MULTI_HATCH_TIERS);
addWirelessEnergyHatchName(provider, 1048576, false, MULTI_HATCH_TIERS);

provider.add("message.eunetwork.network_id", "Network ID: %d", "网络 ID:%d");
provider.add("message.eunetwork.network_storage", "Storage: %s EU", "已存储:%s EU");
provider.add("message.eunetwork.invalid_number", "Invalid number: %s", "无效的数字:%s");
provider.add("message.eunetwork.invalid_network", "Invalid Network: %d", "无效的网络:%d");
provider.add("message.eunetwork.add_successed", "Network %d Energy added successfully, added: %s", "网络 %d 能量添加成功,已添加:%s");
}

private static void addWirelessEnergyHatchName(MOLangProvider provider, int amperage, boolean isInput, int... tiers) {
Expand Down

0 comments on commit 9d36bc7

Please sign in to comment.