Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
import net.minecraftforge.items.wrapper.PlayerArmorInvWrapper;
import net.minecraftforge.items.wrapper.PlayerInvWrapper;
import net.minecraftforge.items.wrapper.PlayerOffhandInvWrapper;
import org.jetbrains.annotations.NotNull;

import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -187,9 +187,14 @@ public final int getFreeSlot() throws LuaException {
return getOwnerPlayer().getInventory().getFreeSlot();
}

@LuaFunction(mainThread = true)
public final int getHandSlot() throws LuaException {
return getOwnerPlayer().getInventory().selected;
}

@LuaFunction(mainThread = true)
public final Map<String, Object> getItemInHand() throws LuaException {
return LuaConverter.itemStackToObject(getOwnerPlayer().getMainHandItem());
return LuaConverter.itemStackToObject(getOwnerPlayer().getMainHandItem(), getOwnerPlayer().getInventory().selected);
}

@LuaFunction(mainThread = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
import net.minecraftforge.common.IForgeShearable;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidType;
import org.jetbrains.annotations.NotNull;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -104,8 +105,11 @@ public static Object posToObject(BlockPos pos) {
return map;
}

@Nullable
public static Map<String, Object> itemStackToObject(@NotNull ItemStack stack) {
if (stack.isEmpty()) return new HashMap<>();
if (stack.isEmpty()) {
return null;
}
Map<String, Object> map = itemToObject(stack.getItem());
CompoundTag nbt = stack.copy().getOrCreateTag();
map.put("count", stack.getCount());
Expand Down Expand Up @@ -141,10 +145,13 @@ public static Map<String, Object> itemStackToObject(@NotNull ItemStack itemStack
* @return a Map containing proper item stack details
* @see InventoryManagerPeripheral#getItems()
*/
@Nullable
public static Map<String, Object> stackToObjectWithSlot(@NotNull ItemStack stack, int slot) {
if (stack.isEmpty()) return new HashMap<>();
if (stack.isEmpty()) {
return null;
}
Map<String, Object> map = itemStackToObject(stack);
map.put("slot", slot);
map.put("slot", slot + 1);
return map;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ public static Pair<ItemFilter, String> parse(Map<?, ?> item) {
}
if (item.containsKey("fromSlot")) {
try {
itemFilter.fromSlot = TableHelper.getIntField(item, "fromSlot");
itemFilter.fromSlot = TableHelper.getIntField(item, "fromSlot") - 1;
} catch (LuaException luaException) {
return Pair.of(null, "NO_VALID_FROMSLOT");
}
}
if (item.containsKey("toSlot")) {
try {
itemFilter.toSlot = TableHelper.getIntField(item, "toSlot");
itemFilter.toSlot = TableHelper.getIntField(item, "toSlot") - 1;
} catch (LuaException luaException) {
return Pair.of(null, "NO_VALID_TOSLOT");
}
Expand Down