aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/kubatech/commands
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/kubatech/commands')
-rw-r--r--src/main/java/kubatech/commands/CommandBees.java149
-rw-r--r--src/main/java/kubatech/commands/CommandConfig.java103
-rw-r--r--src/main/java/kubatech/commands/CommandHandler.java156
-rw-r--r--src/main/java/kubatech/commands/CommandHelp.java86
-rw-r--r--src/main/java/kubatech/commands/CommandTea.java142
5 files changed, 636 insertions, 0 deletions
diff --git a/src/main/java/kubatech/commands/CommandBees.java b/src/main/java/kubatech/commands/CommandBees.java
new file mode 100644
index 0000000000..2df0c294a6
--- /dev/null
+++ b/src/main/java/kubatech/commands/CommandBees.java
@@ -0,0 +1,149 @@
+/*
+ * spotless:off
+ * KubaTech - Gregtech Addon
+ * Copyright (C) 2022 - 2024 kuba6000
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library. If not, see <https://www.gnu.org/licenses/>.
+ * spotless:on
+ */
+
+package kubatech.commands;
+
+import static forestry.api.apiculture.BeeManager.beeRoot;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.util.List;
+
+import net.minecraft.command.CommandBase;
+import net.minecraft.command.ICommandSender;
+import net.minecraft.item.ItemStack;
+import net.minecraft.util.ChatComponentText;
+import net.minecraft.util.EnumChatFormatting;
+
+import com.google.common.io.Files;
+
+import forestry.api.apiculture.IAlleleBeeSpecies;
+import forestry.api.apiculture.IBee;
+import forestry.api.apiculture.IBeeGenome;
+import kubatech.api.utils.ModUtils;
+
+@CommandHandler.ChildCommand
+public class CommandBees extends CommandBase {
+
+ @Override
+ public String getCommandName() {
+ return "bees";
+ }
+
+ @Override
+ public String getCommandUsage(ICommandSender p_71518_1_) {
+ return "bees";
+ }
+
+ @Override
+ public int getRequiredPermissionLevel() {
+ return 4;
+ }
+
+ @SuppressWarnings("UnstableApiUsage")
+ @Override
+ public void processCommand(ICommandSender p_71515_1_, String[] p_71515_2_) {
+
+ if (!ModUtils.isClientSided) {
+ p_71515_1_
+ .addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "This command is single-player only!"));
+ return;
+ }
+
+ // https://docs.google.com/spreadsheets/d/1XaNGtJZ8WYv2nMnYcixTX4Jz3qUr71RadiKT5pToYFk/edit?usp=sharing
+ try {
+ File f = new File("bees.txt");
+ BufferedWriter writer = Files.newWriter(f, StandardCharsets.UTF_8);
+ String delimer = ",";
+
+ writer.write(
+ "Bee,CHANCE,OLD_0.6S_0UP,OLD_0.6S_8UP,OLD_1.7S_0UP,OLD_1.7S_8UP,NEW_0.6S_0UP_1T,NEW_0.6S_8UP_1T,NEW_1.7S_0UP_1T,NEW_1.7S_8UP_1T,NEW_1.7S_0UP_8T,NEW_1.7S_8UP_8T\n");
+
+ List<IBee> bees = beeRoot.getIndividualTemplates();
+ for (IBee bee : bees) {
+ // System.out.println("Bee: " + bee.getDisplayName());
+ StringBuilder b = new StringBuilder(bee.getDisplayName());
+ b.append(",-,-,-,-,-,-,-,-,-,-\n");
+ IBeeGenome genome = bee.getGenome();
+ IAlleleBeeSpecies primary = genome.getPrimary();
+ IAlleleBeeSpecies secondary = genome.getSecondary();
+ primary.getProductChances()
+ .forEach((k, v) -> printData("[PRIMARY]", k, v, delimer, b));
+ secondary.getProductChances()
+ .forEach((k, v) -> printData("[SECONDARY]", k, v / 2f, delimer, b));
+ primary.getSpecialtyChances()
+ .forEach((k, v) -> printData("[SPECIALITY]", k, v, delimer, b));
+ writer.write(b.toString());
+ }
+
+ writer.flush();
+ writer.close();
+ p_71515_1_.addChatMessage(new ChatComponentText(f.getAbsolutePath()));
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ private void printData(String nameOfData, ItemStack k, float v, String delimer, StringBuilder b) {
+ b.append(nameOfData);
+ b.append(k.getDisplayName());
+ b.append(delimer);
+ b.append(format(v));
+ b.append(delimer);
+ b.append(format(productChanceOld(0, 0.6d, v)));
+ b.append(delimer);
+ b.append(format(productChanceOld(8, 0.6d, v)));
+ b.append(delimer);
+ b.append(format(productChanceOld(0, 1.7d, v)));
+ b.append(delimer);
+ b.append(format(productChanceOld(8, 1.7d, v)));
+ b.append(delimer);
+ b.append(format(productChanceNew(0, 0.6d, v, 1)));
+ b.append(delimer);
+ b.append(format(productChanceNew(8, 0.6d, v, 1)));
+ b.append(delimer);
+ b.append(format(productChanceNew(0, 1.7d, v, 1)));
+ b.append(delimer);
+ b.append(format(productChanceNew(8, 1.7d, v, 1)));
+ b.append(delimer);
+ b.append(format(productChanceNew(0, 1.7d, v, 8)));
+ b.append(delimer);
+ b.append(format(productChanceNew(8, 1.7d, v, 8)));
+ b.append("\n");
+ }
+
+ private String format(double chance) {
+ return String.format("%.2f%%", chance * 100d);
+ }
+
+ private double productChanceNew(int upgradeCount, double beeSpeed, double chance, int t) {
+ chance *= 100f;
+ float productionModifier = (float) upgradeCount * 0.25f;
+ return (float) (((1f + t / 6f) * Math.sqrt(chance) * 2f * (1f + beeSpeed)
+ + Math.pow(productionModifier, Math.cbrt(chance))
+ - 3f) / 100f);
+ }
+
+ private double productChanceOld(int upgradeCount, double beeSpeed, double chance) {
+ return chance * beeSpeed * Math.pow(1.2d, upgradeCount);
+ }
+}
diff --git a/src/main/java/kubatech/commands/CommandConfig.java b/src/main/java/kubatech/commands/CommandConfig.java
new file mode 100644
index 0000000000..be759be2c9
--- /dev/null
+++ b/src/main/java/kubatech/commands/CommandConfig.java
@@ -0,0 +1,103 @@
+/*
+ * spotless:off
+ * KubaTech - Gregtech Addon
+ * Copyright (C) 2022 - 2024 kuba6000
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library. If not, see <https://www.gnu.org/licenses/>.
+ * spotless:on
+ */
+
+package kubatech.commands;
+
+import static kubatech.commands.CommandConfig.Translations.INVALID_OPTION;
+import static kubatech.commands.CommandConfig.Translations.SUCCESS;
+import static kubatech.commands.CommandConfig.Translations.USAGE;
+
+import net.minecraft.command.CommandBase;
+import net.minecraft.command.ICommandSender;
+import net.minecraft.entity.player.EntityPlayerMP;
+import net.minecraft.server.MinecraftServer;
+import net.minecraft.util.ChatComponentText;
+import net.minecraft.util.StatCollector;
+
+import kubatech.config.Config;
+import kubatech.kubatech;
+import kubatech.network.LoadConfigPacket;
+
+@CommandHandler.ChildCommand
+public class CommandConfig extends CommandBase {
+
+ enum Translations {
+
+ INVALID_OPTION,
+ SUCCESS,
+ USAGE,;
+
+ final String key;
+
+ Translations() {
+ key = "kubatech.command.config." + this.name()
+ .toLowerCase();
+ }
+
+ public String get() {
+ return StatCollector.translateToLocal(key);
+ }
+
+ public String get(Object... args) {
+ return StatCollector.translateToLocalFormatted(key, args);
+ }
+
+ public String getKey() {
+ return key;
+ }
+
+ @Override
+ public String toString() {
+ return get();
+ }
+ }
+
+ @Override
+ public String getCommandName() {
+ return "config";
+ }
+
+ @Override
+ public String getCommandUsage(ICommandSender p_71518_1_) {
+ return "config " + USAGE.get();
+ }
+
+ @Override
+ public int getRequiredPermissionLevel() {
+ return 4;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public void processCommand(ICommandSender p_71515_1_, String[] p_71515_2_) {
+ if (p_71515_2_.length == 0 || !p_71515_2_[0].equals("reload")) {
+ p_71515_1_.addChatMessage(new ChatComponentText(INVALID_OPTION.get()));
+ return;
+ }
+ Config.synchronizeConfiguration();
+ MinecraftServer.getServer()
+ .getConfigurationManager().playerEntityList.forEach(p -> {
+ if (!(p instanceof EntityPlayerMP)) return;
+ kubatech.info("Sending config to " + ((EntityPlayerMP) p).getDisplayName());
+ kubatech.NETWORK.sendTo(LoadConfigPacket.instance, (EntityPlayerMP) p);
+ });
+ p_71515_1_.addChatMessage(new ChatComponentText(SUCCESS.get()));
+ }
+}
diff --git a/src/main/java/kubatech/commands/CommandHandler.java b/src/main/java/kubatech/commands/CommandHandler.java
new file mode 100644
index 0000000000..b0957c9572
--- /dev/null
+++ b/src/main/java/kubatech/commands/CommandHandler.java
@@ -0,0 +1,156 @@
+/*
+ * spotless:off
+ * KubaTech - Gregtech Addon
+ * Copyright (C) 2022 - 2024 kuba6000
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library. If not, see <https://www.gnu.org/licenses/>.
+ * spotless:on
+ */
+
+package kubatech.commands;
+
+import static kubatech.commands.CommandHandler.Translations.CANT_FIND;
+import static kubatech.commands.CommandHandler.Translations.GENERIC_HELP;
+import static kubatech.commands.CommandHandler.Translations.INVALID;
+import static kubatech.commands.CommandHandler.Translations.USAGE;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+
+import net.minecraft.command.CommandBase;
+import net.minecraft.command.ICommand;
+import net.minecraft.command.ICommandSender;
+import net.minecraft.util.ChatComponentText;
+import net.minecraft.util.ChatComponentTranslation;
+import net.minecraft.util.EnumChatFormatting;
+import net.minecraft.util.StatCollector;
+
+import kubatech.kubatech;
+
+public class CommandHandler extends CommandBase {
+
+ enum Translations {
+
+ INVALID,
+ CANT_FIND,
+ GENERIC_HELP,
+ USAGE,;
+
+ final String key;
+
+ Translations() {
+ key = "kubatech.commandhandler." + this.name()
+ .toLowerCase();
+ }
+
+ public String get() {
+ return StatCollector.translateToLocal(key);
+ }
+
+ public String get(Object... args) {
+ return StatCollector.translateToLocalFormatted(key, args);
+ }
+
+ public String getKey() {
+ return key;
+ }
+
+ @Override
+ public String toString() {
+ return get();
+ }
+ }
+
+ private static final List<String> aliases = Collections.singletonList("kt");
+ public static final HashMap<String, ICommand> commands = new HashMap<>();
+
+ @Override
+ public String getCommandName() {
+ return "kubatech";
+ }
+
+ @Override
+ public String getCommandUsage(ICommandSender p_71518_1_) {
+ return "kubatech " + USAGE.get();
+ }
+
+ @SuppressWarnings("rawtypes")
+ @Override
+ public List getCommandAliases() {
+ return aliases;
+ }
+
+ @Override
+ public void processCommand(ICommandSender p_71515_1_, String[] p_71515_2_) {
+ if (p_71515_1_.getEntityWorld().isRemote) return;
+ if (p_71515_2_.length == 0) {
+ p_71515_1_.addChatMessage(new ChatComponentText(INVALID.get(getCommandUsage(p_71515_1_))));
+ p_71515_1_.addChatMessage(new ChatComponentText(GENERIC_HELP.get()));
+ return;
+ }
+ if (!commands.containsKey(p_71515_2_[0])) {
+ p_71515_1_.addChatMessage(new ChatComponentText(CANT_FIND.get(p_71515_2_[0])));
+ p_71515_1_.addChatMessage(new ChatComponentText(GENERIC_HELP.get()));
+ return;
+ }
+ ICommand cmd = commands.get(p_71515_2_[0]);
+ if (!cmd.canCommandSenderUseCommand(p_71515_1_)) {
+ ChatComponentTranslation chatcomponenttranslation2 = new ChatComponentTranslation(
+ "commands.generic.permission");
+ chatcomponenttranslation2.getChatStyle()
+ .setColor(EnumChatFormatting.RED);
+ p_71515_1_.addChatMessage(chatcomponenttranslation2);
+ } else cmd.processCommand(
+ p_71515_1_,
+ p_71515_2_.length > 1 ? Arrays.copyOfRange(p_71515_2_, 1, p_71515_2_.length) : new String[0]);
+ }
+
+ @Override
+ public boolean canCommandSenderUseCommand(ICommandSender p_71519_1_) {
+ return true;
+ }
+
+ public static void addCommand(ICommand command) {
+ commands.put(command.getCommandName(), command);
+ }
+
+ static {
+ String ChildCommandDesc = "L" + ChildCommand.class.getName()
+ .replace(".", "/") + ";";
+ kubatech.myClasses.stream()
+ .filter(
+ clazz -> clazz.invisibleAnnotations != null && clazz.invisibleAnnotations.stream()
+ .anyMatch(ann -> ann.desc.equals(ChildCommandDesc)))
+ .forEach(clazz -> {
+ try {
+ addCommand(
+ (ICommand) Class.forName(clazz.name.replace("/", "."))
+ .getConstructor()
+ .newInstance());
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ });
+ }
+
+ @Target(ElementType.TYPE)
+ @Retention(RetentionPolicy.CLASS)
+ public @interface ChildCommand {}
+}
diff --git a/src/main/java/kubatech/commands/CommandHelp.java b/src/main/java/kubatech/commands/CommandHelp.java
new file mode 100644
index 0000000000..610f330ede
--- /dev/null
+++ b/src/main/java/kubatech/commands/CommandHelp.java
@@ -0,0 +1,86 @@
+/*
+ * spotless:off
+ * KubaTech - Gregtech Addon
+ * Copyright (C) 2022 - 2024 kuba6000
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library. If not, see <https://www.gnu.org/licenses/>.
+ * spotless:on
+ */
+
+package kubatech.commands;
+
+import static kubatech.commands.CommandHelp.Translations.POSSIBLE_COMMANDS;
+import static kubatech.commands.CommandHelp.Translations.USAGE;
+
+import net.minecraft.command.CommandBase;
+import net.minecraft.command.ICommandSender;
+import net.minecraft.util.ChatComponentText;
+import net.minecraft.util.StatCollector;
+
+@CommandHandler.ChildCommand
+public class CommandHelp extends CommandBase {
+
+ enum Translations {
+
+ POSSIBLE_COMMANDS,
+ USAGE,;
+
+ final String key;
+
+ Translations() {
+ key = "kubatech.command.help." + this.name()
+ .toLowerCase();
+ }
+
+ public String get() {
+ return StatCollector.translateToLocal(key);
+ }
+
+ public String get(Object... args) {
+ return StatCollector.translateToLocalFormatted(key, args);
+ }
+
+ public String getKey() {
+ return key;
+ }
+
+ @Override
+ public String toString() {
+ return get();
+ }
+ }
+
+ @Override
+ public String getCommandName() {
+ return "help";
+ }
+
+ @Override
+ public String getCommandUsage(ICommandSender p_71518_1_) {
+ return "help " + USAGE.get();
+ }
+
+ @Override
+ public boolean canCommandSenderUseCommand(ICommandSender p_71519_1_) {
+ return true;
+ }
+
+ @Override
+ public void processCommand(ICommandSender p_71515_1_, String[] p_71515_2_) {
+ p_71515_1_.addChatMessage(new ChatComponentText(POSSIBLE_COMMANDS.get()));
+ CommandHandler.commands.values()
+ .forEach(
+ c -> p_71515_1_.addChatMessage(new ChatComponentText("/kubatech " + c.getCommandUsage(p_71515_1_))));
+ }
+}
diff --git a/src/main/java/kubatech/commands/CommandTea.java b/src/main/java/kubatech/commands/CommandTea.java
new file mode 100644
index 0000000000..057d2bca69
--- /dev/null
+++ b/src/main/java/kubatech/commands/CommandTea.java
@@ -0,0 +1,142 @@
+/*
+ * spotless:off
+ * KubaTech - Gregtech Addon
+ * Copyright (C) 2022 - 2024 kuba6000
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library. If not, see <https://www.gnu.org/licenses/>.
+ * spotless:on
+ */
+
+package kubatech.commands;
+
+import static kubatech.commands.CommandTea.Translations.INVALID_OPTION;
+import static kubatech.commands.CommandTea.Translations.PLAYER_NOT_FOUND;
+import static kubatech.commands.CommandTea.Translations.SUCCESS_ADD;
+import static kubatech.commands.CommandTea.Translations.SUCCESS_GET;
+import static kubatech.commands.CommandTea.Translations.SUCCESS_SET;
+import static kubatech.commands.CommandTea.Translations.USAGE;
+
+import java.math.BigInteger;
+import java.util.UUID;
+
+import net.minecraft.command.CommandBase;
+import net.minecraft.command.ICommandSender;
+import net.minecraft.util.ChatComponentText;
+import net.minecraft.util.StatCollector;
+
+import kubatech.api.helpers.UUIDFinder;
+import kubatech.api.tea.TeaNetwork;
+
+@CommandHandler.ChildCommand
+public class CommandTea extends CommandBase {
+
+ enum Translations {
+
+ INVALID_OPTION,
+ PLAYER_NOT_FOUND,
+ SUCCESS_GET,
+ SUCCESS_SET,
+ SUCCESS_ADD,
+ USAGE,;
+
+ final String key;
+
+ Translations() {
+ key = "kubatech.command.tea." + this.name()
+ .toLowerCase();
+ }
+
+ public String get() {
+ return StatCollector.translateToLocal(key);
+ }
+
+ public String get(Object... args) {
+ return StatCollector.translateToLocalFormatted(key, args);
+ }
+
+ public String getKey() {
+ return key;
+ }
+
+ @Override
+ public String toString() {
+ return get();
+ }
+ }
+
+ @Override
+ public String getCommandName() {
+ return "tea";
+ }
+
+ @Override
+ public String getCommandUsage(ICommandSender p_71518_1_) {
+ return "tea " + USAGE.get();
+ }
+
+ @Override
+ public int getRequiredPermissionLevel() {
+ return 4;
+ }
+
+ @Override
+ public void processCommand(ICommandSender p_71515_1_, String[] p_71515_2_) {
+ if (p_71515_2_.length < 2) {
+ p_71515_1_.addChatMessage(new ChatComponentText(INVALID_OPTION.get()));
+ return;
+ }
+ UUID player = UUIDFinder.getUUID(p_71515_2_[0]);
+ if (player == null) {
+ p_71515_1_.addChatMessage(new ChatComponentText(PLAYER_NOT_FOUND.get()));
+ return;
+ }
+ TeaNetwork teaNetwork = TeaNetwork.getNetwork(player);
+ if (!p_71515_2_[1].equalsIgnoreCase("get") && p_71515_2_.length < 3) {
+ p_71515_1_.addChatMessage(new ChatComponentText(INVALID_OPTION.get()));
+ return;
+ }
+ switch (p_71515_2_[1].toLowerCase()) {
+ case "get":
+ p_71515_1_.addChatMessage(new ChatComponentText(SUCCESS_GET.get(p_71515_2_[0], teaNetwork.teaAmount)));
+ break;
+ case "set": {
+ BigInteger tea;
+ try {
+ tea = new BigInteger(p_71515_2_[2]);
+ } catch (NumberFormatException ex) {
+ p_71515_1_.addChatMessage(new ChatComponentText(INVALID_OPTION.get()));
+ return;
+ }
+ teaNetwork.teaAmount = tea;
+ teaNetwork.markDirty();
+ p_71515_1_.addChatMessage(new ChatComponentText(SUCCESS_SET.get(p_71515_2_[0], teaNetwork.teaAmount)));
+ break;
+ }
+ case "add": {
+ BigInteger tea;
+ try {
+ tea = new BigInteger(p_71515_2_[2]);
+ } catch (NumberFormatException ex) {
+ p_71515_1_.addChatMessage(new ChatComponentText(INVALID_OPTION.get()));
+ return;
+ }
+ teaNetwork.addTea(tea);
+ p_71515_1_.addChatMessage(new ChatComponentText(SUCCESS_ADD.get(p_71515_2_[0], teaNetwork.teaAmount)));
+ break;
+ }
+ default:
+ break;
+ }
+ }
+}