Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
reobf committed Sep 18, 2024
1 parent 831278a commit 76d33cf
Show file tree
Hide file tree
Showing 17 changed files with 520 additions and 35 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ catch (Exception ignored) {

// Pulls version first from the VERSION env and then git tag
String identifiedVersion = null
String versionOverride = '0.0.18p24'
String versionOverride = '0.0.18p25'
try {
// Produce a version based on the tag, or for branches something like 0.2.2-configurable-maven-and-extras.38+43090270b6-dirty
if (versionOverride == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ private void programLocal() {

}

public void classify(ListeningFluidTank[] fin, ItemStack[] iin) {
public boolean classify(ListeningFluidTank[] fin, ItemStack[] iin,boolean removeInputOnSuccess) {

boolean hasJob = false;
for (int ix = 0; ix < f; ix++) {
Expand All @@ -530,10 +530,10 @@ public void classify(ListeningFluidTank[] fin, ItemStack[] iin) {
}
if (fluidEquals(mStoredFluidInternalSingle[ix], fin[ix])) {
if((fin[ix].getFluidAmount()>0&&mStoredFluidInternal[ix].getFluidAmount()>0)&&!fluidEqualsIngoreAmount(mStoredFluidInternal[ix], fin[ix])){
return;
return false;
}
} else {
return;
return false;
}

}
Expand All @@ -543,20 +543,21 @@ public void classify(ListeningFluidTank[] fin, ItemStack[] iin) {
}
if (ItemStack.areItemStacksEqual(mStoredItemInternalSingle[ix], iin[ix])) {
if((iin[ix]!=null&&mStoredItemInternal[ix]!=null)&&!areItemStacksEqualIngoreAmount(mStoredItemInternal[ix], iin[ix])){
return;
return false;
}
} else {
return;
return false;
}

}
if (!hasJob) {
return;
return false;
}

for (int ix = 0; ix < f; ix++) {
mStoredFluidInternal[ix].fill(mStoredFluidInternalSingle[ix].getFluid(), true);
fin[ix].setFluidDirect(null);
if(removeInputOnSuccess)fin[ix].setFluidDirect(null);else
if(fin[ix].getFluid()!=null)fin[ix].setFluidDirect(fin[ix].getFluid().copy());

}
for (int ix = 0; ix < i; ix++) {
Expand All @@ -565,14 +566,15 @@ public void classify(ListeningFluidTank[] fin, ItemStack[] iin) {
mStoredItemInternal[ix] = mStoredItemInternalSingle[ix].copy();
else
mStoredItemInternal[ix].stackSize += mStoredItemInternalSingle[ix].stackSize;
iin[ix] = null;
if(removeInputOnSuccess)iin[ix] = null;else
if(iin[ix]!=null)iin[ix]=iin[ix].copy();
}
tickFirstClassify=-1;//make it instantly accessible
markJustHadNewItems();
onClassify();
if (program)
programLocal();

return true;
}

public boolean recordRecipeOrClassify(ListeningFluidTank[] fin, ItemStack[] iin) {
Expand Down Expand Up @@ -628,6 +630,35 @@ public FluidStack[] getFluidInputs() {
return asFluidStack.apply(mStoredFluidInternal,shared.getFluid());
}

public int space() {
int ret=Integer.MAX_VALUE;
boolean found=false;
for (int ix = 0; ix < i; ix++) {

if(mStoredItemInternalSingle[ix]!=null&&mStoredItemInternalSingle[ix].stackSize>0){
int now=0;
if(mStoredItemInternal[ix]!=null)now=mStoredItemInternal[ix].stackSize;
int tmp=(itemLimit()-now)/mStoredItemInternalSingle[ix].stackSize;
if(tmp<ret){ret=tmp;found=true;}
}
}
for (int ix = 0; ix < f; ix++) {

if(mStoredFluidInternalSingle[ix].getFluidAmount()>0){
int now=mStoredFluidInternal[ix].getFluidAmount();

int tmp=(fluidLimit()-now)/mStoredFluidInternalSingle[ix].getFluidAmount();
if(tmp<ret){ret=tmp;found=true;}
}
}

if(found)return ret;
return 0;



}

}

int bufferNum;
Expand Down Expand Up @@ -716,7 +747,7 @@ public void startRecipeProcessingImpl() {

if (inv0.full() == false) {
if (!inv0.recordRecipeOrClassify(this.mStoredFluid, mInventory)) {
inv0.classify(this.mStoredFluid, mInventory);
if(inv0.classify(this.mStoredFluid, mInventory,true))break;;
}
}

Expand Down Expand Up @@ -782,9 +813,9 @@ public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) {
for (DualInvBuffer inv0 : this.sortByEmpty()) {
if (on && dirty&&!inputEmpty.get()) {
if (inv0.full() == false) {
if (!inv0.recordRecipeOrClassify(this.mStoredFluid, mInventory)) {
inv0.classify(this.mStoredFluid, mInventory);
}
if (inv0.recordRecipeOrClassify(this.mStoredFluid, mInventory)||
inv0.classify(this.mStoredFluid, mInventory,true))break;;

}
}

Expand Down Expand Up @@ -824,11 +855,22 @@ public void classify() {
return;
for (DualInvBuffer inv0 : this.sortByEmpty()) {
if (inv0.full() == false)
inv0.classify(this.mStoredFluid, mInventory);
if(inv0.classify(this.mStoredFluid, mInventory,true))break;
}

}
public DualInvBuffer classifyForce() {
if (isRemote())
return null;
for (DualInvBuffer inv0 : this.sortByEmpty()) {
if (inv0.full() == false)
if(inv0.classify(this.mStoredFluid, mInventory,true)||
inv0.recordRecipeOrClassify(mStoredFluid, mInventory)
)return inv0;
}
return null;

}
boolean dirty;

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@
import net.minecraftforge.fluids.FluidTank;
import reobf.proghatches.gt.metatileentity.BufferedDualInputHatch.DualInvBuffer;
import reobf.proghatches.gt.metatileentity.DualInputHatch.Net;
import reobf.proghatches.gt.metatileentity.util.IMultiplePatternPushable;
import reobf.proghatches.gt.metatileentity.util.MappingItemHandler;
import reobf.proghatches.lang.LangManager;
import reobf.proghatches.main.Config;

import com.glodblock.github.common.item.ItemFluidPacket;
import com.google.common.collect.ImmutableList;
Expand Down Expand Up @@ -87,7 +89,7 @@

public class PatternDualInputHatch extends BufferedDualInputHatch
implements ICraftingProvider, IGridProxyable, ICustomNameObject, IInterfaceViewable, IPowerChannelState, IActionHost

,IMultiplePatternPushable
{

public PatternDualInputHatch(String mName, byte mTier, String[] mDescriptionArray, ITexture[][][] mTextures,
Expand Down Expand Up @@ -593,7 +595,7 @@ public boolean pushPattern(ICraftingPatternDetails patternDetails, InventoryCraf
return false;
}

mStoredFluid[fluids-1].setFluid(ItemFluidPacket.getFluidStack(itemStack));
mStoredFluid[fluids-1].setFluidDirect(ItemFluidPacket.getFluidStack(itemStack));

} else {
items++;
Expand All @@ -607,8 +609,13 @@ public boolean pushPattern(ICraftingPatternDetails patternDetails, InventoryCraf
}
markDirty();
dirty = true;
classify();

//inv0.recordRecipeOrClassify(this.mStoredFluid, mInventory)
//classify();
for (DualInvBuffer inv0 : this.sortByEmpty()) {
if (inv0.full() == false)
if(inv0.recordRecipeOrClassify(this.mStoredFluid, mInventory)||
inv0.classify(this.mStoredFluid, mInventory,true))break;
}
justHadNewItems = true;
return true;
}
Expand Down Expand Up @@ -882,6 +889,100 @@ public boolean allowsPatternOptimization() {
}



@Override
public int pushPatternMulti(ICraftingPatternDetails patternDetails, InventoryCrafting table, int maxTodo) {
if(Config.fastPatternDualInput==false)return 0;
if(maxTodo<=0)return 0;
if (!isActive()&&!skipActiveCheck)
return 0;
if (!isEmpty())
return 0;
if (!supportsFluids()) {
for (int i = 0; i < table.getSizeInventory(); ++i) {
ItemStack itemStack = table.getStackInSlot(i);
if (itemStack == null)
continue;
if (itemStack.getItem() instanceof ItemFluidPacket)
return 0;
}
}

int items = 0;
int fluids = 0;
int size = table.getSizeInventory();
for (int i = 0; i < size; i++) {
ItemStack itemStack = table.getStackInSlot(i);
if (itemStack == null)
continue;
if (itemStack.getItem() instanceof ItemFluidPacket) {
fluids++;
if (fluids > this.fluidSlots()) {
clearInv();
return 0;
}

mStoredFluid[fluids-1].setFluidDirect(ItemFluidPacket.getFluidStack(itemStack));

} else {
items++;
if (items > 16) {
clearInv();
return 0;
}
mInventory[items-1] = itemStack;

}
}
markDirty();
dirty = true;
//classify();
int suc=0;
DualInvBuffer theBuffer=classifyForce();
//if(theBuffer!=null){
suc++;maxTodo--;
//}
/*for (DualInvBuffer inv0 : this.sortByEmpty()) {
if (inv0.full() == false)
if(inv0.recordRecipeOrClassify(this.mStoredFluid, mInventory)||
inv0.classify(this.mStoredFluid, mInventory, true)
){
theBuffer=inv0;suc++;maxTodo--;
break;}
}*/
if(theBuffer!=null){//if succeeded, it's safe to simply add to stacksize to push more patterns
int todo=Math.min(theBuffer.space()
/*space() will return correct result here
*it assumes item/fluid type is correct
* */
,maxTodo);

if(todo>0){
for(int ix=0;ix<theBuffer.i;ix++){
if(theBuffer.mStoredItemInternalSingle[ix]!=null){
theBuffer.mStoredItemInternal[ix].stackSize+=theBuffer.mStoredItemInternalSingle[ix].stackSize*todo;
}
if(theBuffer.mStoredFluidInternalSingle[ix].getFluidAmount()>0){
theBuffer.mStoredFluidInternal[ix].getFluid().amount+=theBuffer.mStoredFluidInternalSingle[ix].getFluidAmount();
}
}
suc+=todo;
}


}







justHadNewItems = true;
return suc;
}





Expand Down
Loading

0 comments on commit 76d33cf

Please sign in to comment.