Skip to content

Instantly share code, notes, and snippets.

@SamHoque
Created March 12, 2022 02:48
Show Gist options
  • Save SamHoque/941e220d4305e4414b59ee96b49a271c to your computer and use it in GitHub Desktop.
Save SamHoque/941e220d4305e4414b59ee96b49a271c to your computer and use it in GitHub Desktop.
A simple forge mod I created in 2016 that would auto mine and repair the pickaxe on a server I used to play on.
public class Main {
static final String MODID = "Rab";
static final String VERSION = "1.0";
private Minecraft mc = Minecraft.getMinecraft();
private boolean repair;
@Mod.EventHandler
public void init(final FMLPreInitializationEvent event) {
MinecraftForge.EVENT_BUS.register(this);
}
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onTick(TickEvent event) {
EntityPlayerSP player = mc.thePlayer;
if(player != null) {
ItemStack currentItem = player.getCurrentEquippedItem();
if (currentItem != null) {
Item item = currentItem.getItem();
if (!isPickaxe(item)) {
setMining(false);
return;
}
if (almostBroken(currentItem)) {
if (!repair) {
setMining(false);
repair = true;
mc.thePlayer.sendChatMessage("/drepair");
}
return;
}
}
setMining(true);
}
}
private void setMining(final boolean value) {
KeyBinding.setKeyBindState(mc.gameSettings.keyBindAttack.getKeyCode(), value);
KeyBinding.onTick(mc.gameSettings.keyBindAttack.getKeyCode());
}
@SubscribeEvent
public void onReceivedMessage(ClientChatReceivedEvent event) {
String isRequestIncoming = event.message.getUnformattedText();
if (isRequestIncoming.equals("MINELINK You cannot use commands before you move!")) {
mc.thePlayer.rotationYaw = mc.thePlayer.rotationYaw - 90;
mc.thePlayer.rotationYaw = mc.thePlayer.rotationYaw + 90;
repair = false;
}
}
private static boolean almostBroken(ItemStack itemStack) {
double damage = itemStack.getItemDamage() / itemStack.getMaxDamage();
return damage > 0.1;
}
private static boolean isPickaxe(Item item) {
return item == Items.diamond_pickaxe || item == Items.iron_pickaxe || item == Items.golden_pickaxe || item == Items.stone_pickaxe || item == Items.wooden_pickaxe;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment