chatmacro, quicksla, minor changes

This commit is contained in:
Stachelbeere1248 2023-11-09 04:14:02 +01:00
parent c4109607c3
commit 9026529071
13 changed files with 202 additions and 64 deletions

View file

@ -3,4 +3,4 @@ org.gradle.jvmargs=-Xmx2g
baseGroup = com.github.stachelbeere1248.zombiesutils baseGroup = com.github.stachelbeere1248.zombiesutils
mcVersion = 1.8.9 mcVersion = 1.8.9
modid = zombiesutils modid = zombiesutils
version = 1.0.3 version = 1.1.1

View file

@ -2,7 +2,8 @@ package com.github.stachelbeere1248.zombiesutils;
import com.github.stachelbeere1248.zombiesutils.commands.CategoryCommand; import com.github.stachelbeere1248.zombiesutils.commands.CategoryCommand;
import com.github.stachelbeere1248.zombiesutils.commands.SlaCommand; import com.github.stachelbeere1248.zombiesutils.commands.SlaCommand;
import com.github.stachelbeere1248.zombiesutils.config.Config; import com.github.stachelbeere1248.zombiesutils.config.ZombiesUtilsConfig;
import com.github.stachelbeere1248.zombiesutils.config.Hotkeys;
import com.github.stachelbeere1248.zombiesutils.handlers.ChatHandler; import com.github.stachelbeere1248.zombiesutils.handlers.ChatHandler;
import com.github.stachelbeere1248.zombiesutils.handlers.TickHandler; import com.github.stachelbeere1248.zombiesutils.handlers.TickHandler;
import com.github.stachelbeere1248.zombiesutils.render.RenderGameOverlayHandler; import com.github.stachelbeere1248.zombiesutils.render.RenderGameOverlayHandler;
@ -18,8 +19,10 @@ import org.jetbrains.annotations.NotNull;
@Mod(modid = "zombiesutils", useMetadata = true, clientSideOnly = true, guiFactory = "com.github.stachelbeere1248.zombiesutils.config.GuiFactory") @Mod(modid = "zombiesutils", useMetadata = true, clientSideOnly = true, guiFactory = "com.github.stachelbeere1248.zombiesutils.config.GuiFactory")
public class ZombiesUtils { public class ZombiesUtils {
private static ZombiesUtils instance; private static ZombiesUtils instance;
private final Hotkeys hotkeys;
private Logger logger; private Logger logger;
public ZombiesUtils() { public ZombiesUtils() {
hotkeys = new Hotkeys();
instance = this; instance = this;
} }
public static ZombiesUtils getInstance() { public static ZombiesUtils getInstance() {
@ -29,19 +32,30 @@ public class ZombiesUtils {
@Mod.EventHandler @Mod.EventHandler
public void preInit(@NotNull FMLPreInitializationEvent event) { public void preInit(@NotNull FMLPreInitializationEvent event) {
logger = event.getModLog(); logger = event.getModLog();
Config.config = new Configuration(event.getSuggestedConfigurationFile()); ZombiesUtilsConfig.config = new Configuration(
Config.load(); event.getSuggestedConfigurationFile(),
"1.1.1"
);
ZombiesUtilsConfig.load();
} }
@Mod.EventHandler @Mod.EventHandler
public void init(FMLInitializationEvent event) { public void init(FMLInitializationEvent event) {
MinecraftForge.EVENT_BUS.register(new ZombiesUtilsConfig());
MinecraftForge.EVENT_BUS.register(new RenderGameOverlayHandler()); MinecraftForge.EVENT_BUS.register(new RenderGameOverlayHandler());
MinecraftForge.EVENT_BUS.register(new TickHandler()); MinecraftForge.EVENT_BUS.register(new TickHandler());
MinecraftForge.EVENT_BUS.register(new ChatHandler()); MinecraftForge.EVENT_BUS.register(new ChatHandler());
MinecraftForge.EVENT_BUS.register(new Config()); MinecraftForge.EVENT_BUS.register(hotkeys);
ClientCommandHandler.instance.registerCommand(new CategoryCommand()); ClientCommandHandler.instance.registerCommand(new CategoryCommand());
ClientCommandHandler.instance.registerCommand(new SlaCommand()); ClientCommandHandler.instance.registerCommand(new SlaCommand());
hotkeys.registerAll();
} }
public Logger getLogger() { public Logger getLogger() {
return logger; return logger;
} }
public Hotkeys getHotkeys() {
return hotkeys;
}
} }

View file

@ -1,8 +1,8 @@
package com.github.stachelbeere1248.zombiesutils.commands; package com.github.stachelbeere1248.zombiesutils.commands;
import com.github.stachelbeere1248.zombiesutils.game.Map; import com.github.stachelbeere1248.zombiesutils.game.Map;
import com.github.stachelbeere1248.zombiesutils.game.windows.Sla; import com.github.stachelbeere1248.zombiesutils.game.sla.QuickSLA;
import net.minecraft.client.Minecraft; import com.github.stachelbeere1248.zombiesutils.game.sla.SLA;
import net.minecraft.command.*; import net.minecraft.command.*;
import net.minecraft.util.BlockPos; import net.minecraft.util.BlockPos;
import net.minecraft.util.ChatComponentText; import net.minecraft.util.ChatComponentText;
@ -26,74 +26,118 @@ public class SlaCommand extends CommandBase {
@Override @Override
public void processCommand(ICommandSender sender, String @NotNull [] args) throws CommandException { public void processCommand(ICommandSender sender, String @NotNull [] args) throws CommandException {
if (args.length == 0) sender.addChatMessage(new ChatComponentText(getCommandUsage(sender))); if (args.length == 0) throw new WrongUsageException(
"[Missing option] options: off, offset, rotate, mirror, map");
else { else {
switch (args[0]) { switch (args[0]) {
case "off": case "off":
Sla.drop(); SLA.drop();
sender.addChatMessage(new ChatComponentText("SLA data deleted")); sender.addChatMessage(new ChatComponentText("SLA data deleted"));
break; break;
case "offset": case "offset":
if (args.length == 1) Sla.getInstance().ifPresent(Sla::resetOffset); if (args.length == 1) SLA.getInstance().ifPresent(SLA::resetOffset);
else if (args.length != 4) throw new WrongUsageException("An offset should have three coordinates!"); else if (args.length != 4) throw new WrongUsageException(
"An offset should have three coordinates!");
else { else {
try { try {
double x = Double.parseDouble(args[1]); int x = Integer.parseInt(args[1]);
double y = Double.parseDouble(args[2]); int y = Integer.parseInt(args[2]);
double z = Double.parseDouble(args[3]); int z = Integer.parseInt(args[3]);
Sla.getInstance().ifPresent(sla -> sla.setOffset(new double[]{x, y, z})); SLA.getInstance().ifPresent(sla -> sla.setOffset(new int[]{x, y, z}));
sender.addChatMessage(new ChatComponentText(String.format("Offset set to %s %s %s", x, y, z)));
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
throw new NumberInvalidException(); throw new NumberInvalidException("Invalid Integer:", args[1]);
} }
} }
break; break;
case "rotate": case "rotate":
sender.addChatMessage(new ChatComponentText("Rotating map...")); if (args.length == 1) SLA.getInstance().ifPresent(sla -> sla.rotate(1));
Sla.getInstance().ifPresent(Sla::rotate); else {
int rotations;
try {
rotations = Integer.parseInt(args[1]);
} catch (NumberFormatException ignored) {
throw new NumberInvalidException("Invalid Integer:", args[1]);
}
SLA.getInstance().ifPresent(sla -> sla.rotate(rotations));
}
break; break;
case "mirror": case "mirror":
switch (args[1]) { switch (args[1]) {
case "x": case "x":
Sla.getInstance().ifPresent(Sla::mirrorX); SLA.getInstance().ifPresent(SLA::mirrorX);
break; break;
case "z": case "z":
Sla.getInstance().ifPresent(Sla::mirrorZ); SLA.getInstance().ifPresent(SLA::mirrorZ);
break; break;
default: throw new WrongUsageException("Invalid option: available: x, z"); default:
throw new WrongUsageException("Invalid option: available: x, z");
} }
break; break;
case "map": case "map":
switch (args[1]) { switch (args[1]) {
case "de": case "de":
Sla.instance = new Sla(Map.DEAD_END); SLA.instance = new SLA(Map.DEAD_END);
Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("SLA forced to map DE"));
break; break;
case "bb": case "bb":
Sla.instance = new Sla(Map.BAD_BLOOD); SLA.instance = new SLA(Map.BAD_BLOOD);
Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("SLA forced to map BB"));
break; break;
case "aa": case "aa":
Sla.instance = new Sla(Map.ALIEN_ARCADIUM); SLA.instance = new SLA(Map.ALIEN_ARCADIUM);
Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("SLA forced to map AA"));
break; break;
default: throw new WrongUsageException("Invalid option: available: de, bb, aa"); default:
throw new WrongUsageException(
"[Invalid option] options: de, bb, aa", args[1]);
} }
break; break;
default: throw new WrongUsageException("Invalid option: available: off, offset, rotate, mirror, map"); case "quick":
switch (args[1]) {
//noinspection SpellCheckingInspection
case "mogi_a":
QuickSLA.mogi_a();
break;
//noinspection SpellCheckingInspection
case "ghxula":
QuickSLA.ghxula();
break;
//noinspection SpellCheckingInspection
case "ghxula-garden":
QuickSLA.ghxulaGarden();
break;
default:
//noinspection SpellCheckingInspection
throw new WrongUsageException(
"[Invalid option] options: mogi_a, ghxula, ghxula-garden", args[1]); }
break;
default:
throw new WrongUsageException(
"[Invalid option] options: off, offset, rotate, mirror, map", args[0]);
} }
} }
} }
@Override @Override
public List<String> addTabCompletionOptions(ICommandSender sender, String @NotNull [] args, BlockPos blockPos) { public List<String> addTabCompletionOptions(ICommandSender sender, String @NotNull [] args, BlockPos blockPos) {
List<String> options = new ArrayList<>(); List<String> options = new ArrayList<>();
if (args.length == 1) options.addAll(Arrays.asList("off","offset","rotate","mirror","map")); if (args.length == 1) options.addAll(Arrays.asList("off", "offset", "rotate", "mirror", "map"));
else if ("offset".equals(args[0]) && (args.length == 2 || args.length == 3 || args.length == 4)) else {
options.add("0"); if (args.length > 1) switch (args[0]) {
else if ("map".equals(args[0])) options.addAll(Arrays.asList("de", "bb", "aa")); case "offset":
else if ("mirror".equals(args[0])) { if (args.length<5) options.add("0");
options.addAll(Arrays.asList("x","z")); break;
case "map":
options.addAll(Arrays.asList("de", "bb", "aa"));
break;
case "mirror":
options.addAll(Arrays.asList("x", "z"));
break;
case "rotate":
options.add("1");
break;
case "quick":
//noinspection SpellCheckingInspection
options.addAll(Arrays.asList("mogi_a", "ghxula", "ghxula-garden"));
default:
}
} }
return options; return options;
} }

View file

@ -8,7 +8,7 @@ public class GuiConfig extends net.minecraftforge.fml.client.config.GuiConfig {
public GuiConfig(GuiScreen parentScreen) { public GuiConfig(GuiScreen parentScreen) {
super( super(
parentScreen, parentScreen,
new ConfigElement(Config.config.getCategory(Configuration.CATEGORY_GENERAL)).getChildElements(), new ConfigElement(ZombiesUtilsConfig.config.getCategory(Configuration.CATEGORY_GENERAL)).getChildElements(),
"zombiesutils", "zombiesutils",
false, false,
false, false,

View file

@ -8,13 +8,8 @@ import java.util.Set;
public class GuiFactory implements IModGuiFactory { public class GuiFactory implements IModGuiFactory {
public boolean hasConfigGui() {
return true;
}
@Override @Override
public void initialize(Minecraft minecraft) { public void initialize(Minecraft minecraft) {
} }
@Override @Override

View file

@ -0,0 +1,29 @@
package com.github.stachelbeere1248.zombiesutils.config;
import net.minecraft.client.Minecraft;
import net.minecraft.client.settings.KeyBinding;
import net.minecraftforge.fml.client.registry.ClientRegistry;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.InputEvent;
import org.lwjgl.input.Keyboard;
public class Hotkeys {
private final KeyBinding chatMacro;
public Hotkeys() {
chatMacro = new KeyBinding(
"Chat Macro",
Keyboard.KEY_Q,
"Zombies Utils"
);
}
public void registerAll() {
ClientRegistry.registerKeyBinding(this.chatMacro);
}
@SubscribeEvent
public void onKeyInput(InputEvent.KeyInputEvent event) {
if (Keyboard.getEventKey() == chatMacro.getKeyCode() && Keyboard.getEventKeyState() && Minecraft.getMinecraft().currentScreen == null) {
Minecraft.getMinecraft().thePlayer.sendChatMessage(ZombiesUtilsConfig.getChatMacro());
}
}
}

View file

@ -6,10 +6,10 @@ import net.minecraftforge.fml.client.event.ConfigChangedEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
public class Config { public class ZombiesUtilsConfig {
public static Configuration config; public static Configuration config;
private static boolean slaToggle; private static boolean slaToggle;
private static String chatMacro;
public static void load() { public static void load() {
ZombiesUtils.getInstance().getLogger().debug("Loading config..."); ZombiesUtils.getInstance().getLogger().debug("Loading config...");
config.load(); config.load();
@ -21,6 +21,12 @@ public class Config {
slaToggle, slaToggle,
"Should SLA be started when a game starts?" "Should SLA be started when a game starts?"
); );
chatMacro = config.getString(
"Chat Macro",
Configuration.CATEGORY_GENERAL,
"T",
"The Text to be sent when pressing the chat-macro hotkey"
);
ZombiesUtils.getInstance().getLogger().debug("Saving Config..."); ZombiesUtils.getInstance().getLogger().debug("Saving Config...");
config.save(); config.save();
@ -30,10 +36,13 @@ public class Config {
public void onConfigChange(ConfigChangedEvent.@NotNull OnConfigChangedEvent event) { public void onConfigChange(ConfigChangedEvent.@NotNull OnConfigChangedEvent event) {
if (event.modID.equals("zombiesutils") && event.configID == null) { if (event.modID.equals("zombiesutils") && event.configID == null) {
config.save(); config.save();
Config.load(); ZombiesUtilsConfig.load();
} }
} }
public static boolean isSlaToggled() { public static boolean isSlaToggled() {
return slaToggle; return slaToggle;
} }
public static String getChatMacro() {
return chatMacro;
}
} }

View file

@ -0,0 +1,20 @@
package com.github.stachelbeere1248.zombiesutils.game.sla;
import com.github.stachelbeere1248.zombiesutils.game.Map;
@SuppressWarnings("SpellCheckingInspection")
public class QuickSLA {
public static void mogi_a() {
SLA.instance = new SLA(Map.BAD_BLOOD);
SLA.instance.rotate(3);
SLA.instance.setOffset(new int[]{-3,35,-9});
}
public static void ghxula() {
SLA.instance = new SLA(Map.DEAD_END);
//TODO
}
public static void ghxulaGarden() {
SLA.instance = new SLA(Map.DEAD_END);
//TODO
}
}

View file

@ -1,7 +1,9 @@
package com.github.stachelbeere1248.zombiesutils.game.windows; package com.github.stachelbeere1248.zombiesutils.game.sla;
import com.github.stachelbeere1248.zombiesutils.ZombiesUtils; import com.github.stachelbeere1248.zombiesutils.ZombiesUtils;
import com.github.stachelbeere1248.zombiesutils.game.Map; import com.github.stachelbeere1248.zombiesutils.game.Map;
import com.github.stachelbeere1248.zombiesutils.game.windows.Room;
import com.github.stachelbeere1248.zombiesutils.game.windows.Window;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.client.entity.EntityPlayerSP;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -9,13 +11,13 @@ import org.jetbrains.annotations.NotNull;
import java.util.Arrays; import java.util.Arrays;
import java.util.Optional; import java.util.Optional;
public class Sla { public class SLA {
public static Sla instance = null; public static SLA instance = null;
private final double[] offset = new double[3]; private final int[] offset = new int[3];
private final Room[] rooms; private final Room[] rooms;
public Sla(@NotNull Map map) { public SLA(@NotNull Map map) {
switch (map) { switch (map) {
case DEAD_END: this.rooms = Room.getDE(); break; case DEAD_END: this.rooms = Room.getDE(); break;
case BAD_BLOOD: this.rooms = Room.getBB(); break; case BAD_BLOOD: this.rooms = Room.getBB(); break;
@ -24,10 +26,10 @@ public class Sla {
} }
} }
public void rotate() { public void rotate(int rotations) {
for (Room room : rooms) { for (Room room : rooms) {
for (Window window: room.getWindows()) { for (Window window: room.getWindows()) {
window.rotate(); window.rotate(rotations);
} }
} }
System.out.println("Co3 now at " + Arrays.toString(rooms[0].getWindows()[0].getXYZ())); System.out.println("Co3 now at " + Arrays.toString(rooms[0].getWindows()[0].getXYZ()));
@ -66,7 +68,7 @@ public class Sla {
distanceDoubledThenSquared += ((playerCoords[i]*2 - window.getXYZ()[i]) * (playerCoords[i]*2 - window.getXYZ()[i])); distanceDoubledThenSquared += ((playerCoords[i]*2 - window.getXYZ()[i]) * (playerCoords[i]*2 - window.getXYZ()[i]));
} }
// (2x)² + (2y)² + (2z)² = 4 (x²+y²+z²) // (2x)²+(2y)²+(2z)² = 4(x²+y²+z²) = 4d²
if (distanceDoubledThenSquared < 10000) { if (distanceDoubledThenSquared < 10000) {
window.setActive(true); window.setActive(true);
room.increaseActiveWindowCount(); room.increaseActiveWindowCount();
@ -76,7 +78,7 @@ public class Sla {
} }
public static Optional<Sla> getInstance() { public static Optional<SLA> getInstance() {
return Optional.ofNullable(instance); return Optional.ofNullable(instance);
} }
public static void drop() { public static void drop() {
@ -88,7 +90,7 @@ public class Sla {
public void resetOffset() { public void resetOffset() {
Arrays.fill(this.offset, 0); Arrays.fill(this.offset, 0);
} }
public void setOffset(double[] offset) { public void setOffset(int[] offset) {
System.arraycopy(offset, 0, this.offset, 0, 3); System.arraycopy(offset, 0, this.offset, 0, 3);
} }
} }

View file

@ -1,5 +1,6 @@
package com.github.stachelbeere1248.zombiesutils.game; package com.github.stachelbeere1248.zombiesutils.game.waves;
import com.github.stachelbeere1248.zombiesutils.game.Map;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@SuppressWarnings("DuplicatedCode") @SuppressWarnings("DuplicatedCode")

View file

@ -23,11 +23,35 @@ public class Window {
public boolean isActive() { public boolean isActive() {
return isActive; return isActive;
} }
public void rotate() { private void rotateCounterClockwise() {
final short x = xyz[0], z = xyz[2]; final short x = xyz[0], z = xyz[2];
xyz[0] = (short) -z; xyz[0] = (short) -z;
xyz[2] = x; xyz[2] = x;
} }
private void mirrorBoth() {
xyz[0] = (short) -xyz[0];
xyz[2] = (short) -xyz[2];
}
private void rotateClockwise() {
final short x = xyz[0], z = xyz[2];
xyz[0] = z;
xyz[2] = (short) -x;
}
public void rotate(int rotations) {
rotations %= 4;
switch (rotations) {
case -3: case 1:
rotateCounterClockwise();
break;
case -2: case 2:
mirrorBoth();
break;
case -1: case 3:
rotateClockwise();
break;
case 0: break;
}
}
public void mirrorX() { public void mirrorX() {
xyz[0] = (short) -xyz[0]; xyz[0] = (short) -xyz[0];
} }

View file

@ -1,7 +1,7 @@
package com.github.stachelbeere1248.zombiesutils.render; package com.github.stachelbeere1248.zombiesutils.render;
import com.github.stachelbeere1248.zombiesutils.game.sla.SLA;
import com.github.stachelbeere1248.zombiesutils.game.windows.Room; import com.github.stachelbeere1248.zombiesutils.game.windows.Room;
import com.github.stachelbeere1248.zombiesutils.game.windows.Sla;
import com.github.stachelbeere1248.zombiesutils.timer.Timer; import com.github.stachelbeere1248.zombiesutils.timer.Timer;
import com.github.stachelbeere1248.zombiesutils.utils.Scoreboard; import com.github.stachelbeere1248.zombiesutils.utils.Scoreboard;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
@ -24,7 +24,7 @@ public class RenderGameOverlayHandler {
public void onRenderGameOverlay(RenderGameOverlayEvent.@NotNull Post event) { public void onRenderGameOverlay(RenderGameOverlayEvent.@NotNull Post event) {
if (event.type != RenderGameOverlayEvent.ElementType.TEXT) return; if (event.type != RenderGameOverlayEvent.ElementType.TEXT) return;
Timer.getInstance().ifPresent(timer -> renderTime(timer.roundTime())); Timer.getInstance().ifPresent(timer -> renderTime(timer.roundTime()));
Sla.getInstance().ifPresent(sla -> { SLA.getInstance().ifPresent(sla -> {
sla.refreshActives(); sla.refreshActives();
renderSla(sla.getRooms()); renderSla(sla.getRooms());
}); });

View file

@ -1,10 +1,10 @@
package com.github.stachelbeere1248.zombiesutils.timer; package com.github.stachelbeere1248.zombiesutils.timer;
import com.github.stachelbeere1248.zombiesutils.ZombiesUtils; import com.github.stachelbeere1248.zombiesutils.ZombiesUtils;
import com.github.stachelbeere1248.zombiesutils.config.Config; import com.github.stachelbeere1248.zombiesutils.config.ZombiesUtilsConfig;
import com.github.stachelbeere1248.zombiesutils.game.GameMode; import com.github.stachelbeere1248.zombiesutils.game.GameMode;
import com.github.stachelbeere1248.zombiesutils.game.Map; import com.github.stachelbeere1248.zombiesutils.game.Map;
import com.github.stachelbeere1248.zombiesutils.game.windows.Sla; import com.github.stachelbeere1248.zombiesutils.game.sla.SLA;
import com.github.stachelbeere1248.zombiesutils.timer.recorder.Category; import com.github.stachelbeere1248.zombiesutils.timer.recorder.Category;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -35,7 +35,7 @@ public class Timer {
this.category = new Category(); this.category = new Category();
GameMode.create(map); GameMode.create(map);
if (Config.isSlaToggled()) Sla.instance = new Sla(map); if (ZombiesUtilsConfig.isSlaToggled()) SLA.instance = new SLA(map);
} }
@ -91,6 +91,6 @@ public class Timer {
public static void dropInstances() { public static void dropInstances() {
instance = null; instance = null;
GameMode.drop(); GameMode.drop();
Sla.drop(); SLA.drop();
} }
} }