Skip to content

Commit

Permalink
remove ItemGroup & fixup proxy port
Browse files Browse the repository at this point in the history
- use ItemStack directly instead of an ItemGroup
- continue read/write the stack size separately, but as integer instead of long
- overhaul proxy port inventory management to finally work with hoppers & ender io conduits (not tested yet with other mods)
- remove early mixins
  • Loading branch information
Pilzinsel64 committed Jan 10, 2025
1 parent 726d3c5 commit 1f32651
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 202 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ mixinsPackage = mixins
# Specify the core mod entry class if you use a core mod. This class must implement IFMLLoadingPlugin!
# This parameter is for legacy compatibility only
# Example value: (coreModClass = asm.FMLPlugin) + (modGroup = com.myname.mymodid) -> com.myname.mymodid.asm.FMLPlugin
coreModClass = EarlyMixinPlugin
coreModClass =

# If your project is only a consolidation of mixins or a core mod and does NOT contain a 'normal' mod ( = some class
# that is annotated with @Mod) you want this to be true. When in doubt: leave it on false!
Expand Down
52 changes: 0 additions & 52 deletions src/main/java/com/zerofall/ezstorage/EarlyMixinPlugin.java

This file was deleted.

30 changes: 14 additions & 16 deletions src/main/java/com/zerofall/ezstorage/gui/GuiStorageCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import com.zerofall.ezstorage.network.MyMessage;
import com.zerofall.ezstorage.tileentity.TileEntityStorageCore;
import com.zerofall.ezstorage.util.EZItemRenderer;
import com.zerofall.ezstorage.util.ItemGroup;
import com.zerofall.ezstorage.util.ItemStackCountComparator;

import codechicken.nei.SearchField;
import codechicken.nei.api.ItemFilter;
Expand All @@ -46,7 +46,7 @@ public class GuiStorageCore extends GuiContainer {
"textures/gui/container/creative_inventory/tab_item_search.png");
private float currentScroll;
private GuiTextField searchField;
private List<ItemGroup> filteredList;
private List<ItemStack> filteredList;
private ItemStack mouseOverItem;
protected List<GuiButton> extraButtons;

Expand All @@ -65,7 +65,7 @@ public void initGui() {
this.searchField.setCanLoseFocus(true);
this.searchField.setFocused(true);
this.searchField.setText("");
filteredList = new ArrayList<ItemGroup>(this.tileEntity.inventory.inventory);
filteredList = new ArrayList<ItemStack>(this.tileEntity.inventory.inventory);
extraButtons = new ArrayList<GuiButton>();
}

Expand Down Expand Up @@ -139,15 +139,14 @@ protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
break;
}

ItemGroup group = this.filteredList.get(index);
ItemStack stack = group.itemStack;
ItemStack stack = this.filteredList.get(index);
FontRenderer font = null;
if (stack != null) font = stack.getItem()
.getFontRenderer(stack);
if (font == null) font = fontRendererObj;
RenderHelper.enableGUIStandardItemLighting();
itemRender.renderItemAndEffectIntoGUI(font, this.mc.getTextureManager(), stack, x, y);
ezRenderer.renderItemOverlayIntoGUI(font, stack, x, y, "" + group.count);
ezRenderer.renderItemOverlayIntoGUI(font, stack, x, y, "" + stack.stackSize);
x += 18;
}
if (finished) {
Expand Down Expand Up @@ -177,10 +176,10 @@ protected void cacheMouseOverItem(int mouseX, int mouseY) {

if (slot != null) {
if (slot < this.filteredList.size()) {
ItemGroup group = this.filteredList.get(slot);
ItemStack group = this.filteredList.get(slot);

if (group != null) {
mouseOverItem = group.itemStack;
mouseOverItem = group;
return;
}
}
Expand All @@ -205,7 +204,7 @@ private void updateFilteredItems() {
.trim();

if (filteredList == null) {
filteredList = new ArrayList<ItemGroup>();
filteredList = new ArrayList<ItemStack>();
}
filteredList.clear();

Expand All @@ -217,13 +216,12 @@ private void updateFilteredItems() {
filterItems(searchText.toLowerCase());
}

Collections.sort(filteredList, new ItemGroup.CountComparator());
Collections.sort(filteredList, new ItemStackCountComparator());
}

private void filterItems(String searchText) {
for (ItemGroup group : this.tileEntity.inventory.inventory) {
List<String> infos = group.itemStack
.getTooltip(this.mc.thePlayer, this.mc.gameSettings.advancedItemTooltips);
for (ItemStack group : this.tileEntity.inventory.inventory) {
List<String> infos = group.getTooltip(this.mc.thePlayer, this.mc.gameSettings.advancedItemTooltips);
for (String info : infos) {
if (EnumChatFormatting.getTextWithoutFormattingCodes(info)
.toLowerCase()
Expand All @@ -239,8 +237,8 @@ private void filterItemsViaNei(String searchText) {
ItemFilter filter = SearchField.getFilter(searchText);
boolean matches;

for (ItemGroup group : this.tileEntity.inventory.inventory) {
matches = filter.matches(group.itemStack);
for (ItemStack group : this.tileEntity.inventory.inventory) {
matches = filter.matches(group);

if (matches) {
filteredList.add(group);
Expand Down Expand Up @@ -286,7 +284,7 @@ protected void mouseClicked(int mouseX, int mouseY, int mouseButton) {
}
int index = this.tileEntity.inventory.slotCount();
if (slot < this.filteredList.size()) {
ItemGroup group = this.filteredList.get(slot);
ItemStack group = this.filteredList.get(slot);
if (group != null) {
index = this.tileEntity.inventory.inventory.indexOf(group);
if (index < 0) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import com.zerofall.ezstorage.configuration.EZConfiguration;
import com.zerofall.ezstorage.util.EZInventory;
import com.zerofall.ezstorage.util.ItemGroup;

public class TileEntityInventoryProxy extends TileEntity implements ISidedInventory {

Expand All @@ -18,7 +17,7 @@ public class TileEntityInventoryProxy extends TileEntity implements ISidedInvent
@Override
public int getSizeInventory() {
if (core == null) {
return 0;
return 1;
}
int size = core.inventory.inventory.size();
if (core.inventory.getTotalCount() < core.inventory.maxItems
Expand All @@ -30,11 +29,8 @@ public int getSizeInventory() {

@Override
public ItemStack getStackInSlot(int index) {
if (index < core.inventory.inventory.size()) {
ItemGroup group = core.inventory.inventory.get(index);
ItemStack copy = group.itemStack.copy();
copy.stackSize = (int) group.count;
return copy;
if (core != null && index < core.inventory.inventory.size()) {
return core.inventory.inventory.get(index);
}
return null;
}
Expand All @@ -48,10 +44,18 @@ public ItemStack decrStackSize(int index, int count) {

@Override
public void setInventorySlotContents(int index, ItemStack stack) {
if (stack != null && stack.stackSize != 0 && isItemValidForSlot(index, stack)) {
if (core == null) {
return;
} else if (stack == null || stack.stackSize == 0) {
core.inventory.inventory.remove(index);
} else if (index >= core.inventory.inventory.size()) {
core.inventory.input(stack);
core.updateTileEntity();
} else if (isItemValidForSlot(index, stack)) {
core.inventory.inventory.set(index, stack);
} else {
return;
}
core.updateTileEntity();
}

@Override
Expand Down Expand Up @@ -85,15 +89,15 @@ public boolean isItemValidForSlot(int index, ItemStack stack) {

// Search for existing group of the given item type
for (int i = 0; i < itemsCount; i++) {
ItemGroup group = core.inventory.inventory.get(i);
if (EZInventory.stacksEqual(group.itemStack, stack)) {
ItemStack group = core.inventory.inventory.get(i);
if (EZInventory.stacksEqual(group, stack)) {
foundIndex = i;
}
}

// Permit if the destination is a new slot and the item doesn't exist
if (index >= core.inventory.inventory.size()) {
return foundIndex == -1;
return true; // return foundIndex == -1;
}

// Permit if the item eixsts and is in the destination slot
Expand All @@ -103,13 +107,13 @@ public boolean isItemValidForSlot(int index, ItemStack stack) {

// If the item doesn't exist, permit if the destination slot is empty
if (index == -1) {
ItemGroup group = core.inventory.inventory.get(index);
if (group == null || group.count == 0 || group.itemStack == null) {
ItemStack group = core.inventory.inventory.get(index);
if (group == null || group.stackSize == 0) {
return true;
}
}

// Deny if the item exists but in another slot
// Permit if the item exists but in another slot
return false;
}

Expand All @@ -130,8 +134,8 @@ public boolean canExtractItem(int index, ItemStack stack, int direction) {
}

// The item in the slot needs to be the same as the given item
ItemGroup theGroup = core.inventory.inventory.get(index);
return theGroup != null && theGroup.itemStack != null && EZInventory.stacksEqual(theGroup.itemStack, stack);
ItemStack theGroup = core.inventory.inventory.get(index);
return theGroup != null && EZInventory.stacksEqual(theGroup, stack);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import com.zerofall.ezstorage.util.BlockRef;
import com.zerofall.ezstorage.util.EZInventory;
import com.zerofall.ezstorage.util.EZStorageUtils;
import com.zerofall.ezstorage.util.ItemGroup;

public class TileEntityStorageCore extends TileEntity {

Expand Down Expand Up @@ -82,12 +81,11 @@ public void writeToNBT(NBTTagCompound paramNBTTagCompound) {
super.writeToNBT(paramNBTTagCompound);
NBTTagList nbttaglist = new NBTTagList();
for (int i = 0; i < this.inventory.slotCount(); ++i) {
ItemGroup group = this.inventory.inventory.get(i);
if (group != null && group.itemStack != null && group.count > 0) {
ItemStack group = this.inventory.inventory.get(i);
if (group != null && group.stackSize > 0) {
NBTTagCompound nbttagcompound1 = new NBTTagCompound();
nbttagcompound1.setByte("Index", (byte) i);
group.itemStack.writeToNBT(nbttagcompound1);
nbttagcompound1.setLong("InternalCount", group.count);
group.writeToNBT(nbttagcompound1);
nbttagcompound1.setInteger("InternalCount", group.stackSize);
nbttaglist.appendTag(nbttagcompound1);
}
}
Expand All @@ -102,13 +100,16 @@ public void readFromNBT(NBTTagCompound paramNBTTagCompound) {
NBTTagList nbttaglist = paramNBTTagCompound.getTagList("Internal", 10);

if (nbttaglist != null) {
inventory.inventory = new ArrayList<ItemGroup>();
inventory.inventory = new ArrayList<ItemStack>();
for (int i = 0; i < nbttaglist.tagCount(); ++i) {
NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i);
ItemStack stack = ItemStack.loadItemStackFromNBT(nbttagcompound1);
long count = nbttagcompound1.getLong("InternalCount");
ItemGroup group = new ItemGroup(stack, count);
this.inventory.inventory.add(group);
if (nbttagcompound1.hasKey("InternalCount", 3)) {
stack.stackSize = (int) nbttagcompound1.getInteger("InternalCount");
} else if (nbttagcompound1.hasKey("InternalCount", 4)) {
stack.stackSize = (int) nbttagcompound1.getLong("InternalCount");
}
this.inventory.inventory.add(stack);
}
}
long maxItems = paramNBTTagCompound.getLong("InternalMax");
Expand Down
Loading

0 comments on commit 1f32651

Please sign in to comment.