port to 26.1.2

This commit is contained in:
seb
2026-04-26 02:40:37 +02:00
parent a70b972c0d
commit b8129ee32a
7 changed files with 205 additions and 224 deletions

1
.gitignore vendored
View File

@@ -1,2 +1,3 @@
.gradle .gradle
build/ build/
.jdk21/

View File

@@ -1,16 +1,27 @@
plugins { plugins {
id 'fabric-loom' version '1.11-SNAPSHOT' id 'net.fabricmc.fabric-loom' version '1.16-SNAPSHOT'
id 'com.diffplug.spotless' version '6.19.0' id 'com.diffplug.spotless' version '6.19.0'
id "com.modrinth.minotaur" version "2.+" id "com.modrinth.minotaur" version "2.+"
} }
java { java {
sourceCompatibility = JavaVersion.VERSION_21 toolchain {
targetCompatibility = JavaVersion.VERSION_21 languageVersion = JavaLanguageVersion.of(25)
}
} }
repositories { repositories {
maven { url 'https://masa.dy.fi/maven' } exclusiveContent {
forRepository {
maven {
name = 'Modrinth'
url = 'https://api.modrinth.com/maven'
}
}
filter {
includeGroup 'maven.modrinth'
}
}
maven { url 'https://maven.terraformersmc.com/releases/' } maven { url 'https://maven.terraformersmc.com/releases/' }
maven { url 'https://jitpack.io' } maven { url 'https://jitpack.io' }
flatDir { flatDir {
@@ -20,10 +31,9 @@ repositories {
dependencies { dependencies {
minecraft "com.mojang:minecraft:${project.minecraft_version}" minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.mappings_version}:v2" implementation "net.fabricmc:fabric-loader:${project.fabric_loader_version}"
modImplementation "net.fabricmc:fabric-loader:${project.fabric_loader_version}" implementation "maven.modrinth:malilib:${project.malilib_version}"
modImplementation "fi.dy.masa.malilib:malilib-fabric-${project.minecraft_version_out}:${project.malilib_version}" compileOnly "com.terraformersmc:modmenu:${project.mod_menu_version}"
modCompileOnly "com.terraformersmc:modmenu:${project.mod_menu_version}"
} }
group = project.group + "." + project.mod_id group = project.group + "." + project.mod_id
@@ -50,7 +60,6 @@ processResources {
tasks.withType(JavaCompile).configureEach { tasks.withType(JavaCompile).configureEach {
it.options.encoding = "UTF-8" it.options.encoding = "UTF-8"
it.options.release = 21
} }
spotless { spotless {
@@ -63,13 +72,13 @@ spotless {
} }
} }
import com.modrinth.minotaur.dependencies.ModDependency
modrinth { modrinth {
token = System.getenv("MODRINTH_TOKEN") token = System.getenv("MODRINTH_TOKEN")
syncBodyFrom = rootProject.file("README.md").text syncBodyFrom = rootProject.file("README.md").text
projectId = 'C1naQCmt' projectId = 'C1naQCmt'
uploadFile = remapJar // Loom 1.16+ with net.fabricmc.fabric-loom (unobfuscated MC) does not create remapJar; ship the standard jar
gameVersions = ['1.21.11'] uploadFile = tasks.jar
gameVersions = ['26.1.2']
loaders = ['fabric'] loaders = ['fabric']
dependencies = [] dependencies = []
} }

View File

@@ -1,5 +1,7 @@
# Done to increase the memory available to gradle. # Done to increase the memory available to gradle.
org.gradle.jvmargs=-Xmx1G org.gradle.jvmargs=-Xmx1G
org.gradle.parallel=true
org.gradle.configuration-cache=false
group = com.github.sebseb7 group = com.github.sebseb7
mod_id = autotrade mod_id = autotrade
@@ -7,14 +9,13 @@ mod_name = AutoTrade
author = sebseb7 author = sebseb7
mod_file_name = autotrade-fabric mod_file_name = autotrade-fabric
mod_version = 0.0.11 mod_version = 0.0.12
malilib_version = 0.21.0 malilib_version = 0.28.2
minecraft_version_min = 1.21.11 minecraft_version_min = 26.1.2
minecraft_version_out = 1.21.1 minecraft_version_out = 26.1.2
minecraft_version = 1.21.11 minecraft_version = 26.1.2
mappings_version = 1.21.11+build.2 fabric_loader_version = 0.19.2
fabric_loader_version = 0.16.10 mod_menu_version = 18.0.0-alpha.8
mod_menu_version = 15.0.0

View File

@@ -1,5 +1,7 @@
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip distributionUrl=https\://services.gradle.org/distributions/gradle-9.4.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists

View File

@@ -4,6 +4,14 @@ pluginManagement {
name = 'Fabric' name = 'Fabric'
url = 'https://maven.fabricmc.net/' url = 'https://maven.fabricmc.net/'
} }
mavenCentral()
gradlePluginPortal() gradlePluginPortal()
} }
} }
// Lets Gradle 21 run the build while a JDK 25 toolchain is used to compile (required by 26.1 Mod Menu, etc.)
plugins {
id 'org.gradle.toolchains.foojay-resolver-convention' version '1.0.0'
}
rootProject.name = 'autotrade-fabric'

View File

@@ -68,7 +68,7 @@ public class Configs implements IConfigHandler {
File configFile = new File(getConfigDirectory(), CONFIG_FILE_NAME); File configFile = new File(getConfigDirectory(), CONFIG_FILE_NAME);
if (configFile.exists() && configFile.isFile() && configFile.canRead()) { if (configFile.exists() && configFile.isFile() && configFile.canRead()) {
JsonElement element = JsonUtils.parseJsonFile(configFile); JsonElement element = JsonUtils.parseJsonFile(configFile.toPath());
if (element != null && element.isJsonObject()) { if (element != null && element.isJsonObject()) {
JsonObject root = element.getAsJsonObject(); JsonObject root = element.getAsJsonObject();
@@ -88,7 +88,7 @@ public class Configs implements IConfigHandler {
ConfigUtils.writeConfigBase(root, "Generic", Generic.OPTIONS); ConfigUtils.writeConfigBase(root, "Generic", Generic.OPTIONS);
ConfigUtils.writeConfigBase(root, "Hotkeys", Hotkeys.HOTKEY_LIST); ConfigUtils.writeConfigBase(root, "Hotkeys", Hotkeys.HOTKEY_LIST);
JsonUtils.writeJsonToFile(root, new File(dir, CONFIG_FILE_NAME)); JsonUtils.writeJsonToFile(root, new File(dir, CONFIG_FILE_NAME).toPath());
} }
} }

View File

@@ -14,40 +14,41 @@ import fi.dy.masa.malilib.interfaces.IClientTickHandler;
import fi.dy.masa.malilib.util.GuiUtils; import fi.dy.masa.malilib.util.GuiUtils;
import fi.dy.masa.malilib.util.InfoUtils; import fi.dy.masa.malilib.util.InfoUtils;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Vector; import java.util.Vector;
import net.minecraft.block.Blocks; import net.minecraft.client.Minecraft;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.screens.inventory.ContainerScreen;
import net.minecraft.client.gui.screen.ingame.GenericContainerScreen; import net.minecraft.client.gui.screens.inventory.MerchantScreen;
import net.minecraft.client.gui.screen.ingame.MerchantScreen; import net.minecraft.client.gui.screens.inventory.ShulkerBoxScreen;
import net.minecraft.client.gui.screen.ingame.ShulkerBoxScreen; import net.minecraft.core.BlockPos;
import net.minecraft.entity.Entity; import net.minecraft.core.Direction;
import net.minecraft.entity.decoration.ItemFrameEntity; import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.entity.passive.VillagerEntity; import net.minecraft.network.protocol.game.ServerboundSelectTradePacket;
import net.minecraft.entity.passive.WanderingTraderEntity; import net.minecraft.world.InteractionHand;
import net.minecraft.entity.player.PlayerInventory; import net.minecraft.world.entity.Entity;
import net.minecraft.item.ItemStack; import net.minecraft.world.entity.decoration.ItemFrame;
import net.minecraft.network.packet.c2s.play.SelectMerchantTradeC2SPacket; import net.minecraft.world.entity.npc.villager.Villager;
import net.minecraft.predicate.entity.EntityPredicates; import net.minecraft.world.entity.npc.wanderingtrader.WanderingTrader;
import net.minecraft.registry.Registries; import net.minecraft.world.entity.player.Inventory;
import net.minecraft.screen.GenericContainerScreenHandler; import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.screen.MerchantScreenHandler; import net.minecraft.world.inventory.ContainerInput;
import net.minecraft.screen.ScreenHandler; import net.minecraft.world.inventory.MerchantMenu;
import net.minecraft.screen.ShulkerBoxScreenHandler; import net.minecraft.world.inventory.ShulkerBoxMenu;
import net.minecraft.screen.slot.Slot; import net.minecraft.world.inventory.Slot;
import net.minecraft.screen.slot.SlotActionType; import net.minecraft.world.item.ItemStack;
import net.minecraft.util.Hand; import net.minecraft.world.item.trading.MerchantOffer;
import net.minecraft.util.hit.BlockHitResult; import net.minecraft.world.item.trading.MerchantOffers;
import net.minecraft.util.hit.HitResult; import net.minecraft.world.level.block.Blocks;
import net.minecraft.util.math.BlockPos; import net.minecraft.world.phys.AABB;
import net.minecraft.util.math.Box; import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.util.math.Direction; import net.minecraft.world.phys.EntityHitResult;
import net.minecraft.village.TradeOffer; import net.minecraft.world.phys.HitResult;
import net.minecraft.village.TradeOfferList; import net.minecraft.world.phys.Vec3;
public class KeybindCallbacks implements IHotkeyCallback, IClientTickHandler { public class KeybindCallbacks implements IHotkeyCallback, IClientTickHandler {
private static final KeybindCallbacks INSTANCE = new KeybindCallbacks(); private static final KeybindCallbacks INSTANCE = new KeybindCallbacks();
private Vector<Entity> villagersInRange = new Vector<Entity>(); private Vector<Entity> villagersInRange = new Vector<>();
private int villagerActive = 0; private int villagerActive = 0;
private boolean state = false; private boolean state = false;
@@ -78,80 +79,78 @@ public class KeybindCallbacks implements IHotkeyCallback, IClientTickHandler {
@Override @Override
public boolean onKeyAction(KeyAction action, IKeybind key) { public boolean onKeyAction(KeyAction action, IKeybind key) {
boolean cancel = this.onKeyActionImpl(action, key); return this.onKeyActionImpl(action, key);
return cancel;
} }
private void processOutput(ScreenHandler handler) { private static String id(net.minecraft.world.item.Item item) {
outputOpened = false; return BuiltInRegistries.ITEM.getKey(item).toString();
}
private void quickMoveResultSlot(Minecraft mc, AbstractContainerMenu menu, int slotIndex) {
Slot slot = menu.getSlot(slotIndex);
mc.gameMode.handleContainerInput(menu.containerId, slot.index, 0, ContainerInput.QUICK_MOVE, mc.player);
}
private void processOutput(AbstractContainerMenu menu, Inventory playerInv) {
outputOpened = false;
String itemToPlace = "minecraft:emerald"; String itemToPlace = "minecraft:emerald";
if (Configs.Generic.ENABLE_BUY.getBooleanValue()) { if (Configs.Generic.ENABLE_BUY.getBooleanValue()) {
itemToPlace = Configs.Generic.BUY_ITEM.getStringValue(); itemToPlace = Configs.Generic.BUY_ITEM.getStringValue();
} }
Minecraft mc = Minecraft.getInstance();
for (int i = 0; i < handler.slots.size(); i++) { for (int i = 0; i < menu.slots.size(); i++) {
if (handler.getSlot(i).inventory instanceof PlayerInventory) { Slot s = menu.getSlot(i);
if (Registries.ITEM.getId(handler.getSlot(i).getStack().getItem()).toString().equals(itemToPlace)) { if (s.container == playerInv) {
if (id(s.getItem().getItem()).equals(itemToPlace)) {
try { try {
MinecraftClient.getInstance().interactionManager.clickSlot(handler.syncId, quickMoveResultSlot(mc, menu, i);
handler.getSlot(i).id, 0, SlotActionType.QUICK_MOVE,
MinecraftClient.getInstance().player);
} catch (Exception e) { } catch (Exception e) {
System.out.println("err " + e.toString()); System.out.println("err " + e);
} }
} }
} }
} }
} }
private void processInput(ScreenHandler handler) { private void processInput(AbstractContainerMenu menu, Inventory playerInv) {
inputOpened = false; inputOpened = false;
HashMap<String, Integer> inventory = new HashMap<>();
HashMap<String, Integer> inventory = new HashMap<String, Integer>(); for (int i = 0; i < menu.slots.size(); i++) {
Slot s = menu.getSlot(i);
for (int i = 0; i < handler.slots.size(); i++) { if (s.container == playerInv) {
if (handler.getSlot(i).inventory instanceof PlayerInventory) { String k = id(s.getItem().getItem());
inventory.put(Registries.ITEM.getId(handler.getSlot(i).getStack().getItem()).toString(), inventory.put(k, s.getItem().getCount() + inventory.getOrDefault(k, 0));
handler.getSlot(i).getStack().getCount() + inventory.getOrDefault(
Registries.ITEM.getId(handler.getSlot(i).getStack().getItem()).toString(), 0));
} }
} }
String itemToTake = "minecraft:emerald"; String itemToTake = "minecraft:emerald";
if (Configs.Generic.ENABLE_SELL.getBooleanValue()) { if (Configs.Generic.ENABLE_SELL.getBooleanValue()) {
itemToTake = Configs.Generic.SELL_ITEM.getStringValue(); itemToTake = Configs.Generic.SELL_ITEM.getStringValue();
} }
int inputCount = inventory.getOrDefault(itemToTake, 0); int inputCount = inventory.getOrDefault(itemToTake, 0);
Minecraft mc = Minecraft.getInstance();
for (int i = 0; i < handler.slots.size(); i++) { for (int i = 0; i < menu.slots.size(); i++) {
if ((handler.getSlot(i).inventory instanceof PlayerInventory) == false) { Slot s = menu.getSlot(i);
if (Registries.ITEM.getId(handler.getSlot(i).getStack().getItem()).toString().equals(itemToTake)) { if (s.container == playerInv) {
if (inputCount < (Configs.Generic.MAX_INPUT_ITEMS.getIntegerValue() * 64)) { continue;
inputCount += handler.getSlot(i).getStack().getCount(); }
try { if (id(s.getItem().getItem()).equals(itemToTake)) {
MinecraftClient.getInstance().interactionManager.clickSlot(handler.syncId, if (inputCount < (Configs.Generic.MAX_INPUT_ITEMS.getIntegerValue() * 64)) {
handler.getSlot(i).id, 0, SlotActionType.QUICK_MOVE, inputCount += s.getItem().getCount();
MinecraftClient.getInstance().player); try {
} catch (Exception e) { quickMoveResultSlot(mc, menu, i);
System.out.println("err " + e.toString()); } catch (Exception e) {
} System.out.println("err " + e);
} }
} }
} }
} }
} }
private boolean onKeyActionImpl(KeyAction action, IKeybind key) { private boolean onKeyActionImpl(KeyAction action, IKeybind key) {
MinecraftClient mc = MinecraftClient.getInstance(); Minecraft mc = Minecraft.getInstance();
if (mc.player == null || mc.level == null) {
if (mc.player == null || mc.world == null) {
return false; return false;
} }
if (key == Hotkeys.TOGGLE_KEY.getKeybind()) { if (key == Hotkeys.TOGGLE_KEY.getKeybind()) {
Configs.Generic.ENABLED.toggleBooleanValue(); Configs.Generic.ENABLED.toggleBooleanValue();
String msg = this.functionalityEnabled() String msg = this.functionalityEnabled()
@@ -167,85 +166,75 @@ public class KeybindCallbacks implements IHotkeyCallback, IClientTickHandler {
GuiBase.openGui(new GuiConfigs()); GuiBase.openGui(new GuiConfigs());
return true; return true;
} else if (key == Hotkeys.SET_INPUT_KEY.getKeybind()) { } else if (key == Hotkeys.SET_INPUT_KEY.getKeybind()) {
HitResult result = mc.player.raycast(20.0D, 0.0F, false); HitResult result = mc.player.pick(20.0D, 0.0F, false);
if (result.getType() == HitResult.Type.BLOCK) { if (result.getType() == HitResult.Type.BLOCK) {
BlockHitResult blockHit = (BlockHitResult) result; BlockHitResult blockHit = (BlockHitResult) result;
Configs.Generic.INPUT_CONTAINER_X.setIntegerValue(blockHit.getBlockPos().getX()); BlockPos p = blockHit.getBlockPos();
Configs.Generic.INPUT_CONTAINER_Y.setIntegerValue(blockHit.getBlockPos().getY()); Configs.Generic.INPUT_CONTAINER_X.setIntegerValue(p.getX());
Configs.Generic.INPUT_CONTAINER_Z.setIntegerValue(blockHit.getBlockPos().getZ()); Configs.Generic.INPUT_CONTAINER_Y.setIntegerValue(p.getY());
Configs.Generic.INPUT_CONTAINER_Z.setIntegerValue(p.getZ());
InfoUtils.showGuiOrInGameMessage(Message.MessageType.INFO, "autotrade.message.input_container_set", InfoUtils.showGuiOrInGameMessage(Message.MessageType.INFO, "autotrade.message.input_container_set",
blockHit.getBlockPos().getX(), blockHit.getBlockPos().getY(), blockHit.getBlockPos().getZ()); p.getX(), p.getY(), p.getZ());
} }
} else if (key == Hotkeys.SET_OUTPUT_KEY.getKeybind()) { } else if (key == Hotkeys.SET_OUTPUT_KEY.getKeybind()) {
HitResult result = mc.player.raycast(20.0D, 0.0F, false); HitResult result = mc.player.pick(20.0D, 0.0F, false);
if (result.getType() == HitResult.Type.BLOCK) { if (result.getType() == HitResult.Type.BLOCK) {
BlockHitResult blockHit = (BlockHitResult) result; BlockHitResult blockHit = (BlockHitResult) result;
Configs.Generic.OUTPUT_CONTAINER_X.setIntegerValue(blockHit.getBlockPos().getX()); BlockPos p = blockHit.getBlockPos();
Configs.Generic.OUTPUT_CONTAINER_Y.setIntegerValue(blockHit.getBlockPos().getY()); Configs.Generic.OUTPUT_CONTAINER_X.setIntegerValue(p.getX());
Configs.Generic.OUTPUT_CONTAINER_Z.setIntegerValue(blockHit.getBlockPos().getZ()); Configs.Generic.OUTPUT_CONTAINER_Y.setIntegerValue(p.getY());
Configs.Generic.OUTPUT_CONTAINER_Z.setIntegerValue(p.getZ());
InfoUtils.showGuiOrInGameMessage(Message.MessageType.INFO, "autotrade.message.output_container_set", InfoUtils.showGuiOrInGameMessage(Message.MessageType.INFO, "autotrade.message.output_container_set",
blockHit.getBlockPos().getX(), blockHit.getBlockPos().getY(), blockHit.getBlockPos().getZ()); p.getX(), p.getY(), p.getZ());
} }
} else if (key == Hotkeys.SET_BUY_KEY.getKeybind()) { } else if (key == Hotkeys.SET_BUY_KEY.getKeybind()) {
String buyItem = Registries.ITEM.getId(mc.player.getMainHandStack().getItem()).toString(); String buyItem = id(mc.player.getItemInHand(InteractionHand.MAIN_HAND).getItem());
InfoUtils.showGuiOrInGameMessage(Message.MessageType.INFO, "autotrade.message.buy_item_set", buyItem); InfoUtils.showGuiOrInGameMessage(Message.MessageType.INFO, "autotrade.message.buy_item_set", buyItem);
Configs.Generic.BUY_ITEM.setValueFromString(buyItem); Configs.Generic.BUY_ITEM.setValueFromString(buyItem);
} else if (key == Hotkeys.SET_SELL_KEY.getKeybind()) { } else if (key == Hotkeys.SET_SELL_KEY.getKeybind()) {
String sellItem = Registries.ITEM.getId(mc.player.getMainHandStack().getItem()).toString(); String sellItem = id(mc.player.getItemInHand(InteractionHand.MAIN_HAND).getItem());
InfoUtils.showGuiOrInGameMessage(Message.MessageType.INFO, "autotrade.message.sell_item_set", sellItem); InfoUtils.showGuiOrInGameMessage(Message.MessageType.INFO, "autotrade.message.sell_item_set", sellItem);
Configs.Generic.SELL_ITEM.setValueFromString(sellItem); Configs.Generic.SELL_ITEM.setValueFromString(sellItem);
} }
return false; return false;
} }
@Override @Override
public void onClientTick(MinecraftClient mc) { public void onClientTick(Minecraft mc) {
if (voidDelay > 0) { if (voidDelay > 0) {
if (Configs.Generic.VOID_TRADING_DELAY_AFTER_TELEPORT.getBooleanValue()) { if (Configs.Generic.VOID_TRADING_DELAY_AFTER_TELEPORT.getBooleanValue()) {
boolean found = false; boolean found = false;
for (Entity entity : mc.world.getEntities()) { for (Entity entity : mc.level.entitiesForRendering()) {
if (entity.getId() == villagerActive) { if (entity.getId() == villagerActive) {
found = true; found = true;
} }
} }
if (!found) { if (!found) {
voidDelay--; voidDelay--;
} }
} else { } else {
voidDelay--; voidDelay--;
} }
return; return;
} }
if (containerDelay > 0) { if (containerDelay > 0) {
containerDelay--; containerDelay--;
} }
if (this.functionalityEnabled() == false || mc.player == null) { if (this.functionalityEnabled() == false || mc.player == null) {
return; return;
} }
Inventory plInv = mc.player.getInventory();
if (Configs.Generic.GLASS_BLOCK.getBooleanValue()) { if (Configs.Generic.GLASS_BLOCK.getBooleanValue()) {
int playerX = (int) mc.player.getX(); int playerX = (int) mc.player.getX();
int playerZ = (int) mc.player.getZ(); int playerZ = (int) mc.player.getZ();
int playerY = (int) mc.player.getY(); int playerY = (int) mc.player.getY();
int selectorOffset = Configs.Generic.SELECTOR_OFFSET.getIntegerValue(); int selectorOffset = Configs.Generic.SELECTOR_OFFSET.getIntegerValue();
int absSelectorOffset = Math.abs(selectorOffset); int absSelectorOffset = Math.abs(selectorOffset);
for (int x = playerX - (absSelectorOffset + 3); x < playerX + (absSelectorOffset + 3); x += 1) { for (int x = playerX - (absSelectorOffset + 3); x < playerX + (absSelectorOffset + 3); x += 1) {
for (int z = playerZ - (absSelectorOffset + 3); z < playerZ + (absSelectorOffset + 3); z += 1) { for (int z = playerZ - (absSelectorOffset + 3); z < playerZ + (absSelectorOffset + 3); z += 1) {
for (int y = playerY - (absSelectorOffset + 3); y < playerY + (absSelectorOffset + 3); y += 1) { for (int y = playerY - (absSelectorOffset + 3); y < playerY + (absSelectorOffset + 3); y += 1) {
BlockPos pos = new BlockPos(x, y, z); BlockPos pos = new BlockPos(x, y, z);
if (mc.world.getBlockState(pos).isOf(Blocks.RED_STAINED_GLASS)) { if (mc.level.getBlockState(pos).getBlock() == Blocks.RED_STAINED_GLASS) {
if ((x != Configs.Generic.INPUT_CONTAINER_X.getIntegerValue()) if ((x != Configs.Generic.INPUT_CONTAINER_X.getIntegerValue())
|| ((y - selectorOffset) != Configs.Generic.INPUT_CONTAINER_Y.getIntegerValue()) || ((y - selectorOffset) != Configs.Generic.INPUT_CONTAINER_Y.getIntegerValue())
|| (z != Configs.Generic.INPUT_CONTAINER_Z.getIntegerValue())) { || (z != Configs.Generic.INPUT_CONTAINER_Z.getIntegerValue())) {
@@ -257,7 +246,7 @@ public class KeybindCallbacks implements IHotkeyCallback, IClientTickHandler {
} }
break; break;
} }
if (mc.world.getBlockState(pos).isOf(Blocks.BLUE_STAINED_GLASS)) { if (mc.level.getBlockState(pos).getBlock() == Blocks.BLUE_STAINED_GLASS) {
if ((x != Configs.Generic.OUTPUT_CONTAINER_X.getIntegerValue()) if ((x != Configs.Generic.OUTPUT_CONTAINER_X.getIntegerValue())
|| ((y - selectorOffset) != Configs.Generic.OUTPUT_CONTAINER_Y.getIntegerValue()) || ((y - selectorOffset) != Configs.Generic.OUTPUT_CONTAINER_Y.getIntegerValue())
|| (z != Configs.Generic.OUTPUT_CONTAINER_Z.getIntegerValue())) { || (z != Configs.Generic.OUTPUT_CONTAINER_Z.getIntegerValue())) {
@@ -273,17 +262,17 @@ public class KeybindCallbacks implements IHotkeyCallback, IClientTickHandler {
} }
} }
} }
if (Configs.Generic.ITEM_FRAME.getBooleanValue()) { if (Configs.Generic.ITEM_FRAME.getBooleanValue()) {
Vec3 pm = new Vec3(mc.player.getX(), mc.player.getY(), mc.player.getZ());
for (ItemFrameEntity entity : mc.world.getEntitiesByClass( AABB box = new AABB(pm.subtract(3, 3, 3), pm.add(3, 3, 3));
ItemFrameEntity.class, new Box(mc.player.getX() - 3, mc.player.getY() - 3, mc.player.getZ() - 3, @SuppressWarnings("unchecked")
mc.player.getX() + 3, mc.player.getY() + 3, mc.player.getZ() + 3), List<ItemFrame> frames = (List<ItemFrame>) (List<?>) mc.level.getEntities((Entity) null, box,
EntityPredicates.VALID_ENTITY)) { e -> e instanceof ItemFrame && e.isAlive());
ItemStack stack = entity.getHeldItemStack(); for (ItemFrame entity : frames) {
String customName = stack.getName().getString(); ItemStack stack = entity.getItem();
String customName = stack.getHoverName().getString();
if ("sell".equalsIgnoreCase(customName) || "\"sell\"".equals(customName)) { if ("sell".equalsIgnoreCase(customName) || "\"sell\"".equals(customName)) {
String sellItem = Registries.ITEM.getId(stack.getItem()).toString(); String sellItem = id(stack.getItem());
if (!Configs.Generic.SELL_ITEM.getStringValue().equals(sellItem)) { if (!Configs.Generic.SELL_ITEM.getStringValue().equals(sellItem)) {
InfoUtils.showGuiOrInGameMessage(Message.MessageType.INFO, "autotrade.message.sell_item_set", InfoUtils.showGuiOrInGameMessage(Message.MessageType.INFO, "autotrade.message.sell_item_set",
sellItem); sellItem);
@@ -292,7 +281,7 @@ public class KeybindCallbacks implements IHotkeyCallback, IClientTickHandler {
} }
} }
if ("buy".equalsIgnoreCase(customName) || "\"buy\"".equals(customName)) { if ("buy".equalsIgnoreCase(customName) || "\"buy\"".equals(customName)) {
String buyItem = Registries.ITEM.getId(stack.getItem()).toString(); String buyItem = id(stack.getItem());
if (!Configs.Generic.BUY_ITEM.getStringValue().equals(buyItem)) { if (!Configs.Generic.BUY_ITEM.getStringValue().equals(buyItem)) {
InfoUtils.showGuiOrInGameMessage(Message.MessageType.INFO, "autotrade.message.buy_item_set", InfoUtils.showGuiOrInGameMessage(Message.MessageType.INFO, "autotrade.message.buy_item_set",
buyItem); buyItem);
@@ -300,106 +289,84 @@ public class KeybindCallbacks implements IHotkeyCallback, IClientTickHandler {
break; break;
} }
} }
} }
} }
if (GuiUtils.getCurrentScreen() instanceof MerchantScreen screen) {
if (GuiUtils.getCurrentScreen() instanceof MerchantScreen) { if (!state) {
MerchantScreen screen = (MerchantScreen) GuiUtils.getCurrentScreen();
if (state == false) {
String sellItemStr = Configs.Generic.SELL_ITEM.getStringValue(); String sellItemStr = Configs.Generic.SELL_ITEM.getStringValue();
String buyItemStr = Configs.Generic.BUY_ITEM.getStringValue(); String buyItemStr = Configs.Generic.BUY_ITEM.getStringValue();
state = true; state = true;
MerchantScreenHandler handler = screen.getScreenHandler(); MerchantMenu menu = screen.getMenu();
TradeOfferList offers = handler.getRecipes(); MerchantOffers offers = menu.getOffers();
for (int i = 0; i < offers.size(); i++) { for (int i = 0; i < offers.size(); i++) {
TradeOffer offer = offers.get(i); MerchantOffer offer = offers.get(i);
ItemStack sellItem = offer.getSellItem(); String costA = id(offer.getCostA().getItem());
ItemStack buyItem = offer.getDisplayedFirstBuyItem(); String resultI = id(offer.getResult().getItem());
String sellId = Registries.ITEM.getId(sellItem.getItem()).toString(); // buying from villager: configured buy item matches the trade result
String buyId = Registries.ITEM.getId(buyItem.getItem()).toString(); if (resultI.equals(buyItemStr) && Configs.Generic.ENABLE_BUY.getBooleanValue()
&& offer.getResult().getCount() <= Configs.Generic.BUY_LIMIT.getIntegerValue()) {
if (sellId.equals(buyItemStr) && Configs.Generic.ENABLE_BUY.getBooleanValue() Slot slot = menu.getSlot(2);
&& buyItem.getCount() <= Configs.Generic.BUY_LIMIT.getIntegerValue()) { menu.setSelectionHint(i);
Slot slot = handler.getSlot(2); mc.player.connection.send(new ServerboundSelectTradePacket(i));
handler.switchTo(i);
handler.setRecipeIndex(i);
mc.getNetworkHandler().sendPacket(new SelectMerchantTradeC2SPacket(i));
AutoTrade.bought += offer.getMaxUses(); AutoTrade.bought += offer.getMaxUses();
try { try {
/* quickMoveResultSlot(mc, menu, slot.index);
* if (slot.hasStack()) { System.out.println("buy " +
* slot.getStack().getCount()); }
*/
mc.interactionManager.clickSlot(handler.syncId, slot.id, 0, SlotActionType.QUICK_MOVE,
mc.player);
} catch (Exception e) { } catch (Exception e) {
System.out.println("err " + e.toString()); System.out.println("err " + e);
} }
} }
if (buyId.equals(sellItemStr) && Configs.Generic.ENABLE_SELL.getBooleanValue() // "sell" to villager: cost matches configured sell list
&& buyItem.getCount() <= Configs.Generic.SELL_LIMIT.getIntegerValue()) { if (costA.equals(sellItemStr) && Configs.Generic.ENABLE_SELL.getBooleanValue()
Slot slot = handler.getSlot(2); && offer.getCostA().getCount() <= Configs.Generic.SELL_LIMIT.getIntegerValue()) {
handler.switchTo(i); Slot slot = menu.getSlot(2);
handler.setRecipeIndex(i); menu.setSelectionHint(i);
AutoTrade.sold += offer.getMaxUses(); AutoTrade.sold += offer.getMaxUses();
mc.getNetworkHandler().sendPacket(new SelectMerchantTradeC2SPacket(i)); mc.player.connection.send(new ServerboundSelectTradePacket(i));
try { try {
/* quickMoveResultSlot(mc, menu, slot.index);
* if (slot.hasStack()) { System.out.println("sell " +
* slot.getStack().getCount()); }
*/
mc.interactionManager.clickSlot(handler.syncId, slot.id, 0, SlotActionType.QUICK_MOVE,
mc.player);
} catch (Exception e) { } catch (Exception e) {
System.out.println("err " + e.toString()); System.out.println("err " + e);
} }
} }
} }
} }
screen.close(); screen.onClose();
inputInRange = false; inputInRange = false;
outputInRange = false; outputInRange = false;
return; return;
} }
if (GuiUtils.getCurrentScreen() instanceof ShulkerBoxScreen sbs) {
if (GuiUtils.getCurrentScreen() instanceof ShulkerBoxScreen) { ShulkerBoxMenu m = sbs.getMenu();
ShulkerBoxScreen screen = (ShulkerBoxScreen) GuiUtils.getCurrentScreen();
ShulkerBoxScreenHandler handler = screen.getScreenHandler();
if ((containerDelay == 0) && inputOpened) { if ((containerDelay == 0) && inputOpened) {
processInput(handler); processInput(m, plInv);
screen.close(); sbs.onClose();
} }
if ((containerDelay == 0) && outputOpened) { if ((containerDelay == 0) && outputOpened) {
processOutput(handler); processOutput(m, plInv);
screen.close(); sbs.onClose();
} }
} } else if (GuiUtils.getCurrentScreen() instanceof ContainerScreen cs) {
if (GuiUtils.getCurrentScreen() instanceof GenericContainerScreen) { AbstractContainerMenu m = cs.getMenu();
GenericContainerScreen screen = (GenericContainerScreen) GuiUtils.getCurrentScreen();
GenericContainerScreenHandler handler = screen.getScreenHandler();
if ((containerDelay == 0) && inputOpened) { if ((containerDelay == 0) && inputOpened) {
processInput(handler); processInput(m, plInv);
screen.close(); cs.onClose();
} }
if ((containerDelay == 0) && outputOpened) { if ((containerDelay == 0) && outputOpened) {
processOutput(handler); processOutput(m, plInv);
screen.close(); cs.onClose();
} }
} }
boolean found = false; boolean found = false;
Vector<Entity> newVillagersInRange = new Vector<>(villagersInRange);
Vector<Entity> newVillagersInRange = new Vector<Entity>(villagersInRange); for (Entity entity : mc.level.entitiesForRendering()) {
if (entity instanceof Villager || entity instanceof WanderingTrader) {
for (Entity entity : mc.world.getEntities()) { if (entity.distanceToSqr(mc.player) < (2.5f * 2.5f)) {
if (entity instanceof VillagerEntity || entity instanceof WanderingTraderEntity) { if (!found) {
if (entity.squaredDistanceTo(mc.player) < (2.5f * 2.5f)) { if (!newVillagersInRange.contains(entity)) {
if (found == false) {
if (newVillagersInRange.contains(entity) == false) {
found = true; found = true;
newVillagersInRange.add(entity); newVillagersInRange.add(entity);
mc.interactionManager.interactEntity(mc.player, entity, Hand.MAIN_HAND); EntityHitResult ehr = new EntityHitResult(entity, entity.position());
mc.gameMode.interact(mc.player, entity, ehr, InteractionHand.MAIN_HAND);
voidDelay = Configs.Generic.VOID_TRADING_DELAY.getIntegerValue(); voidDelay = Configs.Generic.VOID_TRADING_DELAY.getIntegerValue();
villagerActive = entity.getId(); villagerActive = entity.getId();
state = false; state = false;
@@ -409,9 +376,8 @@ public class KeybindCallbacks implements IHotkeyCallback, IClientTickHandler {
} }
} }
} }
for (Entity entity : villagersInRange) { for (Entity entity : villagersInRange) {
if ((entity.squaredDistanceTo(mc.player) < 16.0D) == false) { if (entity.distanceToSqr(mc.player) >= 16.0D) {
newVillagersInRange.remove(entity); newVillagersInRange.remove(entity);
} }
} }
@@ -419,57 +385,51 @@ public class KeybindCallbacks implements IHotkeyCallback, IClientTickHandler {
if (found) { if (found) {
return; return;
} }
BlockPos input = new BlockPos(Configs.Generic.INPUT_CONTAINER_X.getIntegerValue(), BlockPos input = new BlockPos(Configs.Generic.INPUT_CONTAINER_X.getIntegerValue(),
Configs.Generic.INPUT_CONTAINER_Y.getIntegerValue(), Configs.Generic.INPUT_CONTAINER_Y.getIntegerValue(),
Configs.Generic.INPUT_CONTAINER_Z.getIntegerValue()); Configs.Generic.INPUT_CONTAINER_Z.getIntegerValue());
BlockPos output = new BlockPos(Configs.Generic.OUTPUT_CONTAINER_X.getIntegerValue(), BlockPos output = new BlockPos(Configs.Generic.OUTPUT_CONTAINER_X.getIntegerValue(),
Configs.Generic.OUTPUT_CONTAINER_Y.getIntegerValue(), Configs.Generic.OUTPUT_CONTAINER_Y.getIntegerValue(),
Configs.Generic.OUTPUT_CONTAINER_Z.getIntegerValue()); Configs.Generic.OUTPUT_CONTAINER_Z.getIntegerValue());
Vec3 ic = input.getCenter();
if ((mc.player.squaredDistanceTo(input.toCenterPos()) < 16.0D) && (inputInRange == false)) { Vec3 oc = output.getCenter();
if ((mc.player.distanceToSqr(ic) < 16.0D) && (inputInRange == false)) {
inputInRange = true; inputInRange = true;
mc.interactionManager.interactBlock(mc.player, Hand.MAIN_HAND, mc.gameMode.useItemOn(mc.player, InteractionHand.MAIN_HAND,
new BlockHitResult(input.toCenterPos(), Direction.UP, input, false)); new BlockHitResult(ic, Direction.UP, input, false));
containerDelay = Configs.Generic.CONTAINER_CLOSE_DELAY.getIntegerValue(); containerDelay = Configs.Generic.CONTAINER_CLOSE_DELAY.getIntegerValue();
inputOpened = true; inputOpened = true;
return; return;
} }
if ((mc.player.squaredDistanceTo(output.toCenterPos()) < 16.0D) && (outputInRange == false)) { if ((mc.player.distanceToSqr(oc) < 16.0D) && (outputInRange == false)) {
outputInRange = true; outputInRange = true;
mc.interactionManager.interactBlock(mc.player, Hand.MAIN_HAND, mc.gameMode.useItemOn(mc.player, InteractionHand.MAIN_HAND,
new BlockHitResult(output.toCenterPos(), Direction.UP, output, false)); new BlockHitResult(oc, Direction.UP, output, false));
containerDelay = Configs.Generic.CONTAINER_CLOSE_DELAY.getIntegerValue(); containerDelay = Configs.Generic.CONTAINER_CLOSE_DELAY.getIntegerValue();
outputOpened = true; outputOpened = true;
return; return;
} }
if (mc.player.distanceToSqr(ic) > 25.0D) {
if (mc.player.squaredDistanceTo(input.toCenterPos()) > 25.0D) {
inputOpened = false; inputOpened = false;
inputInRange = false; inputInRange = false;
} }
if (mc.player.squaredDistanceTo(output.toCenterPos()) > 25.0D) { if (mc.player.distanceToSqr(oc) > 25.0D) {
outputOpened = false; outputOpened = false;
outputInRange = false; outputInRange = false;
} }
tickCount++; tickCount++;
if (tickCount > 200) { if (tickCount > 200) {
tickCount = 0; tickCount = 0;
villagersInRange = new Vector<Entity>(); villagersInRange = new Vector<>();
inputInRange = false; inputInRange = false;
outputInRange = false; outputInRange = false;
if (GuiUtils.getCurrentScreen() instanceof MerchantScreen) { var cur = GuiUtils.getCurrentScreen();
GuiUtils.getCurrentScreen().close(); if (cur != null) {
} if (cur instanceof MerchantScreen || cur instanceof ShulkerBoxScreen
if (GuiUtils.getCurrentScreen() instanceof ShulkerBoxScreen) { || cur instanceof ContainerScreen) {
GuiUtils.getCurrentScreen().close(); cur.onClose();
} }
if (GuiUtils.getCurrentScreen() instanceof GenericContainerScreen) {
GuiUtils.getCurrentScreen().close();
} }
} }
} }
} }