-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
482 additions
and
102 deletions.
There are no files selected for viewing
201 changes: 122 additions & 79 deletions
201
src/main/java/reobf/proghatches/gt/metatileentity/BufferedDualInputHatch.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
173 changes: 173 additions & 0 deletions
173
src/main/java/reobf/proghatches/gt/metatileentity/bufferutil/ItemStackG.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
package reobf.proghatches.gt.metatileentity.bufferutil; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Iterator; | ||
|
||
import net.minecraft.item.Item; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.nbt.NBTTagCompound; | ||
import net.minecraft.nbt.NBTTagList; | ||
|
||
//G is for group | ||
public class ItemStackG { | ||
public ArrayList<ItemStack> arr = new ArrayList<>(); | ||
|
||
|
||
public static ItemStackG neo(ItemStack is) { | ||
if (is == null) | ||
return null; | ||
return new ItemStackG(is); | ||
} | ||
|
||
private ItemStackG(ItemStack is) { | ||
arr.add(is); | ||
} | ||
public ItemStack getZero(){ | ||
return arr.get(0); | ||
|
||
|
||
} | ||
public NBTTagCompound writeToNBT(NBTTagCompound p_77955_1_) { | ||
|
||
arr.get(0).writeToNBT(p_77955_1_); | ||
p_77955_1_.setInteger("ICount", arr.get(0).stackSize); | ||
|
||
NBTTagList lst = new NBTTagList(); | ||
for (int i = 1; i < arr.size(); i++) { | ||
|
||
NBTTagCompound t = new NBTTagCompound(); | ||
arr.get(i).writeToNBT(t); | ||
t.setInteger("ICount", arr.get(i).stackSize); | ||
lst.appendTag(t); | ||
|
||
} | ||
|
||
p_77955_1_.setTag("therest", lst); | ||
|
||
return p_77955_1_; | ||
} | ||
|
||
public static ItemStackG readFromNBT(NBTTagCompound p_77963_1_) { | ||
|
||
ItemStack is = ItemStack.loadItemStackFromNBT(p_77963_1_); | ||
if (is == null) | ||
return null; | ||
is.stackSize = p_77963_1_.getInteger("ICount"); | ||
ItemStackG to = neo(is); | ||
if (to != null) { | ||
|
||
if (p_77963_1_.hasKey("therest")) { | ||
|
||
NBTTagList lst = (NBTTagList) p_77963_1_.getTag("therest"); | ||
for (int ix = 0; ix < lst.tagCount(); ix++) { | ||
NBTTagCompound TAG = lst.getCompoundTagAt(ix); | ||
|
||
ItemStack isX = ItemStack.loadItemStackFromNBT(TAG); | ||
if (isX != null) { | ||
isX.stackSize = TAG.getInteger("ICount"); | ||
to.arr.add(isX); | ||
} | ||
|
||
} | ||
|
||
} | ||
|
||
} | ||
|
||
return to; | ||
|
||
} | ||
|
||
public long stackSize() { | ||
return arr.stream().mapToLong(s->s.stackSize).sum(); | ||
} | ||
|
||
public Item getItem() { | ||
|
||
return arr.get(0).getItem(); | ||
} | ||
|
||
public ItemStack getStack() { | ||
ItemStack ret=arr.get(0).copy(); | ||
ret.stackSize=(int) Math.min(stackSize(),Integer.MAX_VALUE); | ||
return ret; | ||
} | ||
|
||
public void stackSizeInc(int todo) { | ||
|
||
for(ItemStack is:arr){ | ||
int cando=Math.min( | ||
|
||
Integer.MAX_VALUE | ||
//64 | ||
|
||
|
||
-is.stackSize,todo); | ||
todo-=cando; | ||
is.stackSize+=cando; | ||
if(todo<=0)return; | ||
} | ||
ItemStack i = arr.get(0).copy(); | ||
i.stackSize=todo; | ||
arr.add(i); | ||
|
||
|
||
} | ||
|
||
public static ItemStackG loadItemStackFromNBT(NBTTagCompound tag) { | ||
|
||
return readFromNBT(tag); | ||
} | ||
|
||
public ItemStack[] flat() { | ||
adjust(); | ||
return arr.toArray(new ItemStack[arr.size()]); | ||
} | ||
|
||
|
||
|
||
public void stackSize(int i) { | ||
|
||
if(arr.size()>1){arr.remove(1);} | ||
arr.get(0).stackSize=i; | ||
} | ||
|
||
public static ItemStackG setZero(ItemStackG itemStackG, ItemStack copyStackWithSize) { | ||
|
||
|
||
if(itemStackG==null){ | ||
return neo(copyStackWithSize); | ||
} | ||
if(copyStackWithSize==null) | ||
itemStackG.arr.get(0).stackSize=0; | ||
|
||
else | ||
itemStackG.arr.get(0).stackSize=copyStackWithSize.stackSize; | ||
itemStackG.adjust(); | ||
return itemStackG; | ||
} | ||
|
||
public void adjust(){boolean dirty=false; | ||
for(int i=0;i<arr.size()-1;i++){ | ||
if(arr.get(i).stackSize<Integer.MAX_VALUE){ | ||
if(arr.get(i+1).stackSize>0){ | ||
int todo=Math.min(Integer.MAX_VALUE-arr.get(i).stackSize, arr.get(i+1).stackSize); | ||
arr.get(i).stackSize+=todo; | ||
arr.get(i+1).stackSize-=todo;dirty=true; | ||
|
||
} | ||
} | ||
|
||
} | ||
|
||
if(dirty){ | ||
Iterator<ItemStack> it = arr.iterator();it.next(); | ||
while(it.hasNext()){ | ||
if(it.next().stackSize<=0){it.remove();} | ||
|
||
} | ||
|
||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.