Skip to content

Commit

Permalink
add an inventory to one of the test tiles
Browse files Browse the repository at this point in the history
  • Loading branch information
BlueWeabo committed Dec 21, 2024
1 parent 6563790 commit 86cd03a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public IItemStackLong insertItemLong(int slot, IItemStackLong stack, boolean sim
original.setStackSize(0);
}
if (!ItemHandlerHelper.canItemStacksStack(original, stack)) return stack;
long amountToInsert = Math.min(stack.getStackSize(), getSlotLimitLong(slot) - original.getStackSize());
long amountToInsert = Math.max(stack.getStackSize(), getSlotLimitLong(slot) - original.getStackSize());
stack.setStackSize(stack.getStackSize() - amountToInsert);
if (simulate) {
return stack;
Expand Down
44 changes: 33 additions & 11 deletions src/main/java/com/gtnewhorizons/mutecore/test/TestRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@

import com.cleanroommc.modularui.screen.ModularPanel;
import com.cleanroommc.modularui.utils.Alignment;
import com.cleanroommc.modularui.widget.ScrollWidget;
import com.cleanroommc.modularui.widgets.ItemSlotLong;
import com.cleanroommc.modularui.widgets.SlotGroupWidget;
import com.gtnewhorizons.mutecore.api.block.MultiTileEntityBlock;
import com.gtnewhorizons.mutecore.api.data.ItemInputInventory;
import com.gtnewhorizons.mutecore.api.inventory.ItemComponentInventoryHandler;
import com.gtnewhorizons.mutecore.api.inventory.ItemInventory;
import com.gtnewhorizons.mutecore.api.item.MultiTileEntityItem;
import com.gtnewhorizons.mutecore.api.registry.ComponentsCreator;
import com.gtnewhorizons.mutecore.api.registry.MultiTileEntityRegistry;
Expand All @@ -27,19 +33,35 @@ public class TestRegistry implements Runnable {
@Override
public void run() {
TEST_REGISTRY.create(0, MultiTileEntity.class)
.gui((entity, syncManager) -> { return new ModularPanel("testOne").align(Alignment.Center); })
.componentsCreator(new ComponentsCreator().build())
.unlocalizedName("testblockone")
.register();
TEST_REGISTRY.create(1, MultiTileEntity.class)
.gui((entity, syncManager) -> { return new ModularPanel("testTwo").align(Alignment.BottomCenter); })
.componentsCreator(new ComponentsCreator().build())
.unlocalizedName("testblocktwo")
.register();
.gui((entity, syncManager) -> {
ItemInventory inventory = entity.getComponent(ItemInputInventory.class);
ItemComponentInventoryHandler inventoryHandler = new ItemComponentInventoryHandler(inventory);
final ScrollWidget<?> scrollable = new ScrollWidget<>();
SlotGroupWidget slotGroup = new SlotGroupWidget();
scrollable.size(64, 64).child(slotGroup);
for (int row = 0; row * 4 < inventory.getSize() - 1; row++) {
int columnsToMake = Math.min(inventory.getSize() - row * 4, 4);
for (int column = 0; column < columnsToMake; column++) {
slotGroup.child(new ItemSlotLong().slot(inventoryHandler, row * 4 + column)
.pos(column * 18, row * 18).size(18, 18));
}
}

return new ModularPanel("testOne").align(Alignment.Center).child(scrollable.align(Alignment.Center)).bindPlayerInventory();
})
.componentsCreator(new ComponentsCreator().component(() -> new ItemInputInventory(3, 64)).build())
.unlocalizedName("testblockone").register();
TEST_REGISTRY.create(1, MultiTileEntity.class).gui((entity, syncManager) ->

{
return new ModularPanel("testTwo").align(Alignment.BottomCenter);
}).componentsCreator(new ComponentsCreator().build()).unlocalizedName("testblocktwo").register();
}

public static void registerRenders() {
TEST_REGISTRY.registerRender(0, (e, rb, x, y, z, w) -> {});
TEST_REGISTRY.registerRender(1, (e, rb, x, y, z, w) -> {});
TEST_REGISTRY.registerRender(0, (e, rb, x, y, z, w) -> {
});
TEST_REGISTRY.registerRender(1, (e, rb, x, y, z, w) -> {
});
}
}

0 comments on commit 86cd03a

Please sign in to comment.