forked from xsun2001/Applied-Energistics-2-Unofficial
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement controller based crafting CPU
fixes xsun2001#8
- Loading branch information
Showing
8 changed files
with
267 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
137 changes: 137 additions & 0 deletions
137
src/main/java/appeng/me/cluster/implementations/InternalCraftingCPU.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
package appeng.me.cluster.implementations; | ||
|
||
import appeng.api.networking.IGrid; | ||
import appeng.api.networking.crafting.ICraftingGrid; | ||
import appeng.api.networking.energy.IEnergyGrid; | ||
import appeng.api.networking.security.BaseActionSource; | ||
import appeng.api.networking.security.MachineSource; | ||
import appeng.me.GridAccessException; | ||
import appeng.me.cache.CraftingGridCache; | ||
import appeng.tile.legacy.TileLegacyController; | ||
import net.minecraft.world.World; | ||
|
||
public class InternalCraftingCPU extends AbstractCraftingCPU { | ||
|
||
private TileLegacyController controller; | ||
private MachineSource actionSource; | ||
private boolean isDestroyed = false; | ||
private final int[] usedOps = new int[3]; | ||
private int cpuNum; | ||
|
||
public InternalCraftingCPU(TileLegacyController controller, int cpuNum) { | ||
this.controller = controller; | ||
this.actionSource = new MachineSource(controller); | ||
this.cpuNum = cpuNum; | ||
} | ||
|
||
@Override | ||
public BaseActionSource getActionSource() { | ||
return this.actionSource; | ||
} | ||
|
||
@Override | ||
public long getAvailableStorage() { | ||
return Long.MAX_VALUE; | ||
} | ||
|
||
@Override | ||
public int getCoProcessors() { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "Controller #" + this.cpuNum; | ||
} | ||
|
||
public void updateCPUNum(int num) { | ||
this.cpuNum = num; | ||
} | ||
|
||
@Override | ||
public void updateCraftingLogic(IGrid grid, IEnergyGrid eg, ICraftingGrid cc) { | ||
if (!this.isActive()) { | ||
return; | ||
} | ||
|
||
if (this.myLastLink != null) { | ||
if (this.myLastLink.isCanceled()) { | ||
this.myLastLink = null; | ||
this.cancel(); | ||
} | ||
} | ||
|
||
if (this.isComplete) { | ||
if (this.inventory.getItemList().isEmpty()) { | ||
return; | ||
} | ||
|
||
this.storeItems(); | ||
return; | ||
} | ||
|
||
this.waiting = false; | ||
if (this.waiting || this.tasks.isEmpty()) // nothing to do here... | ||
{ | ||
return; | ||
} | ||
|
||
this.remainingOperations = 1 | ||
- (this.usedOps[0] + this.usedOps[1] + this.usedOps[2]); | ||
final int started = this.remainingOperations; | ||
|
||
if (this.remainingOperations > 0) { | ||
do { | ||
this.somethingChanged = false; | ||
this.executeCrafting(eg, (CraftingGridCache)cc); | ||
} while (this.somethingChanged && this.remainingOperations > 0); | ||
} | ||
this.usedOps[2] = this.usedOps[1]; | ||
this.usedOps[1] = this.usedOps[0]; | ||
this.usedOps[0] = started - this.remainingOperations; | ||
|
||
if (this.remainingOperations > 0 && !this.somethingChanged) { | ||
this.waiting = true; | ||
} | ||
} | ||
|
||
@Override | ||
public boolean isActive() { | ||
return this.controller.getProxy().isActive(); | ||
} | ||
|
||
@Override | ||
public boolean isDestroyed() { | ||
return this.isDestroyed; | ||
} | ||
|
||
public void destroy() { | ||
this.isDestroyed = true; | ||
} | ||
|
||
@Override | ||
protected IGrid getGrid() { | ||
try { | ||
return controller.getProxy().getGrid(); | ||
} catch (GridAccessException e) { | ||
return null; | ||
} | ||
} | ||
|
||
@Override | ||
protected void markDirty() { | ||
controller.markDirty(); | ||
|
||
} | ||
|
||
@Override | ||
protected void updateCPU() { | ||
|
||
} | ||
|
||
@Override | ||
protected World getWorld() { | ||
return controller.getWorldObj(); | ||
} | ||
|
||
} |
Oops, something went wrong.