Created
March 12, 2022 02:48
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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