Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
ItziSpyder authored Apr 9, 2023
1 parent 0b357f3 commit e8a7bfd
Show file tree
Hide file tree
Showing 12 changed files with 191 additions and 14 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ org.gradle.jvmargs=-Xmx1G
loader_version=0.14.14

# Mod Properties
mod_version = 1.19.4-0.6.5
mod_version = 1.19.4-0.7.0
maven_group = io.github.itzispyder
archives_base_name = ClickCrystals

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ public void onInitialize() {
system.addModule(new TpTotem());
system.addModule(new AhhGameCrashed());
system.addModule(new NoResourcePack());
system.addModule(new ToolSwitcher());
system.addModule(new AnchorSearch());
Module.loadConfigModules();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ public class ClickCrystalMenuScreen extends Screen implements Listener {
KEY_CATEGORY
));
public static final int
MAX_ROW_PER_COLUMN = 6,
MAX_ROW_PER_COLUMN = 7,
MARGIN_TOP = 80,
MARGIN_LEFT = 25,
GAP = 3,
BUTTON_HEIGHT = 18,
BUTTON_WIDTH = 130;
BUTTON_HEIGHT = 14,
BUTTON_WIDTH = 90;

/**
* Constructs a new menu screen for the module screen
Expand Down Expand Up @@ -75,7 +75,7 @@ public void init() {
button -> {

});
super.addDrawableChild(title);
super.addDrawable(title);

int y = 0, x = 0;
List<Module> sortedModules = system.modules().values()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ public String getName() {
return name;
}

public String getNameLimited() {
if (name.length() <= 13) return name;
return name.substring(0,11) + "...";
}

/**
* Gets the name of the module, but in a format that can be saved as a file and
* without any special characters.
Expand Down Expand Up @@ -104,7 +109,7 @@ public void sendUpdateInfo() {
* @return label
*/
public String getCurrentStateLabel() {
return "§b" + name + "§7: " + getToggledStateMessage();
return (enabled ? "§b" : "§7") + getNameLimited();
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package io.github.itzispyder.clickcrystals.modules.modules;

import io.github.itzispyder.clickcrystals.events.EventHandler;
import io.github.itzispyder.clickcrystals.events.Listener;
import io.github.itzispyder.clickcrystals.events.events.PacketSendEvent;
import io.github.itzispyder.clickcrystals.modules.Module;
import io.github.itzispyder.clickcrystals.util.BlockUtils;
import io.github.itzispyder.clickcrystals.util.HotbarUtils;
import net.minecraft.item.Items;
import net.minecraft.network.packet.c2s.play.PlayerInteractBlockC2SPacket;
import net.minecraft.util.math.BlockPos;

public class AnchorSearch extends Module implements Listener {

public AnchorSearch() {
super("AnchorSearch","Searches your hotbar for anchors when you right click an end crystal on a non-crystallable block.");
}

@Override
protected void onEnable() {
system.addListener(this);
}

@Override
protected void onDisable() {
system.removeListener(this);
}

@EventHandler
private void onClickBlock(PacketSendEvent e) {
if (e.getPacket() instanceof PlayerInteractBlockC2SPacket packet) {
BlockPos pos = packet.getBlockHitResult().getBlockPos();
if (BlockUtils.isCrystallabe(pos)) return;
if (!HotbarUtils.nameContains("crystal")) return;
if (!HotbarUtils.has(Items.RESPAWN_ANCHOR)) return;
e.setCancelled(true);
HotbarUtils.search(Items.RESPAWN_ANCHOR);
BlockUtils.interact(packet.getBlockHitResult());
HotbarUtils.search(Items.GLOWSTONE);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@
import io.github.itzispyder.clickcrystals.util.HotbarUtils;
import io.github.itzispyder.clickcrystals.util.InteractionUtils;
import io.github.itzispyder.clickcrystals.util.Randomizer;
import net.minecraft.block.Blocks;
import net.minecraft.item.Items;
import net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;

/**
* ClickCrystal module
Expand Down Expand Up @@ -46,7 +44,7 @@ private void onSendPacket(PacketSendEvent e) {
if (e.getPacket() instanceof PlayerActionC2SPacket packet) {
if (packet.getAction() != PlayerActionC2SPacket.Action.START_DESTROY_BLOCK) return;
BlockPos pos = packet.getPos();
if (!(BlockUtils.matchBlock(pos,Blocks.OBSIDIAN) || BlockUtils.matchBlock(pos,Blocks.BEDROCK))) return;
if (!BlockUtils.isCrystallabe(pos)) return;

if (HotbarUtils.isHolding(Items.END_CRYSTAL)) {
e.setCancelled(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import io.github.itzispyder.clickcrystals.util.HotbarUtils;
import io.github.itzispyder.clickcrystals.util.InteractionUtils;
import io.github.itzispyder.clickcrystals.util.Randomizer;
import net.minecraft.block.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
Expand Down Expand Up @@ -37,7 +36,7 @@ private void onSendPacket(PacketSendEvent e) {
if (e.getPacket() instanceof PlayerActionC2SPacket packet) {
if (packet.getAction() != PlayerActionC2SPacket.Action.START_DESTROY_BLOCK) return;
BlockPos pos = packet.getPos();
if (!(BlockUtils.matchBlock(pos, Blocks.OBSIDIAN) || BlockUtils.matchBlock(pos,Blocks.BEDROCK))) return;
if (!BlockUtils.isCrystallabe(pos)) return;
if (!HotbarUtils.has(Items.END_CRYSTAL)) return;

if (HotbarUtils.nameContains("obsidian") || HotbarUtils.nameContains("totem") || HotbarUtils.nameContains("sword")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import io.github.itzispyder.clickcrystals.modules.Module;
import io.github.itzispyder.clickcrystals.util.BlockUtils;
import io.github.itzispyder.clickcrystals.util.HotbarUtils;
import net.minecraft.block.Blocks;
import net.minecraft.item.Items;
import net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket;
import net.minecraft.util.math.BlockPos;
Expand Down Expand Up @@ -39,10 +38,10 @@ private void onPacketSend(PacketSendEvent e) {
cooldown = System.currentTimeMillis() + (50 * 4);
if (packet.getAction() != PlayerActionC2SPacket.Action.START_DESTROY_BLOCK) return;
BlockPos pos = packet.getPos();
if (BlockUtils.matchBlock(pos,Blocks.OBSIDIAN) || BlockUtils.matchBlock(pos,Blocks.BEDROCK)) return;
if (BlockUtils.isCrystallabe(pos)) return;
if (!HotbarUtils.has(Items.END_CRYSTAL)) return;

if (HotbarUtils.nameContains("crystal") || HotbarUtils.nameContains("totem") || HotbarUtils.nameContains("sword")) {
if (HotbarUtils.nameContains("crystal") || HotbarUtils.nameContains("totem") || HotbarUtils.nameContains("sword") || HotbarUtils.nameContains("anchor")) {
e.setCancelled(true);
HotbarUtils.search(Items.OBSIDIAN);
BlockUtils.interact(pos,packet.getDirection());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package io.github.itzispyder.clickcrystals.modules.modules;

import io.github.itzispyder.clickcrystals.events.EventHandler;
import io.github.itzispyder.clickcrystals.events.Listener;
import io.github.itzispyder.clickcrystals.events.events.PacketSendEvent;
import io.github.itzispyder.clickcrystals.modules.Module;
import io.github.itzispyder.clickcrystals.util.BlockUtils;
import io.github.itzispyder.clickcrystals.util.HotbarUtils;
import io.github.itzispyder.clickcrystals.util.NbtUtils;
import net.minecraft.block.BlockState;
import net.minecraft.enchantment.Enchantments;
import net.minecraft.item.ItemStack;
import net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket;
import net.minecraft.util.math.BlockPos;

import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;

/**
* ToolSwitcher module
*/
public class ToolSwitcher extends Module implements Listener {

public ToolSwitcher() {
super("ToolSwitcher","Auto switches to the efficient tool when you try to break a block.");
}


@Override
protected void onEnable() {
system.addListener(this);
}

@Override
protected void onDisable() {
system.removeListener(this);
}

@EventHandler
private void onPacketSend(PacketSendEvent e) {
if (e.getPacket() instanceof PlayerActionC2SPacket packet) {
if (packet.getAction() == PlayerActionC2SPacket.Action.START_DESTROY_BLOCK) {
BlockPos pos = packet.getPos();
BlockState state = mc.player.getWorld().getBlockState(pos);
if (BlockUtils.isCrystallabe(pos)) return;
if (HotbarUtils.nameContains("sword") || HotbarUtils.nameContains("totem") || HotbarUtils.nameContains("crystal") || HotbarUtils.nameContains("anchor")) return;

Map<Integer,Float> entries = new HashMap<>();
HotbarUtils.forEachItem((slot,item) -> {
entries.put(slot,calcWantedLvl(item,state));
});
int slot = entries.keySet()
.stream()
.max(Comparator.comparing(entries::get))
.get();
if (entries.get(slot) != 1) mc.player.getInventory().selectedSlot = slot;
}
}
}

private float calcWantedLvl(ItemStack item, BlockState state) {
float lvl = 0;
lvl += item.getMiningSpeedMultiplier(state);
lvl += NbtUtils.getEnchantLvL(item,Enchantments.EFFICIENCY);
lvl += NbtUtils.getEnchantLvL(item,Enchantments.UNBREAKING);
lvl += NbtUtils.getEnchantLvL(item,Enchantments.MENDING);
return lvl;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.util.ActionResult;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
Expand Down Expand Up @@ -83,4 +84,8 @@ public static boolean matchBlock(BlockPos pos, Block block) {
BlockState state = world.getBlockState(pos);
return state != null && state.isOf(block);
}

public static boolean isCrystallabe(BlockPos pos) {
return matchBlock(pos,Blocks.OBSIDIAN) || matchBlock(pos,Blocks.BEDROCK);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import net.minecraft.item.ItemStack;
import net.minecraft.util.Hand;

import java.util.function.BiConsumer;
import java.util.function.Consumer;

import static io.github.itzispyder.clickcrystals.ClickCrystals.mc;

/**
Expand Down Expand Up @@ -79,4 +82,31 @@ public static boolean nameContains(String contains, Hand hand) {
ItemStack item = mc.player.getStackInHand(hand);
return item != null && item.getTranslationKey().toLowerCase().contains(contains.toLowerCase());
}

public static void forEachItem(Consumer<ItemStack> run) {
for (int i = 0; i < 9; i ++) {
ItemStack item = mc.player.getInventory().getStack(i);
if (item == null) continue;
if (item.isEmpty()) continue;
run.accept(item);
}
}

public static void forEachItem(BiConsumer<Integer,ItemStack> run) {
for (int i = 0; i < 9; i ++) {
ItemStack item = mc.player.getInventory().getStack(i);
if (item == null) continue;
if (item.isEmpty()) continue;
run.accept(i,item);
}
}

public static ItemStack[] getContents() {
PlayerInventory inv = mc.player.getInventory();
ItemStack[] stacks = new ItemStack[]{};
for (int i = 0; i < 9; i++) {
stacks[i] = inv.getStack(i);
}
return stacks;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package io.github.itzispyder.clickcrystals.util;

import net.minecraft.enchantment.Enchantment;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtList;
import net.minecraft.registry.Registries;
import net.minecraft.util.Identifier;

public abstract class NbtUtils {

public static int getEnchantLvL(ItemStack stack, Enchantment enchant) {
NbtList list = stack.getEnchantments();
for (int i = 0; i < list.size(); i++) {
try {
NbtCompound nbt = list.getCompound(i);
Identifier id = Identifier.tryParse(nbt.getString("id"));
Identifier id2 = Registries.ENCHANTMENT.getId(enchant);
if (id.toTranslationKey().equalsIgnoreCase(id2.toTranslationKey())) {
return nbt.getInt("lvl");
}
}
catch (Exception ignore) {}
}
return 0;
}
}

0 comments on commit e8a7bfd

Please sign in to comment.