Container functions#40
Conversation
|
Peak, pls merge |
|
Any update @maxuser0 ? This seems like a useful PR. |
|
YES PLEASE MERGE |
|
Thanks for the PR. Given the power and flexibility of java.py and Pyjinn in Minescript 5.0, I'm not convinced of the need for these functions to be built into the mod. Adding functionality that relies on Minecraft APIs often makes it more difficult to port Minescript across game versions. The script functions already built into Minescript were added before java.py and Pyjinn were integrated into the mod. Going forward, the script functions that I'm likely to include in the mod are ones that provide a significant performance improvement in Java compared to Python or Pyjinn. E.g. I'm planning to add Java implementation for a function like get_blocks_in_region(position1, position2) because it's significantly faster than constructing the nested lists or tuples needed for getblocklist(positions) for thousands of blocks. But I don't think there would be any noticeable speed improvement for the container functions implemented in Java in this PR over an implementation in Python or Pyjinn. |
|
Could you provide an example implementation using Pyjinn? I don't know anything about Java (which is why I use this mod). |
|
Bump, would also like to know how to implement it using Pyjinn. Is there something speaking strictly AGAINST merging? |
|
Got it (I think this is an okay way to do it?) # container_click.py
import minescript # type: ignore
from java import JavaClass # type: ignore
import datetime
from enum import Enum
class _MC:
Minecraft = None
ClickType = None
class EntityType(Enum):
ARMOR_STAND = "entity.minecraft.armor_stand"
PLAYER = "entity.minecraft.player"
def _ensure_classes_loaded():
if _MC.Minecraft is None:
_MC.Minecraft = JavaClass("net.minecraft.client.Minecraft")
if _MC.ClickType is None:
_MC.ClickType = JavaClass("net.minecraft.world.inventory.ClickType")
return True
def _ctx():
_ensure_classes_loaded()
mc = _MC.Minecraft.getInstance()
if mc is None:
return None
player = mc.player
if player is None:
return None
menu = player.containerMenu
if menu is None:
return None
return (mc, player, menu)
def click_slot(slot, button=0, shift=False, index_mode="absolute"):
"""
Click a slot in the currently open container GUI.
slot: index to click
button: 0=left, 1=right, 2=middle
shift: True => shift-click (QUICK_MOVE), False => normal click (PICKUP)
index_mode: "absolute" | "container" | "player"
"""
ctx = _ctx()
if ctx is None:
return False
#minescript.log(f"Got context {datetime.datetime.now()}")
mc, player, menu = ctx
abs_index = slot
click_type = _MC.ClickType.QUICK_MOVE if shift else _MC.ClickType.PICKUP
#minescript.log(f"Executing click {datetime.datetime.now()}")
mc.gameMode.handleInventoryMouseClick(menu.containerId, abs_index, button, click_type, player)
minescript.log(f"Click done! {datetime.datetime.now()}")
return True |
|
Thank you :) |
|
I made a slightly more fetched out util, feel free to edit: https://github.com/brentspine/hypixel-scripts/blob/main/container_click.py |
|
The player_container_click function currently requires you to manually give the amount of slots in a potentially open container. I could maybe add a util function to approximate or get the size, but I have something else to do rn |
|
Btw: I think it might be better to use Pyjinn directly, see here: |
|
I'm too intimidated to learn how to use Pyjinn tbh, especially because I don't know the names of any internal classes or functions, but yeah that would be better |
Yea I still prefer using Minescript, but for some things, like checking inventory, Pyjinn is way better. Just because how slow Minescript would get |
Adds functions for interacting with containers, closes #32.
New functions
container_open(x, y, z)- Open containers (chests, furnaces, crafting tables) at specified coordinatescontainer_close()- Close the currently open containercontainer_get_info()- Get container metadata (slot count, title, type)container_get_items()- Retrieve all items in the open containercontainer_get_slot(slot)- Get the item in a specific slotcontainer_find_item(item_id)- Find all slots containing a specific itemcontainer_click_slot(slot, button, shift)- Click container slots with mouse simulationcontainer_swap_slots(slot1, slot2)- Swap items between two slotsDemo
Screen.Recording.2025-08-12.at.19.30.34.mov