Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
reobf committed Sep 24, 2024
1 parent 63b6ccf commit e0449b1
Show file tree
Hide file tree
Showing 10 changed files with 299 additions and 49 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.19'
String versionOverride = '0.0.19p1'
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 @@ -92,7 +92,10 @@ public CoverToMachineAdaptor(T te,@Nullable InventoryAdaptor invItems,
this.invFluids = invFluids;
this.te=te;
this.fd=fd;
}T te;ForgeDirection fd; private final InventoryAdaptor invItems;
}
T te;

ForgeDirection fd; private final InventoryAdaptor invItems;
private final IFluidHandler invFluids;
@Override
public Iterator<ItemSlot> iterator() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.Queue;
import java.util.function.Consumer;
Expand All @@ -33,6 +34,7 @@
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Blocks;
import net.minecraft.inventory.Slot;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.launchwrapper.Launch;
import net.minecraft.nbt.JsonToNBT;
Expand All @@ -51,8 +53,11 @@
import net.minecraftforge.fluids.IFluidTank;
import net.minecraftforge.oredict.OreDictionary;

import com.google.common.collect.HashMultimap;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Multimap;
import com.google.common.collect.Multiset;
import com.gtnewhorizons.modularui.api.ModularUITextures;
import com.gtnewhorizons.modularui.api.drawable.IDrawable;
import com.gtnewhorizons.modularui.api.drawable.ItemDrawable;
Expand Down Expand Up @@ -81,7 +86,6 @@
import com.gtnewhorizons.modularui.common.widget.SlotWidget;
import com.gtnewhorizons.modularui.common.widget.SyncedWidget;
import com.gtnewhorizons.modularui.common.widget.TextWidget;

import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
Expand Down Expand Up @@ -225,6 +229,7 @@ public BufferedDualInputHatch(String aName, int aTier, int aSlots, String[] aDes

public class DualInvBuffer implements IDualInputInventory {
public long tickFirstClassify=-1;

protected FluidTank[] mStoredFluidInternal;
protected ItemStack[] mStoredItemInternal;
protected FluidTank[] mStoredFluidInternalSingle;
Expand Down Expand Up @@ -451,18 +456,7 @@ private boolean isItemStackEqualIngoreAmount(ItemStack p_77959_1_,ItemStack thiz
return false ? false : (thiz.getItem() != p_77959_1_.getItem() ? false : (thiz.getItemDamage() != p_77959_1_.getItemDamage() ? false : (thiz.stackTagCompound == null && p_77959_1_.stackTagCompound != null ? false : thiz.stackTagCompound == null || thiz.stackTagCompound.equals(p_77959_1_.stackTagCompound))));
}

private boolean fluidEquals(FluidTank a, FluidTank b) {
// if(a==b)return false;
// if(a==null||b==null)return false;
if (a.getFluidAmount() != b.getFluidAmount())
return false;
if (a.getFluid() == null && a.getFluid() == null)
return true;
if (a.getFluid() != null && (!a.getFluid().equals(b.getFluid())))
return false;

return true;
}


/**
* classify() with less check, for better performance
Expand Down Expand Up @@ -1533,7 +1527,7 @@ public void getWailaBody(ItemStack itemStack, List<String> currenttip, IWailaDat
+tag.getInteger("sleepTime")

);

int idle[]=new int[1];
IntStream.range(0, tag.getInteger("inv_size")).forEach(s -> {
NBTTagCompound sub = (NBTTagCompound) tag.getTag("No" + s);
boolean noClear = sub.getBoolean("noClear");
Expand All @@ -1548,6 +1542,8 @@ public void getWailaBody(ItemStack itemStack, List<String> currenttip, IWailaDat
info = LangManager.translateToLocal("programmable_hatches.buffer.waila.001");
break;
case 0b010:
idle[0]++;
if(idle[0]>5)return;
info = LangManager.translateToLocal("programmable_hatches.buffer.waila.010");
break;
case 0b011:
Expand Down Expand Up @@ -1599,8 +1595,9 @@ public void getWailaBody(ItemStack itemStack, List<String> currenttip, IWailaDat
Arrays.stream(lock_fluid.split("\n")).map(ss -> " " + ss).forEach(currenttip::add);

});

;
if(idle[0]>5)
currenttip.add(LangManager.translateToLocalFormatted("programmable_hatches.buffer.waila.hidden",(idle[0]-5)+""));

}

Expand All @@ -1620,6 +1617,13 @@ public void updateSlots() {

@Override
public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) {

mergeSame().forEachRemaining(s->{

System.out.println(s);


});
BaseMetaTileEntity tile = (BaseMetaTileEntity) this.getBaseMetaTileEntity();
if (tile.isServerSide()) {
if (!tile.privateAccess() || aPlayer.getDisplayName().equalsIgnoreCase(tile.getOwnerName())) {
Expand Down Expand Up @@ -1709,11 +1713,153 @@ public boolean isInputEmpty() {
}
return true;
}
@Override
/*@Override
public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer, ForgeDirection side,
float aX, float aY, float aZ) {
return super.onRightclick(aBaseMetaTileEntity, aPlayer, side, aX, aY, aZ);
}
}*/
@SuppressWarnings("unchecked")
public Iterator<? extends IDualInputInventory> mergeSame(){


class Wrapper{
DualInvBuffer d;
public Wrapper(DualInvBuffer s) {
d=s;
}

@Override
public int hashCode() {
int hash=0;
for(int i=0;i<d.mStoredFluidInternalSingle.length;i++){
FluidStack f=d.mStoredFluidInternalSingle[i].getFluid();
if(f!=null)
hash^= f.hashCode();
int a=hash&1;
hash=hash>>>1;
if(a!=0)hash|=0x80000000;
}
for(int i=0;i<d.mStoredItemInternalSingle.length;i++){
ItemStack f=d.mStoredItemInternalSingle[i];
if(f!=null){
hash^=
f.stackSize*31+
+Item.getIdFromItem(f.getItem());
if(f.getTagCompound()!=null){
hash^=f.getTagCompound().hashCode();
}
}
int a=hash&1;
hash=hash>>>1;
if(a!=0)hash|=0x80000000;
}

return hash;
}

@Override
public boolean equals(Object obj) {
if(obj==this){return true;}
boolean empty=true;
DualInvBuffer a=d;
DualInvBuffer b=((Wrapper) obj).d;
for(int i=0;i<a.mStoredFluidInternalSingle.length;i++){
if(!fluidEquals(
a.mStoredFluidInternalSingle[i],
b.mStoredFluidInternalSingle[i])
){return false;}
if(a.mStoredFluidInternalSingle[i].getFluidAmount()>0)
empty=false;

}
for(int i=0;i<a.mStoredItemInternalSingle.length;i++){
if(!ItemStack.areItemStacksEqual(
a.mStoredItemInternalSingle[i],
b.mStoredItemInternalSingle[i])
){return false;}
if(a.mStoredItemInternalSingle[i]!=null)
empty=false;

}
if(empty)return false;
return true;
}

}



Multimap<Wrapper,DualInvBuffer> a=HashMultimap
.create();
inv0.stream().filter((DualInvBuffer::isAccessibleForMulti))
.forEach(
s->{
a.put(new Wrapper(s), s);
}
);
return (Iterator<? extends IDualInputInventory>) a.asMap().values().stream().map(
s->{
return new IDualInputInventory(){
void init(){
Iterator<DualInvBuffer> itr = s.iterator();
int icount=0;
ItemStack[][] idata=new ItemStack[s.size()][];
int fcount=0;
FluidStack[][] fdata=new FluidStack[s.size()][];
for(int i=0;i<s.size();i++){
DualInvBuffer e = itr.next();
idata[i]=e.getItemInputs();
icount+=idata[i].length;
fdata[i]=e.getFluidInputs();
fcount+=fdata[i].length;
}
i=new ItemStack[icount];
f=new FluidStack[fcount];
int ic=0;
for(ItemStack[] ii:idata){
for(ItemStack iii:ii){
i[ic]=iii;
ic++;
}
}
ic=0;
for(FluidStack[] ii:fdata){
for(FluidStack iii:ii){
f[ic]=iii;
ic++;
}
}

}
ItemStack[] i;
FluidStack[] f;
@Override
public ItemStack[] getItemInputs() {
if(i==null)init();

return i;
}

@Override
public FluidStack[] getFluidInputs() {
if(f==null)init();
return f;
}};
}
).iterator();
}

static public boolean fluidEquals(FluidTank a, FluidTank b) {
// if(a==b)return false;
// if(a==null||b==null)return false;
if (a.getFluidAmount() != b.getFluidAmount())
return false;
if (a.getFluid() == null && a.getFluid() == null)
return true;
if (a.getFluid() != null && (!a.getFluid().equals(b.getFluid())))
return false;

return true;
}
}
Loading

0 comments on commit e0449b1

Please sign in to comment.