Skip to content

Commit

Permalink
EU Crafting update
Browse files Browse the repository at this point in the history
  • Loading branch information
reobf committed Apr 11, 2024
1 parent acd01c6 commit 81c4644
Show file tree
Hide file tree
Showing 15 changed files with 180 additions and 91 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ catch (Exception ignored) {

// Pulls version first from the VERSION env and then git tag
String identifiedVersion = null
String versionOverride = '0.0.9'
String versionOverride = '0.0.10'
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
25 changes: 22 additions & 3 deletions src/main/java/reobf/proghatches/eucrafting/IEUManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ public interface IEUManager extends IGridCache{
public interface ISource{
public long getVoltage();
public void reset();
/*public long request(long amp);
public void refund(long amp);
public long providing();*/

//directly get EU token
public long request(long packets);


}
public void refund(UUID id,long amount);
public long request(long v,long packets);
public interface IDrain{
public default boolean isP2POut(){return false;}
public long getVoltage();
Expand Down Expand Up @@ -156,6 +158,23 @@ public void refund(UUID id, long amount) {



}


@Override
public long request(long v, long packets) {
long req=packets;

for(ISource s:cache2){

if(s.getVoltage()!=v) continue;
packets-=s.request(packets);
if(packets==0)break;
};



return req-packets;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -457,13 +457,13 @@ public TickRateModulation tickingRequest(IGridNode node, int ticksSinceLastCall)

if(refund(inv,store)){

((CraftingCPUCluster)cluster).addCrafting(new PatternDetail(blank_token.copy(),
/* ((CraftingCPUCluster)cluster).addCrafting(new PatternDetail(blank_token.copy(),
token.copy()), prevamp);
((CraftingCPUCluster)cluster).addEmitable(AEItemStack.create(blank_token.copy()).setStackSize(prevamp));
redstoneticks=0;
*/redstoneticks=0;
amp=0;
break;
}
Expand Down Expand Up @@ -1416,6 +1416,9 @@ public void refund(long amp) {

}


@Override
public ItemStack getCrafterIcon() {
return new ItemStack(MyMod.euinterface_p2p);
}

}
9 changes: 9 additions & 0 deletions src/main/java/reobf/proghatches/eucrafting/PartEUSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -712,4 +712,13 @@ public ItemStack getCrafterIcon() {
return new ItemStack(MyMod.eu_source_part).setStackDisplayName(this.voltage + "V");
}

@Override
public long request(long packets) {
long free=amp-consumed ;
long actual=Math.min(free, packets);
consumed+=actual;

return actual;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ public int hashCode() {
}


ICraftingPatternDetails original;
public final ICraftingPatternDetails original;
public final IAEItemStack extraIn;
public final IAEItemStack extraOut;
public final ItemStack extraIn0;
Expand Down Expand Up @@ -1072,7 +1072,8 @@ public void refund(long amp) {
this.amp-=amp;

}



@Override
public ItemStack getCrafterIcon() {
return new ItemStack(MyMod.block_euinterface);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.Fluid;
import reobf.proghatches.gt.cover.WirelessControlCover.Data;

@Deprecated
public class RecipeCheckResultCover extends GT_CoverBehaviorBase<RecipeCheckResultCover.Data> {

public RecipeCheckResultCover() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.FluidStack;

@Deprecated
public class RecipeOutputAwarenessCover extends GT_CoverBehavior{
@Override
public int getTickRate(ForgeDirection side, int aCoverID, int aCoverVariable, ICoverable aTileEntity) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.util.ForgeDirection;
import reobf.proghatches.main.registration.Registration;

@Deprecated
public class RecipeCheckResultDetector extends GT_MetaTileEntity_Hatch_InputBus
implements IRecipeProcessingAwareHatch
{
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/reobf/proghatches/main/MyMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public class MyMod {
// preInit "Run before anything else. Read your config, create blocks, items, etc, and register them with the
// GameRegistry." (Remove if not needed)
public void preInit(FMLPreInitializationEvent event) {
CraftingCPUCluster.class.getFields();
//CraftingCPUCluster.class.getFields();
net.registerMessage(new OpenPartGuiMessage.Handler(), OpenPartGuiMessage.class, 0, Side.CLIENT);
proxy.preInit(event);
}
Expand Down
16 changes: 11 additions & 5 deletions src/main/java/reobf/proghatches/main/mixin/MixinPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,14 @@ public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) {

}
String cfg=
"#set to true to disable those optional mixins if it breaks someting"+System.lineSeparator()+
"#disable those optional mixins if it breaks someting"+System.lineSeparator()+
"#set to true to disable otherwise apply"+System.lineSeparator()+
"noPatternEncodingMixin=false"+System.lineSeparator()+
"noFixTossBug=false"+System.lineSeparator()+
"noRecipeFilterForDualHatch=false"+System.lineSeparator()+
"noRemoveUnusedCacheInModularUIContainer=fasle"+System.lineSeparator()
"noRemoveUnusedCacheInModularUIContainer=fasle"+System.lineSeparator()+
"noFixRecursiveCraft=false"+System.lineSeparator()+
"noEUCraftingMixins=false"+System.lineSeparator()
;
@SuppressWarnings("unused")
@Override
Expand Down Expand Up @@ -105,13 +108,16 @@ public List<String> getMixins() {

ArrayList<String> ret = new ArrayList<>();
ret.add("eucrafting."+"MixinWailaProvider");
ret.add("eucrafting."+"MixinRecipeStateDetect");
ret.add("eucrafting."+"MixinCpuClusterAccess");
//ret.add("eucrafting."+"MixinRecipeStateDetect");
// ret.add("eucrafting."+"MixinCpuClusterAccess");

ret.add("eucrafting."+"MixinInstantComplete");
if(!"true".equals(pp.get("noFixRecursiveCraft")))
ret.add("eucrafting."+"MixinCraftingRecursiveWorkaround");
if(!"true".equals(pp.get("noEUCraftingMixins"))){
ret.add("eucrafting."+"MixinCpuClusterEUAutoRequest");
ret.add("eucrafting."+"MixinRemoveExcessiveEU");

}

ret.add("MixinAwarenessForDualHatch");
if(!"true".equals(pp.get("noRemoveUnusedCacheInModularUIContainer")))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
package reobf.proghatches.main.mixin.mixins.eucrafting;

import java.lang.ref.WeakReference;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.UUID;
import java.util.WeakHashMap;
import java.util.function.Function;
import java.util.stream.Collectors;

Expand All @@ -29,6 +33,7 @@
import com.google.common.collect.ImmutableMap;

import appeng.api.config.Actionable;
import appeng.api.config.FuzzyMode;
import appeng.api.networking.crafting.ICraftingPatternDetails;
import appeng.api.networking.energy.IEnergyGrid;
import appeng.api.networking.security.IActionHost;
Expand All @@ -38,10 +43,12 @@
import appeng.crafting.v2.CraftingContext;
import appeng.me.cache.CraftingGridCache;
import appeng.me.cluster.implementations.CraftingCPUCluster;
import appeng.tile.crafting.TileCraftingTile;
import appeng.util.item.AEItemStack;
import appeng.util.item.HashBasedItemList;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import reobf.proghatches.eucrafting.IEUManager;
import reobf.proghatches.eucrafting.TileFluidInterface_EU.PatternDetail;
import reobf.proghatches.eucrafting.TileFluidInterface_EU.WrappedPatternDetail;
import reobf.proghatches.main.MyMod;
Expand All @@ -50,35 +57,42 @@


@Mixin(value = CraftingCPUCluster.class, remap = false, priority = 0)
public class MixinCpuClusterEUAutoRequest {
public abstract class MixinCpuClusterEUAutoRequest {
@Shadow private MachineSource machineSrc;
Map<IAEItemStack,Long> storage=new HashMap<>();
Map<IAEItemStack,Long> needed=new HashMap<>();
@Shadow private MECraftingInventory inventory;

@Shadow private final LinkedList<TileCraftingTile> tiles = new LinkedList<>();
@Shadow Map<ICraftingPatternDetails, Object> tasks;


private WeakHashMap<WrappedPatternDetail, int[]> cooldown=new WeakHashMap<>();
@Shadow abstract boolean canCraft(final ICraftingPatternDetails details, final IAEItemStack[] condensedInputs) ;
/**
if (!this.canCraft(details, details.getCondensedInputs())) {
//INJECT HERE Shift.BY.3
i.remove();
}
*/
//collect failed WrappedPatternDetail

@ModifyVariable(at = @At(value="INVOKE",target="canCraft(Lappeng/api/networking/crafting/ICraftingPatternDetails;[Lappeng/api/storage/data/IAEItemStack;)Z"
,shift=Shift.BY,by=3),method = "executeCrafting")
private ICraftingPatternDetails executeCrafting2(ICraftingPatternDetails pattern
){
){//collect failed WrappedPatternDetail
if(pattern instanceof WrappedPatternDetail){
WrappedPatternDetail p=(WrappedPatternDetail) pattern;
int cd[]=cooldown.computeIfAbsent(p, (s)->new int[1]);
if(cd[0]>0){cd[0]--;return pattern;}
boolean isOnlyEUTokenMissing=false;
//cannot craft, but original one can, means that only eu token is missing
if (this.canCraft(p.original, p.original.getCondensedInputs())) {isOnlyEUTokenMissing=true;}





needed.put(p.extraIn.copy(),p.extraIn0.stackSize+0l);

if(isOnlyEUTokenMissing)
{
needed.put(p.extraIn.copy().setStackSize(1),p.extraIn0.stackSize+0l);
cooldown.remove(p);
}
else
cooldown.get(p)[0]+=20;
}

return pattern;
Expand All @@ -91,38 +105,43 @@ private void executeCrafting3(final IEnergyGrid eg, final CraftingGridCache cc,C


}
private static AEItemStack type=AEItemStack.create(new ItemStack(MyMod.eu_token,1,1));
@Inject(at = @At("RETURN"),method = "executeCrafting",cancellable=true)
private void executeCrafting1(final IEnergyGrid eg, final CraftingGridCache cc,CallbackInfo RE
){
if(needed.isEmpty()){storage.clear();;return;}

//ArrayList<Object> arr=new ArrayList();

//inventory.getItemList().forEach(arr::add);
//System.out.println(arr);


inventory.getItemList().forEach(s->{
inventory.getItemList().findFuzzy(type, FuzzyMode.IGNORE_ALL).forEach(s->{

if(s.getItem()==MyMod.eu_token){
if(s.getItemDamage()==1){

IAEItemStack u=s.copy().setStackSize(1);
if(storage.get(u)==null){storage.put(u, 0l);};
storage.compute(u, (a,b)->b+s.getStackSize());

storage.merge(u,0l, (a,b)->a+b+s.getStackSize());
}


}

});

//System.out.println(storage);
tasks.entrySet().forEach(s->{


if(s.getKey() instanceof PatternDetail){
PatternDetail d=(PatternDetail) s.getKey();
if(d.out.getItemDamage()==1){
IAEItemStack key = d.o[0].copy().setStackSize(1);


storage.computeIfPresent(d.o[0].copy().setStackSize(1),
(a,b)->b+MixinCallback.getter.apply(s.getValue())
storage.merge(key, 0l,
(a,b)->a+b+MixinCallback.getter.apply(s.getValue())
);

}
Expand All @@ -134,19 +153,36 @@ private void executeCrafting1(final IEnergyGrid eg, final CraftingGridCache cc,C


});
//System.out.println(storage);

needed.entrySet().forEach(s->{

long num=Optional.ofNullable(storage.get(s.getKey())).orElse(0l);
long missing=s.getValue()-num;
if(missing<=0)return;
Object o=this;
//CraftingCPUCluster thiz=(CraftingCPUCluster) o;
//System.out.println(s.getValue()+" "+num);
//System.out.println(missing);

CraftingCPUCluster j;
inventory.injectItems(
s.getKey().copy().setStackSize(missing),
if(tiles.isEmpty()){return;}
try {
IEUManager man=tiles.get(0).getProxy().getGrid().getCache(IEUManager.class);
long get=man.request(
s.getKey().getTagCompound().getNBTTagCompoundCopy().getLong("voltage")
, missing);
inventory.injectItems(
s.getKey().copy().setStackSize(get),
Actionable.MODULATE,machineSrc

);
} catch (Exception e) {

e.printStackTrace();
}

/*
*/

});

Expand Down
Loading

0 comments on commit 81c4644

Please sign in to comment.