Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move future package #11

Merged
merged 1 commit into from
Aug 13, 2024
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

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.cleanroommc.modularui.screen;

import com.cleanroommc.modularui.api.inventory.ClickType;
import com.cleanroommc.modularui.future.ItemHandlerHelper;
import com.cleanroommc.modularui.utils.item.ItemHandlerHelper;
import com.cleanroommc.modularui.widgets.slot.ModularSlot;
import com.cleanroommc.modularui.widgets.slot.SlotGroup;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.cleanroommc.modularui.api.drawable.IKey;
import com.cleanroommc.modularui.factory.GuiData;
import com.cleanroommc.modularui.factory.SimpleGuiFactory;
import com.cleanroommc.modularui.future.ItemStackHandler;
import com.cleanroommc.modularui.utils.item.ItemStackHandler;
import com.cleanroommc.modularui.screen.ModularPanel;
import com.cleanroommc.modularui.utils.Alignment;
import com.cleanroommc.modularui.value.sync.IntSyncValue;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/cleanroommc/modularui/test/TestItem.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.cleanroommc.modularui.test;

import com.cleanroommc.modularui.api.IGuiHolder;
import com.cleanroommc.modularui.future.IItemHandlerModifiable;
import com.cleanroommc.modularui.utils.item.IItemHandlerModifiable;
import com.cleanroommc.modularui.factory.GuiData;
import com.cleanroommc.modularui.factory.ItemGuiFactory;
import com.cleanroommc.modularui.screen.ModularPanel;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/cleanroommc/modularui/test/TestTile.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import com.cleanroommc.modularui.drawable.GuiTextures;
import com.cleanroommc.modularui.drawable.ItemDrawable;
import com.cleanroommc.modularui.drawable.Rectangle;
import com.cleanroommc.modularui.future.IItemHandlerModifiable;
import com.cleanroommc.modularui.future.ItemStackHandler;
import com.cleanroommc.modularui.utils.item.IItemHandlerModifiable;
import com.cleanroommc.modularui.utils.item.ItemStackHandler;
import com.cleanroommc.modularui.factory.PosGuiData;
import com.cleanroommc.modularui.screen.ModularPanel;
import com.cleanroommc.modularui.screen.Tooltip;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.cleanroommc.modularui.utils;

import com.cleanroommc.modularui.future.IItemHandlerModifiable;
import com.cleanroommc.modularui.future.ItemHandlerHelper;
import com.cleanroommc.modularui.utils.item.IItemHandlerModifiable;
import com.cleanroommc.modularui.utils.item.ItemHandlerHelper;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.cleanroommc.modularui.future;
package com.cleanroommc.modularui.utils.item;

import net.minecraft.item.ItemStack;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package com.cleanroommc.modularui.utils.item;

import com.cleanroommc.modularui.api.IItemStackLong;

public class CombinedInvWrapperLong implements IItemHandlerLong {

protected final IItemHandlerLong[] itemHandler; // the handlers
protected final int[] baseIndex; // index-offsets of the different handlers
protected final int slotCount; // number of total slots

public CombinedInvWrapperLong(IItemHandlerLong... itemHandler) {
this.itemHandler = itemHandler;
this.baseIndex = new int[itemHandler.length];
int index = 0;
for (int i = 0; i < itemHandler.length; i++) {
index += itemHandler[i].getSlots();
baseIndex[i] = index;
}
this.slotCount = index;
}

// returns the handler index for the slot
protected int getIndexForSlot(int slot) {
if (slot < 0) {
return -1;
}

for (int i = 0; i < baseIndex.length; i++) {
if (slot - baseIndex[i] < 0) {
return i;
}
}
return -1;
}

protected IItemHandlerLong getHandlerFromIndex(int index) {
if (index < 0 || index >= itemHandler.length) {
return EmptyHandlerLong.INSTANCE;
}
return itemHandler[index];
}

protected int getSlotFromIndex(int slot, int index) {
if (index <= 0 || index >= baseIndex.length) {
return slot;
}
return slot - baseIndex[index - 1];
}

@Override
public void setStackInSlotLong(int slot, IItemStackLong stack) {
int index = getIndexForSlot(slot);
IItemHandlerLong handler = getHandlerFromIndex(index);
slot = getSlotFromIndex(slot, index);
handler.setStackInSlotLong(slot, stack);
}

@Override
public int getSlots() {
return slotCount;
}

@Override
public IItemStackLong getStackInSlotLong(int slot) {
int index = getIndexForSlot(slot);
IItemHandlerLong handler = getHandlerFromIndex(index);
slot = getSlotFromIndex(slot, index);
return handler.getStackInSlotLong(slot);
}

@Override
public IItemStackLong insertItemLong(int slot, IItemStackLong stack, boolean simulate) {
int index = getIndexForSlot(slot);
IItemHandlerLong handler = getHandlerFromIndex(index);
slot = getSlotFromIndex(slot, index);
return handler.insertItemLong(slot, stack, simulate);
}

@Override
public IItemStackLong extractItemLong(int slot, long amount, boolean simulate) {
int index = getIndexForSlot(slot);
IItemHandlerLong handler = getHandlerFromIndex(index);
slot = getSlotFromIndex(slot, index);
return handler.extractItemLong(slot, amount, simulate);
}

@Override
public long getSlotLimitLong(int slot) {
int index = getIndexForSlot(slot);
IItemHandlerLong handler = getHandlerFromIndex(index);
int localSlot = getSlotFromIndex(slot, index);
return handler.getSlotLimitLong(localSlot);
}

@Override
public boolean isItemValidLong(int slot, IItemStackLong stack) {
int index = getIndexForSlot(slot);
IItemHandlerLong handler = getHandlerFromIndex(index);
int localSlot = getSlotFromIndex(slot, index);
return handler.isItemValidLong(localSlot, stack);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.cleanroommc.modularui.future;
package com.cleanroommc.modularui.utils.item;

import net.minecraft.item.ItemStack;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.cleanroommc.modularui.utils.item;

import com.cleanroommc.modularui.api.IItemStackLong;

public class EmptyHandlerLong implements IItemHandlerLong {

public static final IItemHandlerLong INSTANCE = new EmptyHandlerLong();

@Override
public void setStackInSlotLong(int slot, IItemStackLong stack) {
// nothing to do here
}

@Override
public IItemStackLong extractItemLong(int slot, long amount, boolean simulate) {
return null;
}

@Override
public long getSlotLimitLong(int slot) {
return 0;
}

@Override
public IItemStackLong getStackInSlotLong(int slot) {
return null;
}

@Override
public IItemStackLong insertItemLong(int slot, IItemStackLong stack, boolean simulate) {
return null;
}

@Override
public int getSlots() {
return 0;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.cleanroommc.modularui.future;
package com.cleanroommc.modularui.utils.item;

import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package com.cleanroommc.modularui.future;
package com.cleanroommc.modularui.utils.item;

import static com.google.common.primitives.Ints.saturatedCast;

import java.util.ArrayList;
import java.util.List;

import com.cleanroommc.modularui.api.IItemStackLong;
import com.cleanroommc.modularui.utils.item.ItemStackLong;

import net.minecraft.item.ItemStack;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.cleanroommc.modularui.future;
package com.cleanroommc.modularui.utils.item;

import net.minecraft.item.ItemStack;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.cleanroommc.modularui.future;
package com.cleanroommc.modularui.utils.item;

//
// Source code recreated from a .class file by IntelliJ IDEA
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.cleanroommc.modularui.future;
package com.cleanroommc.modularui.utils.item;

import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.cleanroommc.modularui.future;
package com.cleanroommc.modularui.utils.item;
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.cleanroommc.modularui.future;
package com.cleanroommc.modularui.utils.item;
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package com.cleanroommc.modularui.future;
package com.cleanroommc.modularui.utils.item;

import java.util.Arrays;
import java.util.List;

import com.cleanroommc.modularui.api.IItemStackLong;
import com.cleanroommc.modularui.utils.item.ItemStackLong;

import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.cleanroommc.modularui.future;
package com.cleanroommc.modularui.utils.item;

import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.cleanroommc.modularui.future;
package com.cleanroommc.modularui.utils.item;

import net.minecraft.entity.player.InventoryPlayer;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.cleanroommc.modularui.future;
package com.cleanroommc.modularui.utils.item;

import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.InventoryPlayer;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.cleanroommc.modularui.future;
package com.cleanroommc.modularui.utils.item;

import com.google.common.base.Preconditions;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.cleanroommc.modularui.future;
package com.cleanroommc.modularui.utils.item;
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import org.jetbrains.annotations.Nullable;

import com.cleanroommc.modularui.api.IItemStackLong;
import com.cleanroommc.modularui.future.ItemHandlerHelper;
import com.cleanroommc.modularui.utils.item.ItemHandlerHelper;
import com.cleanroommc.modularui.network.NetworkUtils;
import com.cleanroommc.modularui.utils.MouseData;
import com.cleanroommc.modularui.utils.item.ItemStackLong;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.cleanroommc.modularui.value.sync;

import com.cleanroommc.modularui.future.ItemHandlerHelper;
import com.cleanroommc.modularui.utils.item.ItemHandlerHelper;
import com.cleanroommc.modularui.network.NetworkUtils;
import com.cleanroommc.modularui.utils.MouseData;
import com.cleanroommc.modularui.widgets.slot.ModularSlot;
Expand Down
Loading