Skip to content

Commit

Permalink
Add autojoin
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgeRNG committed Apr 8, 2023
1 parent 54f1f70 commit 06698c4
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 11 deletions.
15 changes: 14 additions & 1 deletion src/main/java/dev/dfonline/codeclient/CodeClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class CodeClient implements ModInitializer {
public static final MinecraftClient MC = MinecraftClient.getInstance();
public static final Gson gson = new Gson();
private static KeyBinding editBind;

public static AutoJoin autoJoin = AutoJoin.NONE;

@NotNull
public static Action currentAction = new None();
Expand Down Expand Up @@ -68,6 +68,10 @@ public static void onTick() {
while(editBind.isPressed()) {
MC.setScreen(new DevInventoryScreen(MC.player));
}
if(autoJoin == AutoJoin.PLOT) {
MC.getNetworkHandler().sendCommand("join " + Config.getConfig().AutoJoinPlotId);
autoJoin = AutoJoin.NONE;
}
}

@Override
Expand All @@ -81,6 +85,9 @@ public void onInitialize() {
LOGGER.error(e.getMessage());
}
}
if(Config.getConfig().AutoJoin) {
autoJoin = AutoJoin.GAME;
}

editBind = KeyBindingHelper.registerKeyBinding(new KeyBinding(
"key.codeclient.actionpallete",
Expand All @@ -93,4 +100,10 @@ public void onInitialize() {
Commands.register(dispatcher);
});
}

public enum AutoJoin {
NONE,
GAME,
PLOT
}
}
76 changes: 67 additions & 9 deletions src/main/java/dev/dfonline/codeclient/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ public class Config {
public boolean CCDBUG = true;
public boolean CustomBlockInteractions = true;
public boolean CustomTagInteraction = false;
public boolean AutoJoin = false;
public Node AutoNode = Node.None;
public boolean AutoJoinPlot = false;
public int AutoJoinPlotId = 0;

private void save() {
try {
Expand All @@ -32,6 +36,10 @@ private void save() {
object.addProperty("CCDBUG",CCDBUG);
object.addProperty("CustomBlockInteractions",CustomBlockInteractions);
object.addProperty("CustomTagInteraction",CustomTagInteraction);
object.addProperty("AutoJoin", AutoJoin);
object.addProperty("AutoNode",AutoNode.name());
object.addProperty("AutoJoinPlot",AutoJoinPlot);
object.addProperty("AutoJoinPlotId",AutoJoinPlotId);
FileManager.writeFile("options.json", object.toString());
} catch (Exception e) {
CodeClient.LOGGER.info("Couldn't save config: " + e);
Expand Down Expand Up @@ -129,20 +137,70 @@ public YetAnotherConfigLib getLibConfig() {
.controller(TickBoxController::new)
.build())
.build())
.category(ConfigCategory.createBuilder()
.name(Text.literal("AutoJoin"))
.tooltip(Text.literal("If and where to auto join"))
.option(Option.createBuilder(boolean.class)
.name(Text.literal("Enabled"))
.tooltip(Text.literal("If CodeClient should automatically connect you to DF."))
.binding(
false,
() -> AutoJoin,
opt -> AutoJoin = opt
)
.controller(TickBoxController::new)
.build())
.option(Option.createBuilder(Node.class)
.name(Text.literal("Node"))
.tooltip(Text.literal("Which node you should be sent to, or have DF handle it."))
.binding(
Node.None,
() -> AutoNode,
opt -> AutoNode = opt
)
.controller(EnumController::new)
// .available(AutoJoin)
.build())
.option(Option.createBuilder(boolean.class)
.name(Text.literal("Auto join plot"))
.tooltip(Text.literal("If you should automatically be sent to a plot."))
.binding(
false,
() -> AutoJoinPlot,
opt -> AutoJoinPlot = opt
)
.controller(TickBoxController::new)
.build())
.option(Option.createBuilder(int.class)
.name(Text.literal("Plot ID"))
.tooltip(Text.literal("The plot ID of the plot to automatically join, if enabled."))
.binding(
0,
() -> AutoJoinPlotId,
opt -> AutoJoinPlotId = opt
)
.controller(IntegerFieldController::new)
.build())
.build())
.save(this::save)
.build();
}

public enum Node {
None,
Node1,
Node2,
Node3,
Node4,
Node5,
Node6,
Node7,
Beta,
None(""),
Node1("node1."),
Node2("node2."),
Node3("node3."),
Node4("node4."),
Node5("node5."),
Node6("node6."),
Node7("node7."),
Beta("beta.");

public final String prepend;
Node(String prepend) {
this.prepend = prepend;
}
}

public Config() {
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/dev/dfonline/codeclient/mixin/MTitleScreen.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package dev.dfonline.codeclient.mixin;

import dev.dfonline.codeclient.CodeClient;
import dev.dfonline.codeclient.config.Config;
import net.minecraft.client.gui.screen.ConnectScreen;
import net.minecraft.client.gui.screen.TitleScreen;
import net.minecraft.client.network.ServerAddress;
import net.minecraft.client.network.ServerInfo;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(TitleScreen.class)
public class MTitleScreen {
@Inject(method = "init", at = @At("RETURN"))
public void onInit(CallbackInfo ci) {
if(CodeClient.autoJoin == CodeClient.AutoJoin.GAME) {
ServerInfo info = new ServerInfo("DiamondFire", Config.getConfig().AutoNode.prepend + "mcdiamondfire.com", false);
ConnectScreen.connect((TitleScreen)(Object)this, CodeClient.MC, ServerAddress.parse(info.address), info);

CodeClient.autoJoin =Config.getConfig().AutoJoinPlot ? CodeClient.AutoJoin.PLOT : CodeClient.AutoJoin.NONE;
}
}
}
3 changes: 2 additions & 1 deletion src/main/resources/CodeClient.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"MInGameHud",
"MInGameOverlayRenderer",
"MLivingEntity",
"MPlayerEntity"
"MPlayerEntity",
"MTitleScreen"
],
"injectors": {
"defaultRequire": 1
Expand Down

0 comments on commit 06698c4

Please sign in to comment.