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 @@ -58,15 +58,15 @@ public Object[] setCraftingRequest(final Context context, final Arguments args)

@Callback
public Object[] getRequest(final Context context, final Arguments args) {
final Map<Integer, Map<String, Object>> result = new LinkedHashMap<>();
final Map<Integer, ItemStack> result = new LinkedHashMap<>();
int index = 1;
for (final BigItemStack stack : blockEntity.encodedRequest.stacks()) {
if (stack.stack.isEmpty()) {
index++;
continue;
}
final Map<String, Object> details = CreateLuaConversion.itemDetails(stack.stack);
details.put("count", stack.count);
final ItemStack details = stack.stack.copy();
details.setCount(stack.count);
result.put(index++, details);
}
return result(result);
Expand Down Expand Up @@ -198,7 +198,7 @@ public Object[] setAddress(final Context context, final Arguments args) {
@Callback
public Object[] getPriceTagItem(final Context context, final Arguments args) {
assertShop();
return result(CreateLuaConversion.itemDetails(blockEntity.priceTag.getFilter()));
return result(blockEntity.priceTag.getFilter());
}

@Callback
Expand Down Expand Up @@ -227,11 +227,11 @@ public Object[] setPriceTagCount(final Context context, final Arguments args) {
@Callback
public Object[] getWares(final Context context, final Arguments args) {
assertShop();
final Map<Integer, Map<String, Object>> result = new LinkedHashMap<>();
final Map<Integer, ItemStack> result = new LinkedHashMap<>();
int index = 1;
for (final BigItemStack stack : blockEntity.requestData.encodedRequest().stacks()) {
final Map<String, Object> details = CreateLuaConversion.itemDetails(stack.stack);
details.put("count", stack.count);
final ItemStack details = stack.stack.copy();
details.setCount(stack.count);
result.put(index++, details);
}
return result(result);
Expand Down
42 changes: 16 additions & 26 deletions src/main/java/li/cil/oc/integration/create/CreateLuaConversion.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,59 +17,49 @@ final class CreateLuaConversion {
private CreateLuaConversion() {
}

static Map<Integer, Map<String, Object>> list(final IItemHandler inventory) {
final Map<Integer, Map<String, Object>> result = new LinkedHashMap<>();
static Map<Integer, ItemStack> list(final IItemHandler inventory) {
final Map<Integer, ItemStack> result = new LinkedHashMap<>();
for (int slot = 0; slot < inventory.getSlots(); slot++) {
final ItemStack stack = inventory.getStackInSlot(slot);
if (!stack.isEmpty())
result.put(slot + 1, itemDetails(stack));
result.put(slot + 1, stack);
}
return result;
}

static Map<Integer, Map<String, Object>> list(final InventorySummary inventory) {
final Map<Integer, Map<String, Object>> result = new LinkedHashMap<>();
static Map<Integer, ItemStack> list(final InventorySummary inventory) {
final Map<Integer, ItemStack> result = new LinkedHashMap<>();
int slot = 1;
for (final BigItemStack stack : inventory.getStacks()) {
final Map<String, Object> details = itemDetails(stack.stack);
details.put("count", stack.count);
final ItemStack details = stack.stack.copy();
details.setCount(stack.count);
result.put(slot++, details);
}
return result;
}

static Map<String, Object> getItemDetail(final IItemHandler inventory, final int slot) {
static ItemStack getItemDetail(final IItemHandler inventory, final int slot) {
if (slot < 1 || slot > inventory.getSlots())
throw new IllegalArgumentException("Slot " + slot + " out of range, available slots between 1 and " + inventory.getSlots());
final ItemStack stack = inventory.getStackInSlot(slot - 1);
return stack.isEmpty() ? null : itemDetails(stack);
return stack.isEmpty() ? null : stack;
}

static Map<String, Object> getItemDetail(final InventorySummary inventory, final int slot) {
static ItemStack getItemDetail(final InventorySummary inventory, final int slot) {
final List<BigItemStack> stacks = inventory.getStacks();
if (slot < 1 || slot > stacks.size())
throw new IllegalArgumentException("Slot " + slot + " out of range, available slots between 1 and " + stacks.size());
final BigItemStack stack = stacks.get(slot - 1);
final Map<String, Object> details = itemDetails(stack.stack);
details.put("count", stack.count);
return details;
}

static Map<String, Object> itemDetails(final ItemStack stack) {
final Map<String, Object> details = new LinkedHashMap<>();
details.put("name", BuiltInRegistries.ITEM.getKey(stack.getItem()).toString());
details.put("count", stack.getCount());
details.put("displayName", stack.getHoverName().getString());
details.put("damage", stack.getDamageValue());
details.put("maxDamage", stack.getMaxDamage());
final ItemStack details = stack.stack.copy();
details.setCount(stack.count);
return details;
}

static int matchingCount(final BigItemStack entry, final Map<?, ?> filter) {
final Map<String, Object> details = itemDetails(entry.stack);
details.put("count", entry.count);
if (filter.get("name") instanceof String name && !name.contains(":"))
details.put("name", "minecraft:" + name);
final ItemStack details = entry.stack.copy();
details.setCount(entry.count);
//if (filter.get("name") instanceof String name && !name.contains(":"))
// details.put("name", "minecraft:" + name);
return deepMatches(filter, details) ? entry.count : 0;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,25 +118,25 @@ public Object[] invoke(final String method, final Context context, final Argumen
};
}

private static Map<Integer, Map<String, Object>> list(final PackageOrderWithCrafts order) {
final Map<Integer, Map<String, Object>> result = new LinkedHashMap<>();
private static Map<Integer, ItemStack> list(final PackageOrderWithCrafts order) {
final Map<Integer, ItemStack> result = new LinkedHashMap<>();
int index = 1;
for (final BigItemStack stack : order.stacks()) {
final Map<String, Object> details = CreateLuaConversion.itemDetails(stack.stack);
details.put("count", stack.count);
final ItemStack details = stack.stack.copy();
details.setCount(stack.count);
result.put(index++, details);
}
return result;
}

private static Map<String, Object> detail(final PackageOrderWithCrafts order, final int slot) {
private static ItemStack detail(final PackageOrderWithCrafts order, final int slot) {
if (slot < 1)
throw new IllegalArgumentException("Slot out of range (1 or greater)");
if (slot > order.stacks().size())
return null;
final BigItemStack stack = order.stacks().get(slot - 1);
final Map<String, Object> details = CreateLuaConversion.itemDetails(stack.stack);
details.put("count", stack.count);
final ItemStack details = stack.stack.copy();
details.setCount(stack.count);
return details;
}

Expand Down
Loading