Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
reobf committed Nov 16, 2024
1 parent d3252c4 commit ba7616b
Show file tree
Hide file tree
Showing 2 changed files with 132 additions and 32 deletions.
98 changes: 79 additions & 19 deletions src/main/java/reobf/proghatches/ae/PartMAP2P.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
import java.util.List;
import java.util.function.Supplier;

import com.google.common.collect.HashMultimap;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.collect.Multimap;

import appeng.api.implementations.tiles.ICraftingMachine;
import appeng.api.networking.crafting.ICraftingPatternDetails;
Expand Down Expand Up @@ -56,38 +58,96 @@ public boolean pushPattern(ICraftingPatternDetails patternDetails, InventoryCraf
if(tick==MinecraftServer.getServer().getTickCounter()){
//same tick... try the one found in acceptsPlans!
ICraftingMachine val;
if((val=candidate.get())!=null&&val.pushPattern(patternDetails,table,ejectionDirection)){return true;}
if((val=candidate.get())!=null&&val.pushPattern(patternDetails,table,candidateDir)){return true;}
}
//direct call to pushPattern? or acceptsPlans but push failed?
//just iterate again to find another valid!
for(ICraftingMachine ep:getOuputEndpoints(null)){
if(ep.pushPattern(patternDetails,table,ejectionDirection)){return true;}
try {

for(PartMAP2P out:getOutputs()){

TileEntity te = out.getTarget();
if(te==null){continue ;}
if(te instanceof ICraftingMachine){


ICraftingMachine ep=(ICraftingMachine) te;
ForgeDirection old=StateHolder.state;
StateHolder.state=out.getSide().getOpposite();
if(ep.acceptsPlans()){
if(ep.pushPattern(patternDetails,table,out.getSide().getOpposite())){return true;}
StateHolder.state=old;
continue ;}
StateHolder.state=old;
}


};
} catch (GridAccessException e) {

}



return false;
}

ForgeDirection candidateDir;
WeakReference<ICraftingMachine> candidate=new WeakReference<>(null);
int tick;
@Override
public boolean acceptsPlans(ForgeDirection ejectionDirection) {
try{

if(chain.contains(this)){return false;}
chain.add(this);if (isOutput()) {
if(chain.contains(this)){

return false;
}
chain.add(this);

if (isOutput()) {
return false;
}
if (getFrequency() == 0) {
return false;
}

for(ICraftingMachine ep:getOuputEndpoints(null)){
if(ep.acceptsPlans()){
tick=MinecraftServer.getServer().getTickCounter();
candidate=new WeakReference<ICraftingMachine>(ep);
return true;}
try {
for(PartMAP2P out:getOutputs()){

TileEntity te = out.getTarget();
if(te==null){continue;}
/*if(te instanceof IPartHost){
//shortcut fot recursive p2p
IPart p=((IPartHost) te).getPart(side.getOpposite());
if( p instanceof PartMAP2P){
((PartMAP2P)p).getOuputEndpoints(fret);
return;
}
}*/
if(te instanceof ICraftingMachine){


ICraftingMachine ep=(ICraftingMachine) te;
ForgeDirection old=StateHolder.state;
StateHolder.state=out.getSide().getOpposite();
if(ep.acceptsPlans()){
tick=MinecraftServer.getServer().getTickCounter();
candidate=new WeakReference<ICraftingMachine>(ep);
candidateDir=out.getSide().getOpposite();
StateHolder.state=old;
return true ;}
StateHolder.state=old;
}


};
} catch (GridAccessException e) {

}



return false;}finally{
chain.remove(this);
}
Expand All @@ -110,14 +170,14 @@ private TileEntity getTarget() {


public static HashSet<Object> chain=new HashSet();
public Collection<ICraftingMachine> getOuputEndpoints(Collection<ICraftingMachine> ret) {
/*public Multimap<ICraftingMachine,ForgeDirection> getOuputEndpoints(Multimap<ICraftingMachine,ForgeDirection> ret) {
try{
if(ret==null)
ret=new LinkedList<>();
ret=HashMultimap.create();
if(chain.contains(this)){return ret;}
chain.add(this);
final Collection<ICraftingMachine> fret=ret;
final Multimap<ICraftingMachine,ForgeDirection> fret=ret;
try {
getOutputs().forEach((out)->{
Expand All @@ -135,10 +195,10 @@ public Collection<ICraftingMachine> getOuputEndpoints(Collection<ICraftingMachin
}
if(te instanceof ICraftingMachine){
ForgeDirection old=StateHolder.state;
StateHolder.state=out.getSide().getOpposite();
fret.add((ICraftingMachine) te);
StateHolder.state=old;
//ForgeDirection old=StateHolder.state;
//StateHolder.state=out.getSide().getOpposite();
fret.put((ICraftingMachine) te,out.getSide().getOpposite());
//StateHolder.state=old;
}
Expand All @@ -154,7 +214,7 @@ public Collection<ICraftingMachine> getOuputEndpoints(Collection<ICraftingMachin
return ret;}finally{
chain.remove(this);
}
}
}*/

@Override
@SideOnly(Side.CLIENT)
Expand Down
66 changes: 53 additions & 13 deletions src/main/java/reobf/proghatches/eio/MAConduit.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,20 +160,20 @@ public IIcon getTransmitionTextureForState(CollidableComponent component) {

int tick;


ForgeDirection candidateDir;
private WeakReference<ICraftingMachine> candidate=new WeakReference<>(null);;
@Override
public boolean pushPattern(ICraftingPatternDetails patternDetails, InventoryCrafting table,
ForgeDirection ejectionDirection) {

if(this.net==null)return false;
try{

if(PartMAP2P.chain.contains(this)){return false;}
PartMAP2P.chain.add(this);
if(PartMAP2P.chain.contains(this.net)){return false;}
PartMAP2P.chain.add(this.net);

if(tick==MinecraftServer.getServer().getTickCounter()){
ICraftingMachine val;
if((val=candidate.get())!=null&&val.pushPattern(patternDetails,table,ejectionDirection)){return true;}
if((val=candidate.get())!=null&&val.pushPattern(patternDetails,table,candidateDir)){return true;}
}

if(( getExternalConnections().contains(StateHolder.state))&&
Expand All @@ -192,7 +192,7 @@ public boolean pushPattern(ICraftingPatternDetails patternDetails, InventoryCraf
if(te instanceof ICraftingMachine){
ForgeDirection old=StateHolder.state;
StateHolder.state=ent.getValue().getOpposite();
if(((ICraftingMachine) te).pushPattern(patternDetails, table, ejectionDirection)){
if(((ICraftingMachine) te).pushPattern(patternDetails, table, ent.getValue().getOpposite())){
StateHolder.state=old;
return true;
}
Expand Down Expand Up @@ -222,7 +222,7 @@ public boolean pushPattern(ICraftingPatternDetails patternDetails, InventoryCraf

}finally{

PartMAP2P.chain.remove(this);
PartMAP2P.chain.remove(this.net);
}
}
private TileEntity getTarget(TileEntity thiz,ForgeDirection side) {
Expand All @@ -241,13 +241,16 @@ private TileEntity getTarget(TileEntity thiz,ForgeDirection side) {

@Override
public boolean acceptsPlans() {

if(this.net==null)return false;
//System.out.println(StateHolder.state);
//System.out.println(getConnectionMode(StateHolder.state).acceptsInput());
try{

if(PartMAP2P.chain.contains(this)){return false;}
PartMAP2P.chain.add(this);
if(PartMAP2P.chain.contains(this.net)){

return false;
}
PartMAP2P.chain.add(this.net);



Expand All @@ -272,7 +275,7 @@ public boolean acceptsPlans() {

tick=MinecraftServer.getServer().getTickCounter();
candidate=new WeakReference<ICraftingMachine>((ICraftingMachine) te);

candidateDir=ent.getValue().getOpposite();


return true;
Expand Down Expand Up @@ -303,7 +306,7 @@ public boolean acceptsPlans() {

}finally{

PartMAP2P.chain.remove(this);
PartMAP2P.chain.remove(this.net);
}
}

Expand Down Expand Up @@ -340,10 +343,20 @@ public TileEntity getTE(){
public void externalConnectionAdded(ForgeDirection fromDirection) {
super.externalConnectionAdded(fromDirection);
ConnectionMode mode=ConnectionMode.DISABLED;


TileEntity te = getLocation().getLocation(fromDirection).getTileEntity(getTE().getWorldObj());
int bit=0;
if(clz.isInstance(te)){
setConnectionMode(fromDirection, ConnectionMode.DISABLED);
return ;}

int bit=0;
if (te instanceof ICraftingMachine) {
StateHolder.state=fromDirection.getOpposite();
if(((ICraftingMachine)te).acceptsPlans())
bit=bit|1;


}
if (te instanceof IInterfaceHost) {
bit=bit|2;
Expand All @@ -352,6 +365,21 @@ public void externalConnectionAdded(ForgeDirection fromDirection) {

if (((IPartHost)te).getPart(fromDirection.getOpposite()) instanceof IInterfaceHost)
bit=bit|2;

if (((IPartHost)te).getPart(fromDirection.getOpposite()) instanceof PartMAP2P)
{
PartMAP2P p2p=(PartMAP2P) ((IPartHost)te).getPart(fromDirection.getOpposite());
if(p2p.output){

bit=bit|2;
}else{
bit=bit|1;

}

}


}

if(bit==1)mode=ConnectionMode.OUTPUT;
Expand All @@ -361,10 +389,22 @@ public void externalConnectionAdded(ForgeDirection fromDirection) {
setConnectionMode(fromDirection, mode);

}

static Class clz;
static{try {
clz=Class.forName("crazypants.enderio.conduit.IConduitBundle");
} catch (ClassNotFoundException e) {e.printStackTrace();

}}
@Override
public boolean canConnectToExternal(ForgeDirection direction, boolean ignoreConnectionMode) {
TileEntity te = getLocation().getLocation(direction).getTileEntity(getTE().getWorldObj());

if(clz.isInstance(te)){

return false;}


ignoreConnectionMode=true;
a:if (te instanceof ICraftingMachine) {
if(ignoreConnectionMode==false&&!getConnectionMode(direction).acceptsOutput()){break a;}
Expand Down

0 comments on commit ba7616b

Please sign in to comment.