chatmacro, quicksla, minor changes
This commit is contained in:
parent
c4109607c3
commit
9026529071
13 changed files with 202 additions and 64 deletions
|
@ -3,4 +3,4 @@ org.gradle.jvmargs=-Xmx2g
|
|||
baseGroup = com.github.stachelbeere1248.zombiesutils
|
||||
mcVersion = 1.8.9
|
||||
modid = zombiesutils
|
||||
version = 1.0.3
|
||||
version = 1.1.1
|
|
@ -2,7 +2,8 @@ package com.github.stachelbeere1248.zombiesutils;
|
|||
|
||||
import com.github.stachelbeere1248.zombiesutils.commands.CategoryCommand;
|
||||
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.TickHandler;
|
||||
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")
|
||||
public class ZombiesUtils {
|
||||
private static ZombiesUtils instance;
|
||||
private final Hotkeys hotkeys;
|
||||
private Logger logger;
|
||||
public ZombiesUtils() {
|
||||
hotkeys = new Hotkeys();
|
||||
instance = this;
|
||||
}
|
||||
public static ZombiesUtils getInstance() {
|
||||
|
@ -29,19 +32,30 @@ public class ZombiesUtils {
|
|||
@Mod.EventHandler
|
||||
public void preInit(@NotNull FMLPreInitializationEvent event) {
|
||||
logger = event.getModLog();
|
||||
Config.config = new Configuration(event.getSuggestedConfigurationFile());
|
||||
Config.load();
|
||||
ZombiesUtilsConfig.config = new Configuration(
|
||||
event.getSuggestedConfigurationFile(),
|
||||
"1.1.1"
|
||||
);
|
||||
ZombiesUtilsConfig.load();
|
||||
}
|
||||
@Mod.EventHandler
|
||||
public void init(FMLInitializationEvent event) {
|
||||
MinecraftForge.EVENT_BUS.register(new ZombiesUtilsConfig());
|
||||
MinecraftForge.EVENT_BUS.register(new RenderGameOverlayHandler());
|
||||
MinecraftForge.EVENT_BUS.register(new TickHandler());
|
||||
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 SlaCommand());
|
||||
|
||||
hotkeys.registerAll();
|
||||
}
|
||||
public Logger getLogger() {
|
||||
return logger;
|
||||
}
|
||||
|
||||
public Hotkeys getHotkeys() {
|
||||
return hotkeys;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package com.github.stachelbeere1248.zombiesutils.commands;
|
||||
|
||||
import com.github.stachelbeere1248.zombiesutils.game.Map;
|
||||
import com.github.stachelbeere1248.zombiesutils.game.windows.Sla;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import com.github.stachelbeere1248.zombiesutils.game.sla.QuickSLA;
|
||||
import com.github.stachelbeere1248.zombiesutils.game.sla.SLA;
|
||||
import net.minecraft.command.*;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.util.ChatComponentText;
|
||||
|
@ -26,74 +26,118 @@ public class SlaCommand extends CommandBase {
|
|||
|
||||
@Override
|
||||
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 {
|
||||
switch (args[0]) {
|
||||
case "off":
|
||||
Sla.drop();
|
||||
SLA.drop();
|
||||
sender.addChatMessage(new ChatComponentText("SLA data deleted"));
|
||||
break;
|
||||
case "offset":
|
||||
if (args.length == 1) Sla.getInstance().ifPresent(Sla::resetOffset);
|
||||
else if (args.length != 4) throw new WrongUsageException("An offset should have three coordinates!");
|
||||
if (args.length == 1) SLA.getInstance().ifPresent(SLA::resetOffset);
|
||||
else if (args.length != 4) throw new WrongUsageException(
|
||||
"An offset should have three coordinates!");
|
||||
else {
|
||||
try {
|
||||
double x = Double.parseDouble(args[1]);
|
||||
double y = Double.parseDouble(args[2]);
|
||||
double z = Double.parseDouble(args[3]);
|
||||
Sla.getInstance().ifPresent(sla -> sla.setOffset(new double[]{x, y, z}));
|
||||
sender.addChatMessage(new ChatComponentText(String.format("Offset set to %s %s %s", x, y, z)));
|
||||
int x = Integer.parseInt(args[1]);
|
||||
int y = Integer.parseInt(args[2]);
|
||||
int z = Integer.parseInt(args[3]);
|
||||
SLA.getInstance().ifPresent(sla -> sla.setOffset(new int[]{x, y, z}));
|
||||
} catch (NumberFormatException ignored) {
|
||||
throw new NumberInvalidException();
|
||||
throw new NumberInvalidException("Invalid Integer:", args[1]);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "rotate":
|
||||
sender.addChatMessage(new ChatComponentText("Rotating map..."));
|
||||
Sla.getInstance().ifPresent(Sla::rotate);
|
||||
if (args.length == 1) SLA.getInstance().ifPresent(sla -> sla.rotate(1));
|
||||
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;
|
||||
case "mirror":
|
||||
switch (args[1]) {
|
||||
case "x":
|
||||
Sla.getInstance().ifPresent(Sla::mirrorX);
|
||||
SLA.getInstance().ifPresent(SLA::mirrorX);
|
||||
break;
|
||||
case "z":
|
||||
Sla.getInstance().ifPresent(Sla::mirrorZ);
|
||||
SLA.getInstance().ifPresent(SLA::mirrorZ);
|
||||
break;
|
||||
default: throw new WrongUsageException("Invalid option: available: x, z");
|
||||
default:
|
||||
throw new WrongUsageException("Invalid option: available: x, z");
|
||||
}
|
||||
break;
|
||||
case "map":
|
||||
switch (args[1]) {
|
||||
case "de":
|
||||
Sla.instance = new Sla(Map.DEAD_END);
|
||||
Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("SLA forced to map DE"));
|
||||
SLA.instance = new SLA(Map.DEAD_END);
|
||||
break;
|
||||
case "bb":
|
||||
Sla.instance = new Sla(Map.BAD_BLOOD);
|
||||
Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("SLA forced to map BB"));
|
||||
SLA.instance = new SLA(Map.BAD_BLOOD);
|
||||
break;
|
||||
case "aa":
|
||||
Sla.instance = new Sla(Map.ALIEN_ARCADIUM);
|
||||
Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("SLA forced to map AA"));
|
||||
SLA.instance = new SLA(Map.ALIEN_ARCADIUM);
|
||||
break;
|
||||
default: throw new WrongUsageException("Invalid option: available: de, bb, aa");
|
||||
|
||||
default:
|
||||
throw new WrongUsageException(
|
||||
"[Invalid option] options: de, bb, aa", args[1]);
|
||||
}
|
||||
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
|
||||
public List<String> addTabCompletionOptions(ICommandSender sender, String @NotNull [] args, BlockPos blockPos) {
|
||||
List<String> options = new ArrayList<>();
|
||||
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))
|
||||
options.add("0");
|
||||
else if ("map".equals(args[0])) options.addAll(Arrays.asList("de", "bb", "aa"));
|
||||
else if ("mirror".equals(args[0])) {
|
||||
options.addAll(Arrays.asList("x","z"));
|
||||
if (args.length == 1) options.addAll(Arrays.asList("off", "offset", "rotate", "mirror", "map"));
|
||||
else {
|
||||
if (args.length > 1) switch (args[0]) {
|
||||
case "offset":
|
||||
if (args.length<5) options.add("0");
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ public class GuiConfig extends net.minecraftforge.fml.client.config.GuiConfig {
|
|||
public GuiConfig(GuiScreen parentScreen) {
|
||||
super(
|
||||
parentScreen,
|
||||
new ConfigElement(Config.config.getCategory(Configuration.CATEGORY_GENERAL)).getChildElements(),
|
||||
new ConfigElement(ZombiesUtilsConfig.config.getCategory(Configuration.CATEGORY_GENERAL)).getChildElements(),
|
||||
"zombiesutils",
|
||||
false,
|
||||
false,
|
||||
|
|
|
@ -8,13 +8,8 @@ import java.util.Set;
|
|||
|
||||
public class GuiFactory implements IModGuiFactory {
|
||||
|
||||
public boolean hasConfigGui() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(Minecraft minecraft) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -6,10 +6,10 @@ import net.minecraftforge.fml.client.event.ConfigChangedEvent;
|
|||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class Config {
|
||||
public class ZombiesUtilsConfig {
|
||||
public static Configuration config;
|
||||
|
||||
private static boolean slaToggle;
|
||||
private static String chatMacro;
|
||||
public static void load() {
|
||||
ZombiesUtils.getInstance().getLogger().debug("Loading config...");
|
||||
config.load();
|
||||
|
@ -21,6 +21,12 @@ public class Config {
|
|||
slaToggle,
|
||||
"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...");
|
||||
config.save();
|
||||
|
@ -30,10 +36,13 @@ public class Config {
|
|||
public void onConfigChange(ConfigChangedEvent.@NotNull OnConfigChangedEvent event) {
|
||||
if (event.modID.equals("zombiesutils") && event.configID == null) {
|
||||
config.save();
|
||||
Config.load();
|
||||
ZombiesUtilsConfig.load();
|
||||
}
|
||||
}
|
||||
public static boolean isSlaToggled() {
|
||||
return slaToggle;
|
||||
}
|
||||
public static String getChatMacro() {
|
||||
return chatMacro;
|
||||
}
|
||||
}
|
|
@ -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
|
||||
}
|
||||
}
|
|
@ -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.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.entity.EntityPlayerSP;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
@ -9,13 +11,13 @@ import org.jetbrains.annotations.NotNull;
|
|||
import java.util.Arrays;
|
||||
import java.util.Optional;
|
||||
|
||||
public class Sla {
|
||||
public static Sla instance = null;
|
||||
private final double[] offset = new double[3];
|
||||
public class SLA {
|
||||
public static SLA instance = null;
|
||||
private final int[] offset = new int[3];
|
||||
private final Room[] rooms;
|
||||
|
||||
|
||||
public Sla(@NotNull Map map) {
|
||||
public SLA(@NotNull Map map) {
|
||||
switch (map) {
|
||||
case DEAD_END: this.rooms = Room.getDE(); 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 (Window window: room.getWindows()) {
|
||||
window.rotate();
|
||||
window.rotate(rotations);
|
||||
}
|
||||
}
|
||||
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]));
|
||||
}
|
||||
|
||||
// (2x)² + (2y)² + (2z)² = 4 (x²+y²+z²)
|
||||
// (2x)²+(2y)²+(2z)² = 4(x²+y²+z²) = 4d²
|
||||
if (distanceDoubledThenSquared < 10000) {
|
||||
window.setActive(true);
|
||||
room.increaseActiveWindowCount();
|
||||
|
@ -76,7 +78,7 @@ public class Sla {
|
|||
}
|
||||
|
||||
|
||||
public static Optional<Sla> getInstance() {
|
||||
public static Optional<SLA> getInstance() {
|
||||
return Optional.ofNullable(instance);
|
||||
}
|
||||
public static void drop() {
|
||||
|
@ -88,7 +90,7 @@ public class Sla {
|
|||
public void resetOffset() {
|
||||
Arrays.fill(this.offset, 0);
|
||||
}
|
||||
public void setOffset(double[] offset) {
|
||||
public void setOffset(int[] offset) {
|
||||
System.arraycopy(offset, 0, this.offset, 0, 3);
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
||||
@SuppressWarnings("DuplicatedCode")
|
|
@ -23,11 +23,35 @@ public class Window {
|
|||
public boolean isActive() {
|
||||
return isActive;
|
||||
}
|
||||
public void rotate() {
|
||||
private void rotateCounterClockwise() {
|
||||
final short x = xyz[0], z = xyz[2];
|
||||
xyz[0] = (short) -z;
|
||||
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() {
|
||||
xyz[0] = (short) -xyz[0];
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
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.Sla;
|
||||
import com.github.stachelbeere1248.zombiesutils.timer.Timer;
|
||||
import com.github.stachelbeere1248.zombiesutils.utils.Scoreboard;
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
@ -24,7 +24,7 @@ public class RenderGameOverlayHandler {
|
|||
public void onRenderGameOverlay(RenderGameOverlayEvent.@NotNull Post event) {
|
||||
if (event.type != RenderGameOverlayEvent.ElementType.TEXT) return;
|
||||
Timer.getInstance().ifPresent(timer -> renderTime(timer.roundTime()));
|
||||
Sla.getInstance().ifPresent(sla -> {
|
||||
SLA.getInstance().ifPresent(sla -> {
|
||||
sla.refreshActives();
|
||||
renderSla(sla.getRooms());
|
||||
});
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package com.github.stachelbeere1248.zombiesutils.timer;
|
||||
|
||||
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.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 net.minecraft.client.Minecraft;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
@ -35,7 +35,7 @@ public class Timer {
|
|||
|
||||
this.category = new Category();
|
||||
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() {
|
||||
instance = null;
|
||||
GameMode.drop();
|
||||
Sla.drop();
|
||||
SLA.drop();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue