Skip to content

Commit

Permalink
fix exporter/importer
Browse files Browse the repository at this point in the history
  • Loading branch information
PTOM76 committed Sep 18, 2024
1 parent fe95b7a commit 242d8a9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
11 changes: 0 additions & 11 deletions src/main/java/net/pitan76/itemalchemy/block/EMCExporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,6 @@ public EMCExporter() {

@Override
public void onStateReplaced(StateReplacedEvent e) {
World world = e.world;
BlockPos pos = e.pos;
if (e.isSameState()) return;

BlockEntity blockEntity = WorldUtil.getBlockEntity(world, pos);
if (blockEntity instanceof Inventory) {
Inventory inventory = (Inventory) blockEntity;
inventory.setStack(1, ItemStackUtil.empty());
ItemScattererUtil.spawn(world, pos, inventory);
e.updateComparators();
}
super.onStateReplaced(e);
}

Expand Down
18 changes: 16 additions & 2 deletions src/main/java/net/pitan76/itemalchemy/tile/EMCExporterTile.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public EMCExporterTile(TileCreateEvent e) {
this(Tiles.EMC_EXPORTER.getOrNull(), e);
}

public static int maxStackCount = 4096;

@Override
public void writeNbt(WriteNbtArgs args) {
NbtCompound filterNbt = NbtUtil.create();
Expand Down Expand Up @@ -70,14 +72,25 @@ public void tick(TileTickEvent<EMCExporterTile> e) {

}

@Override
public void setStack(int slot, ItemStack stack) {
System.out.println("setStack: " + slot + ", " + stack);
IInventory.super.setStack(slot, stack);
}

@Override
public ItemStack getStack(int slot) {
System.out.println("getStack: " + slot);
return IInventory.super.getStack(slot);
}

@Override
public DefaultedList<ItemStack> getItems() {
DefaultedList<ItemStack> result = DefaultedList.ofSize(filter.size(), ItemStackUtil.empty());

if (!hasTeam()) return result;
if (filter.get(0).isEmpty()) return result;


@SuppressWarnings("OptionalGetWithoutIsPresent")
TeamState teamState = getTeamState().get();

Expand All @@ -99,7 +112,8 @@ public DefaultedList<ItemStack> getItems() {
if (!teamState.registeredItems.contains(ItemUtil.toCompatID(filterStack.getItem()).toString())) continue;

ItemStack stack = filterStack.copy();
stack.setCount((int) Math.floorDiv(aveEMC, neededEMC));
stack.setCount(Math.min((int) Math.floorDiv(aveEMC, neededEMC), maxStackCount));

result.set(i, stack);
}

Expand Down

0 comments on commit 242d8a9

Please sign in to comment.