HTTPS
https://git.nageyqma.icu/nageyqma/blade-addons-next.git
SSH
git@git.nageyqma.icu:nageyqma/blade-addons-next.git
HTTPS 链接可直接 git clone;推送代码请使用 SSH。
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
package blade.addon.utils;
import blade.addon.features.item.ItemRarityHighlight;
import blade.addon.utils.config.Config;
import com.mojang.authlib.GameProfile;
import com.mojang.blaze3d.platform.InputConstants;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.keymapping.v1.KeyMappingHelper;
import net.minecraft.client.KeyMapping;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.core.BlockPos;
import net.minecraft.core.component.DataComponents;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.Identifier;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.component.CustomData;
import net.minecraft.world.item.component.ItemLore;
import net.minecraft.world.item.component.ResolvableProfile;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.SkullBlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.HitResult;
import java.util.List;
public class Keybinds {
private static KeyMapping openConfig;
private static KeyMapping trades;
private static KeyMapping potions;
private static KeyMapping getItemLore;
private static KeyMapping getItemCustomData;
private static KeyMapping getBlockInfo;
public static void init() {
KeyMapping.Category category = KeyMapping.Category.register(Identifier.parse(Constants.NAMESPACE));
//normal keybinds
openConfig = KeyMappingHelper.registerKeyMapping(new KeyMapping(
"opens Config",
InputConstants.Type.KEYBOARD,
InputConstants.KEY_RSHIFT,
category));
trades = KeyMappingHelper.registerKeyMapping(new KeyMapping(
"Opens the trades menu",
InputConstants.Type.KEYBOARD,
InputConstants.UNKNOWN.getValue(),
category));
potions = KeyMappingHelper.registerKeyMapping(new KeyMapping(
"Opens the potion bag",
InputConstants.Type.KEYBOARD,
InputConstants.UNKNOWN.getValue(),
category));
//debug keybinds
getItemLore = KeyMappingHelper.registerKeyMapping(new KeyMapping(
"Grabs the items lore",
InputConstants.Type.KEYBOARD,
InputConstants.UNKNOWN.getValue(),
category));
getItemCustomData = KeyMappingHelper.registerKeyMapping(new KeyMapping(
"Grabs the items custom data",
InputConstants.Type.KEYBOARD,
InputConstants.UNKNOWN.getValue(),
category));
getBlockInfo = KeyMappingHelper.registerKeyMapping(new KeyMapping(
"Grabs the blocks data",
InputConstants.Type.KEYBOARD,
InputConstants.UNKNOWN.getValue(),
category));
ClientTickEvents.END_CLIENT_TICK.register(Keybinds::checkInputs);
}
public static void checkInputs(Minecraft client) {
if (openConfig.consumeClick()) {
client.gui.setScreen(Config.createScreen(null));
}
if (trades.consumeClick()) {
Misc.executeCommand("trades");
}
if (potions.consumeClick()) {
Misc.executeCommand("potionbag");
}
if (getItemLore.consumeClick()) {
LocalPlayer player = client.player;
if (player == null) {
Misc.addChatMessage(Component.literal("player is null"));
return;
}
ItemStack heldStack = player.getMainHandItem();
ItemLore lore = heldStack.get(DataComponents.LORE);
if (lore == null) {
Misc.addChatMessage(Component.literal("lore is null"));
return;
}
List<Component> lines = lore.lines();
for (Component line : lines) {
Misc.addChatMessage(line);
}
Misc.addChatMessage(Component.literal("Rarity: " + ItemRarityHighlight.getRarity(heldStack).name()));
}
if (getItemCustomData.consumeClick()) {
LocalPlayer player = client.player;
if (player == null) {
Misc.addChatMessage(Component.literal("player is null"));
return;
}
ItemStack heldStack = player.getMainHandItem();
CustomData nbt = heldStack.get(DataComponents.CUSTOM_DATA);
if (nbt == null) {
Misc.addChatMessage(Component.literal("nbt is null"));
return;
}
Misc.addChatMessage(Component.literal(nbt.toString()));
}
if (getBlockInfo.consumeClick()) {
LocalPlayer player = client.player;
ClientLevel world = client.level;
if (player == null || world == null) {
Misc.addChatMessage(Component.literal("player or world is null"));
return;
}
HitResult result = player.pick(4, client.getDeltaTracker().getGameTimeDeltaPartialTick(false), true);
if (result instanceof BlockHitResult blockHitResult) {
BlockPos pos = blockHitResult.getBlockPos();
BlockState state = world.getBlockState(pos);
Misc.addChatMessage(Component.literal("Pos: " + pos));
if (state.hasBlockEntity()) {
BlockEntity entity = world.getBlockEntity(pos);
Misc.addChatMessage(Component.literal(entity.toString()));
if (entity instanceof SkullBlockEntity skullEntity) {
ResolvableProfile component = skullEntity.getOwnerProfile();
if (component != null) {
GameProfile profile = component.partialProfile();
Misc.addChatMessage(Component.literal("name: " + profile.name() + " id: " + profile.id()));
}
}
}
}
//wither essence uuid
//e0f3e929-869e-3dca-9504-54c666ee6f23
}
}
}