Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
reobf committed Jun 10, 2024
1 parent 4603d3b commit 39fee96
Show file tree
Hide file tree
Showing 16 changed files with 821 additions and 52 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.15p4'
String versionOverride = '0.0.15p5'
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 @@ -1180,7 +1180,23 @@ public boolean justUpdated() {
justHadNewItems = false;
return ret;
}

class PiorityBuffer implements Comparable<PiorityBuffer>{
PiorityBuffer(DualInvBuffer buff){this.buff=buff;
this.piority=getPossibleCopies(buff);
}
DualInvBuffer buff;
int piority;
@Override
public String toString() {
return ""+piority;
}
@Override
public int compareTo(PiorityBuffer o) {

return -piority+o.piority;
}

}
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public Optional</* ? extends */IDualInputInventory> getFirstNonEmptyInventory() {
Expand All @@ -1189,23 +1205,7 @@ public boolean justUpdated() {

if(Config.experimentalOptimize){

class PiorityBuffer implements Comparable<PiorityBuffer>{
PiorityBuffer(DualInvBuffer buff){this.buff=buff;
this.piority=getPossibleCopies(buff);
}
DualInvBuffer buff;
int piority;
@Override
public String toString() {
return ""+piority;
}
@Override
public int compareTo(PiorityBuffer o) {

return -piority+o.piority;
}

}


return (Optional) inv0.stream().filter(DualInvBuffer::isAccessibleForMulti)
.map(s->new PiorityBuffer(s))
Expand All @@ -1230,7 +1230,15 @@ private Predicate<DualInvBuffer> not(Predicate<DualInvBuffer> s) {
public Iterator<? extends IDualInputInventory> inventories() {
markDirty();
dirty=true;

if(Config.experimentalOptimize){
return inv0.stream().filter(DualInvBuffer::isAccessibleForMulti)
.map(s->new PiorityBuffer(s))
.sorted().map(s->{return s.buff;}).iterator();
// return inv0.stream().filter(DualInvBuffer::isAccessibleForMulti).iterator();
}
return inv0.stream().filter(DualInvBuffer::isAccessibleForMulti).iterator();

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ public boolean pushPattern(ICraftingPatternDetails patternDetails, InventoryCraf

} else {
items++;
if (items > 4) {
if (items > 16) {
clearInv();
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import gregtech.api.render.TextureFactory;
import gregtech.api.util.GT_Utility;
import gregtech.common.tileentities.machines.IRecipeProcessingAwareHatch;
import reobf.proghatches.gt.metatileentity.util.RecursiveLinkExcpetion;
import reobf.proghatches.lang.LangManager;
import reobf.proghatches.main.MyMod;
import reobf.proghatches.main.registration.Registration;
Expand Down Expand Up @@ -102,7 +103,11 @@ public void onLeftclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aP
this.x = x;
this.y = y;
this.z = z;

if(this.getBaseMetaTileEntity().getWorld().getChunkProvider().chunkExists(x >> 4, z >> 4) == false){
aPlayer.addChatMessage(new ChatComponentTranslation("programmable_hatches.remote.deferred"));
this.linked = true;
return;
}
if (checkBlackList()
// blacklist.contains(this.getBaseMetaTileEntity().getWorld().getBlock(x,
// y, z).getUnlocalizedName())
Expand Down Expand Up @@ -179,6 +184,8 @@ public void addUIWidgets(Builder builder, UIBuildContext buildContext) {

if (opt.isPresent() == false)
return LangManager.translateToLocal("programmable_hatches.remote.nothing");
else
checkBlackList();
if (opt.get() instanceof IInventory == false) {
return LangManager.translateToLocal("programmable_hatches.remote.dummytarget");

Expand Down Expand Up @@ -315,6 +322,7 @@ public boolean checkDepth() {
private int count;

public boolean checkDepthLoose() {
if(2>1){return false;}
if (count++ < 40)
return false;
count = 0;
Expand All @@ -323,6 +331,8 @@ public boolean checkDepthLoose() {

@Override
public int getSizeInventory() {
try(AutoCloseable o=mark()){

if (!processingRecipe)
return 1;
// justQueried=true;
Expand All @@ -332,14 +342,21 @@ public int getSizeInventory() {
}
if (!linked)
return 1;
if (checkDepthLoose()) {
/*if (checkDepthLoose()) {
getBaseMetaTileEntity().getWorld().setBlockToAir(this.x, this.y, this.z);
return 0;
}
}*/

return opt.filter(s -> s instanceof IInventory).map(s -> ((IInventory) s).getSizeInventory()).orElse(0) + 2;

}
catch (RecursiveLinkExcpetion e) {
return 0;
}
catch (Exception e) {
e.printStackTrace();
return 0;
}
}
@Override
public int[] getAccessibleSlotsFromSide(int ordinalSide) {
Expand All @@ -363,16 +380,16 @@ public void setInventorySlotContents(int aIndex, ItemStack aStack) {
@Override
@Nullable
public ItemStack getStackInSlot(int aIndex) {

try(AutoCloseable o=mark()){
// justQueried=true;
Optional<TileEntity> opt = getTile();
if (opt.isPresent() && checkBlackList(opt)) {
this.linked = false;
}
if (checkDepthLoose()) {
/*if (checkDepthLoose()) {
getBaseMetaTileEntity().getWorld().setBlockToAir(this.x, this.y, this.z);
return null;
}
}*/
if(aIndex == getCircuitSlot()){
return mInventory[0];
}
Expand Down Expand Up @@ -408,7 +425,14 @@ public ItemStack getStackInSlot(int aIndex) {

return arr.get(aIndex);
// }catch(Exception e){e.printStackTrace();return null;}

}
catch (RecursiveLinkExcpetion e) {
return null;
}
catch (Exception e) {
e.printStackTrace();
return null;
}
}

@Override
Expand Down Expand Up @@ -520,5 +544,13 @@ protected void validateSlotIndex(int slot) {

};
}

private static HashSet<Object> record=new HashSet<>();
public AutoCloseable mark(){
if(!record.add(this)){
getBaseMetaTileEntity().getWorld().setBlockToAir(this.x, this.y, this.z);
throw new RecursiveLinkExcpetion();
};

return ()->{record.remove(this);};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import static gregtech.api.enums.Textures.BlockIcons.FLUID_IN_SIGN;

import java.io.Closeable;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
Expand All @@ -16,12 +18,15 @@
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ChatComponentTranslation;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTankInfo;
import net.minecraftforge.fluids.IFluidHandler;

import com.gtnewhorizons.modularui.api.screen.ModularWindow.Builder;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.gtnewhorizons.modularui.api.screen.UIBuildContext;
import com.gtnewhorizons.modularui.common.widget.TextWidget;
Expand All @@ -37,6 +42,7 @@
import gregtech.api.recipe.check.CheckRecipeResultRegistry;
import gregtech.api.render.TextureFactory;
import gregtech.common.tileentities.machines.IRecipeProcessingAwareHatch;
import reobf.proghatches.gt.metatileentity.util.RecursiveLinkExcpetion;
import reobf.proghatches.lang.LangManager;
import reobf.proghatches.main.MyMod;
import reobf.proghatches.main.registration.Registration;
Expand Down Expand Up @@ -94,7 +100,11 @@ public void onLeftclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aP
this.x = x;
this.y = y;
this.z = z;

if(this.getBaseMetaTileEntity().getWorld().getChunkProvider().chunkExists(x >> 4, z >> 4) == false){
aPlayer.addChatMessage(new ChatComponentTranslation("programmable_hatches.remote.deferred"));
this.linked = true;
return;
}
if (checkBlackList()
// blacklist.contains(this.getBaseMetaTileEntity().getWorld().getBlock(x,
// y, z).getUnlocalizedName())
Expand Down Expand Up @@ -176,6 +186,8 @@ public void addUIWidgets(Builder builder, UIBuildContext buildContext) {

if (opt.isPresent() == false)
return LangManager.translateToLocal("programmable_hatches.remote.nothing");
else
checkBlackList();
if (opt.get() instanceof IFluidHandler == false) {
return LangManager.translateToLocal("programmable_hatches.remote.dummytarget");

Expand Down Expand Up @@ -215,8 +227,60 @@ public Optional<TileEntity> getTile() {
}
return Optional.ofNullable(this.getBaseMetaTileEntity().getWorld().getTileEntity(x, y, z));
}
@Override
public FluidStack getFluid(int aSlot) {
try(AutoCloseable o=mark()){
Optional<TileEntity> opt = getTile();
if (opt.isPresent() && checkBlackList(opt)) {
this.linked = false;
}
/*if (checkDepthLoose()) {
getBaseMetaTileEntity().getWorld().setBlockToAir(this.x, this.y, this.z);
return null;
}*/

return getTile().map(this::filterTakable)
.map(s->{
if(aSlot<0||aSlot>=s.size())return null;
return s.get(aSlot);
}).orElse(null);
}
catch (RecursiveLinkExcpetion e) {
return null;
}
catch (Exception e) {
e.printStackTrace();
return null;
}
}
@Override
public FluidStack getFillableStack() {
try(AutoCloseable o=mark()){
Optional<TileEntity> opt = getTile();
if (opt.isPresent() && checkBlackList(opt)) {
this.linked = false;
}
/*if (checkDepthLoose()) {
getBaseMetaTileEntity().getWorld().setBlockToAir(this.x, this.y, this.z);
return null;
}*/

return getTile().map(this::filterTakable)
.filter(s->s.size()>=1)
.orElseGet(()->ImmutableList.of(null)).get(0);
}
catch (RecursiveLinkExcpetion e) {
return null;
}
catch (Exception e) {
e.printStackTrace();
return null;
}


public List<? extends FluidStack> filterTakable(TileEntity e) {
}
@SuppressWarnings("unchecked")
public List<FluidStack> filterTakable(TileEntity e) {

if (processingRecipe == false)
return new ArrayList<FluidStack>();
Expand All @@ -242,7 +306,7 @@ public List<? extends FluidStack> filterTakable(TileEntity e) {
// }
ArrayList<ShadowFluidStack> arrm = new ArrayList<>(slots);
tmp = arrm;
return arrm;
return (List<FluidStack>)(Object)arrm;
}

return new ArrayList<>();
Expand Down Expand Up @@ -318,12 +382,26 @@ public boolean checkDepth() {
private int count;

public boolean checkDepthLoose() {
if(2>1)return false;


if (count++ < 40)
return false;
count = 0;
return checkDepth();
}



private static HashSet<Object> record=new HashSet<>();

public AutoCloseable mark(){
if(!record.add(this)){
getBaseMetaTileEntity().getWorld().setBlockToAir(this.x, this.y, this.z);
throw new RecursiveLinkExcpetion();
};

return ()->{record.remove(this);};
}
@Override
public int getSizeInventory() {

Expand All @@ -348,20 +426,29 @@ public void updateSlots() {

@Override
public FluidStack[] getStoredFluid() {

try(AutoCloseable o=mark()){
Optional<TileEntity> opt = getTile();
if (opt.isPresent() && checkBlackList(opt)) {
this.linked = false;
}
if (checkDepthLoose()) {
/*if (checkDepthLoose()) {
getBaseMetaTileEntity().getWorld().setBlockToAir(this.x, this.y, this.z);
return new FluidStack[0];
}
}*/

return getTile().map(this::filterTakable).orElse(new ArrayList<>()).toArray(new FluidStack[0]);

}
catch (RecursiveLinkExcpetion e) {
return new FluidStack[0];
}
catch (Exception e) {
e.printStackTrace();
return new FluidStack[0];
}


}

protected boolean processingRecipe = false;

@Override
Expand Down
Loading

0 comments on commit 39fee96

Please sign in to comment.