Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
De6ris committed Mar 17, 2024
1 parent 9ae7ac0 commit b133713
Show file tree
Hide file tree
Showing 16 changed files with 566 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
replay_pid*
*.iml
/.idea
/src/META-INF
/out
17 changes: 17 additions & 0 deletions src/com/github/Debris/oh_my_mite_client/EventListener.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.github.Debris.oh_my_mite_client;

import com.google.common.eventbus.Subscribe;
import net.xiaoyu233.fml.reload.event.PlayerLoggedInEvent;

import static com.github.Debris.oh_my_mite_client.OhMyMiteClient.MOD_ID;

public class EventListener {
public EventListener() {
}

@Subscribe
public void onPlayerLoggedIn(PlayerLoggedInEvent event) {
String message = String.format("§f[Debris]:§r§b%s 已加载§r", MOD_ID);
event.getPlayer().addChatMessage(message);
}
}
57 changes: 57 additions & 0 deletions src/com/github/Debris/oh_my_mite_client/OhMyMiteClient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.github.Debris.oh_my_mite_client;

import com.github.Debris.oh_my_mite_client.config.Config;
import com.github.Debris.oh_my_mite_client.mixins.MixinMarker;
import net.xiaoyu233.fml.AbstractMod;
import net.xiaoyu233.fml.classloading.Mod;
import net.xiaoyu233.fml.config.ConfigRegistry;
import net.xiaoyu233.fml.config.InjectionConfig;
import net.xiaoyu233.fml.reload.event.MITEEvents;
import org.spongepowered.asm.mixin.MixinEnvironment;

import javax.annotation.Nonnull;
import java.io.File;

@Mod({MixinEnvironment.Side.CLIENT})
public class OhMyMiteClient extends AbstractMod {

public static final String MOD_ID = "OhMyMiteClient";

private static final ConfigRegistry CONFIG_REGISTRY = new ConfigRegistry(Config.ROOT, new File(MOD_ID + ".json"));


@Override
public void preInit() {
}

@Nonnull
@Override
public InjectionConfig getInjectionConfig() {
return InjectionConfig.Builder.of(MOD_ID, MixinMarker.class.getPackage(), MixinEnvironment.Phase.INIT).setRequired().build();
}

@Override
public String modId() {
return MOD_ID;
}

@Override
public int modVerNum() {
return 10;
}

@Override
public String modVerStr() {
return "v1.0";
}

@Override
public void postInit() {
MITEEvents.MITE_EVENT_BUS.register(new EventListener());
}

@Override
public ConfigRegistry getConfigRegistry() {
return CONFIG_REGISTRY;
}
}
12 changes: 12 additions & 0 deletions src/com/github/Debris/oh_my_mite_client/config/Config.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.github.Debris.oh_my_mite_client.config;

import net.xiaoyu233.fml.config.ConfigCategory;
import net.xiaoyu233.fml.config.ConfigEntry;
import net.xiaoyu233.fml.util.FieldReference;

public class Config {
public static final FieldReference<Integer> ATTACK_INTERVAL = new FieldReference<>(500);

public static final ConfigCategory ROOT = ConfigCategory.of("NoClickCD")
.addEntry(ConfigEntry.of("auto_attack_interval", ATTACK_INTERVAL).withComment("自动攻击间隔, 单位毫秒"));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.github.Debris.oh_my_mite_client.config;

import com.github.Debris.oh_my_mite_client.config.OMMCOptions;

public interface FieldAccessor {
OMMCOptions OMMCOptionsProvider();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.github.Debris.oh_my_mite_client.config;

import net.minecraft.KeyBinding;

public class KeyBindingBoolean extends KeyBinding {

private boolean value;

public KeyBindingBoolean(String s, int i, boolean defaultValue) {
super(s, i);
this.value = defaultValue;
}

public boolean getBoolean() {
return this.value;
}

public void invert() {
this.value = !this.value;
}
}
132 changes: 132 additions & 0 deletions src/com/github/Debris/oh_my_mite_client/config/OMMCGuiControls.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
package com.github.Debris.oh_my_mite_client.config;

import net.minecraft.*;

public class OMMCGuiControls extends GuiScreen {
private final GuiScreen parentScreen;
protected String screenTitle = "OMMC按键绑定";
private final OMMCOptions ommcOptions;
private int buttonId = -1;
private int page_index;

public OMMCGuiControls(GuiScreen par1GuiScreen, OMMCOptions par2GameSettings) {
this.parentScreen = par1GuiScreen;
this.ommcOptions = par2GameSettings;
}

private int getLeftBorder() {
return this.width / 2 - 155;
}

private int getKeybindButtonPosX(int index) {
index %= 10;
return this.getLeftBorder() + index % 2 * 160;
}

private int getKeybindButtonPosY(int index) {
index %= 10;
return this.height / 6 + 24 * (index / 2) + 6;
}

@Override
public void initGui() {
for (int var2 = 0; var2 < this.ommcOptions.allKeyBindings.length; ++var2) {
this.buttonList.add(new GuiSmallButton(var2, this.getKeybindButtonPosX(var2), this.getKeybindButtonPosY(var2), 70, 20, this.ommcOptions.allKeyBindings[var2].keyDescription));
}
this.setKeybindButtonVisibilities();
this.buttonList.add(new GuiButton(201, this.width / 2 - 100, this.height / 6 + 168 - 24, I18n.getString("gui.nextPage")));
this.buttonList.add(new GuiButton(200, this.width / 2 - 100, this.height / 6 + 168, I18n.getString("gui.done")));
}

private void setKeybindButtonVisibilities() {
for (int i = 0; i < this.ommcOptions.allKeyBindings.length; ++i) {
((GuiButton) this.buttonList.get(i)).drawButton = this.isKeybindButtonVisible(i);
}
}

private boolean isKeybindButtonVisible(int index) {
return index >= this.page_index * 10 && index < (this.page_index + 1) * 10;
}

protected void actionPerformed(GuiButton par1GuiButton) {
for (int var2 = 0; var2 < this.ommcOptions.allKeyBindings.length; ++var2) {
((GuiButton) this.buttonList.get(var2)).displayString = this.ommcOptions.allKeyBindings[var2].keyDescription;
}

if (par1GuiButton.id == 200) {
this.mc.displayGuiScreen(this.parentScreen);
} else if (par1GuiButton.id == 201) {
if (++this.page_index > (this.ommcOptions.allKeyBindings.length - 1) / 10) {
this.page_index = 0;
}

this.setKeybindButtonVisibilities();
} else {
this.buttonId = par1GuiButton.id;
par1GuiButton.displayString = "> " + this.ommcOptions.getOptionDisplayString(par1GuiButton.id) + " <";
}
}

protected void mouseClicked(int par1, int par2, int par3) {
if (this.buttonId >= 0) {
this.ommcOptions.setKeyBinding(this.buttonId, -100 + par3);
((GuiButton) this.buttonList.get(this.buttonId)).displayString = this.ommcOptions.getOptionDisplayString(this.buttonId);
this.buttonId = -1;
KeyBinding.resetKeyBindingArrayAndHash();
} else {
super.mouseClicked(par1, par2, par3);
}
}

protected void keyTyped(char par1, int par2) {
if (this.buttonId >= 0) {
this.ommcOptions.setKeyBinding(this.buttonId, par2);
((GuiButton) this.buttonList.get(this.buttonId)).displayString = this.ommcOptions.getOptionDisplayString(this.buttonId);
this.buttonId = -1;
KeyBinding.resetKeyBindingArrayAndHash();
} else {
super.keyTyped(par1, par2);
}
}

public void drawScreen(int par1, int par2, float par3) {
this.drawDefaultBackground();
this.drawCenteredString(this.fontRenderer, this.screenTitle, this.width / 2, 20, 16777215);
int var5 = 0;

while (var5 < this.ommcOptions.allKeyBindings.length) {
if (!this.isKeybindButtonVisible(var5)) {
++var5;
} else {
boolean var6 = false;

for (int var7 = 0; var7 < this.ommcOptions.allKeyBindings.length; ++var7) {
if (var7 != var5 && this.ommcOptions.allKeyBindings[var5].keyCode == this.ommcOptions.allKeyBindings[var7].keyCode) {
var6 = true;
break;
}
}

for (int var7 = 0; var7 < this.mc.gameSettings.keyBindings.length; ++var7) {
if (this.ommcOptions.allKeyBindings[var5].keyCode == this.mc.gameSettings.keyBindings[var7].keyCode) {
var6 = true;
break;
}
}

if (this.buttonId == var5) {
((GuiButton) this.buttonList.get(var5)).displayString = "" + EnumChatFormatting.WHITE + "> " + EnumChatFormatting.YELLOW + "??? " + EnumChatFormatting.WHITE + "<";
} else if (var6) {
((GuiButton) this.buttonList.get(var5)).displayString = EnumChatFormatting.RED + this.ommcOptions.getOptionDisplayString(var5);
} else {
((GuiButton) this.buttonList.get(var5)).displayString = this.ommcOptions.getOptionDisplayString(var5);
}

this.drawString(this.fontRenderer, this.ommcOptions.getKeyBindingDescription(var5), this.getKeybindButtonPosX(var5) + 70 + 6, this.getKeybindButtonPosY(var5) + 7, -1);
++var5;
}
}

super.drawScreen(par1, par2, par3);
}
}
114 changes: 114 additions & 0 deletions src/com/github/Debris/oh_my_mite_client/config/OMMCOptions.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package com.github.Debris.oh_my_mite_client.config;

import net.minecraft.I18n;
import net.minecraft.KeyBinding;
import org.lwjgl.input.Keyboard;

import java.io.*;
import java.util.Arrays;
import java.util.stream.Stream;

public class OMMCOptions {
private final File optionsFile;
public int gameMode = 0;
public KeyBindingBoolean keyBindAutoForward = new KeyBindingBoolean("自动前进", 200, false);
public KeyBindingBoolean keyBindAutoLeft = new KeyBindingBoolean("自动向左", 203, false);
public KeyBindingBoolean keyBindAutoBack = new KeyBindingBoolean("自动后退", 208, false);
public KeyBindingBoolean keyBindAutoRight = new KeyBindingBoolean("自动向右", 205, false);
public KeyBindingBoolean keyBindAutojump = new KeyBindingBoolean("自动跳跃", 0, false);
public KeyBindingBoolean keyBindAutoSneak = new KeyBindingBoolean("自动潜行", 0, false);
public KeyBindingBoolean keyBindAutoAttack = new KeyBindingBoolean("自动攻击", 36, false);//J
public KeyBindingBoolean keyBindHoldUse = new KeyBindingBoolean("长按右键", 22, false);//U
public KeyBindingBoolean keyBindAutoCraft = new KeyBindingBoolean("自动合成", 0, false);
public KeyBinding keyBindCopyTP = new KeyBinding("复制tp坐标", 46);//C
public KeyBinding keyBindToggleMode = new KeyBinding("切换游戏模式", 62);//F4

public KeyBindingBoolean[] keyBindingBooleans;
public KeyBinding[] keyBindingTriggers;
public KeyBinding[] allKeyBindings;

public OMMCOptions(File file) {
this.initKeybindings();
this.optionsFile = new File(file, "OMMCoptions.txt");
this.loadOptions();
}

public void initKeybindings() {
this.keyBindingBooleans = new KeyBindingBoolean[]{
keyBindAutoForward,
keyBindAutoLeft,
keyBindAutoBack,
keyBindAutoRight,
keyBindAutojump,
keyBindAutoSneak,
keyBindAutoAttack,
keyBindHoldUse,
keyBindAutoCraft
};

this.keyBindingTriggers = new KeyBinding[]{
keyBindCopyTP,
keyBindToggleMode
};

Stream<KeyBinding> stream1 = Arrays.stream(this.keyBindingBooleans);
Stream<KeyBinding> stream2 = Arrays.stream(this.keyBindingTriggers);

this.allKeyBindings = Stream.concat(stream1, stream2).toArray(KeyBinding[]::new);
}

public void setKeyBinding(int par1, int par2) {
this.allKeyBindings[par1].keyCode = par2;
this.saveOptions();
}

public void loadOptions() {
BufferedReader var1;
try {
if (!this.optionsFile.exists()) {
return;
}
var1 = new BufferedReader(new FileReader(this.optionsFile));
String var2;
while ((var2 = var1.readLine()) != null) {
String[] var3 = var2.split(":");
for (int var4 = 0; var4 < this.allKeyBindings.length; ++var4) {
if (var3[0].equals("key_" + this.allKeyBindings[var4].keyDescription)) {
this.allKeyBindings[var4].keyCode = Integer.parseInt(var3[1]);
}
}
}
KeyBinding.resetKeyBindingArrayAndHash();
var1.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}

public void saveOptions() {
PrintWriter var1;
try {
var1 = new PrintWriter(new FileWriter(this.optionsFile));
for (int var2 = 0; var2 < this.allKeyBindings.length; ++var2) {
var1.println("key_" + this.allKeyBindings[var2].keyDescription + ":" + this.allKeyBindings[var2].keyCode);
}
var1.close();
} catch (IOException e) {
throw new RuntimeException(e);
}

}

public String getOptionDisplayString(int par1) {
int var2 = this.allKeyBindings[par1].keyCode;
return getKeyDisplayString(var2);
}

public static String getKeyDisplayString(int par0) {
return Keyboard.getKeyName(par0);
}

public String getKeyBindingDescription(int par1) {
return I18n.getString(this.allKeyBindings[par1].keyDescription);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.github.Debris.oh_my_mite_client.mixins;

public class MixinMarker {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.github.Debris.oh_my_mite_client.mixins;

import net.minecraft.MITEContainerCrafting;
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(MITEContainerCrafting.class)
public class OMMCCraftingMixin {
@Inject(method = "onUpdate", at = @At(value = "INVOKE", target = "Lnet/minecraft/NetClientHandler;addToSendQueue(Lnet/minecraft/Packet;)V"))
private void inject(CallbackInfo ci) {

}
}
Loading

0 comments on commit b133713

Please sign in to comment.