11package com.nekiplay.hypixelcry.features.lua.objects.player
22
3- import com.nekiplay.hypixelcry.HypixelCry
43import com.nekiplay.hypixelcry.features.lua.utils.ItemStackUtils
54import com.nekiplay.hypixelcry.mixins.gui.AbstractSignEditScreenAccessor
65import com.nekiplay.hypixelcry.pathfinder.utils.mc
76import com.nekiplay.hypixelcry.utils.InventoryUtils
87import net.minecraft.client.gui.screen.ingame.GenericContainerScreen
98import net.minecraft.client.gui.screen.ingame.SignEditScreen
9+ import net.minecraft.screen.GenericContainerScreenHandler
10+ import net.minecraft.screen.ScreenHandler
1011import org.luaj.vm2.LuaValue
1112import org.luaj.vm2.lib.OneArgFunction
1213import org.luaj.vm2.lib.TwoArgFunction
1314import org.luaj.vm2.lib.ZeroArgFunction
1415
16+
1517class InventoryObject : LuaValue () {
1618 override fun call (): LuaValue {
1719 return this
@@ -24,6 +26,7 @@ class InventoryObject: LuaValue() {
2426 " isDoubleChestOpened" -> IsDoubleChestOpenedFunction ()
2527 " getChestTitle" -> GetChestTitleFunction ()
2628
29+ " getStackFromContainer" -> GetStackFromContainerFunction ()
2730 " getStack" -> GetStackFunction ()
2831 " getSignText" -> GetSignTextFunction ()
2932 " setSignText" -> SetSignTextFunction ()
@@ -125,7 +128,7 @@ class InventoryObject: LuaValue() {
125128 val container = screen.screenHandler
126129 val slots = container.slots.size
127130 val chestType = when (slots) {
128- 54 -> TRUE
131+ 53 -> TRUE
129132 else -> FALSE
130133 }
131134 return chestType
@@ -143,7 +146,7 @@ class InventoryObject: LuaValue() {
143146 val container = screen.screenHandler
144147 val slots = container.slots.size
145148 val chestType = when (slots) {
146- 27 -> TRUE
149+ 26 -> TRUE
147150 else -> FALSE
148151 }
149152 return chestType
@@ -164,6 +167,27 @@ class InventoryObject: LuaValue() {
164167 }
165168 }
166169
170+ private inner class GetStackFromContainerFunction : OneArgFunction () {
171+ override fun call (arg : LuaValue ? ): LuaValue {
172+ return if (arg?.isnumber() == true ) {
173+ if (mc.player != null ) {
174+ val screenHandler: ScreenHandler ? = mc.player!! .currentScreenHandler
175+ if (screenHandler is GenericContainerScreenHandler ) {
176+ return ItemStackUtils .ToLua (screenHandler.getSlot(arg.toint()).stack) ? : NIL
177+ }
178+ else {
179+ NIL
180+ }
181+ }
182+ else {
183+ NIL
184+ }
185+ } else {
186+ NIL
187+ }
188+ }
189+ }
190+
167191 override fun typename (): String = " inventory"
168192 override fun tojstring (): String = " InventoryObject"
169193 override fun isnil (): Boolean = false
0 commit comments