Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/smarter' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Dream-Master committed Jan 21, 2025
2 parents 39bce71 + 414e45c commit 0ee77ed
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package appeng.api.networking.events;

import appeng.helpers.IInterfaceHost;

public class MENetworkCraftingPushedPattern extends MENetworkEvent {

public final IInterfaceHost host;

public MENetworkCraftingPushedPattern(final IInterfaceHost host) {
this.host = host;
}

}
85 changes: 72 additions & 13 deletions src/main/java/appeng/helpers/DualityInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import appeng.api.networking.crafting.ICraftingProviderHelper;
import appeng.api.networking.energy.IEnergySource;
import appeng.api.networking.events.MENetworkCraftingPatternChange;
import appeng.api.networking.events.MENetworkCraftingPushedPattern;
import appeng.api.networking.security.BaseActionSource;
import appeng.api.networking.security.IActionHost;
import appeng.api.networking.security.MachineSource;
Expand Down Expand Up @@ -86,6 +87,7 @@
import appeng.tile.inventory.AppEngInternalInventory;
import appeng.tile.inventory.IAEAppEngInventory;
import appeng.tile.inventory.InvOperation;
import appeng.tile.networking.TileCableBus;
import appeng.util.ConfigManager;
import appeng.util.IConfigManagerHost;
import appeng.util.InventoryAdaptor;
Expand Down Expand Up @@ -885,6 +887,47 @@ private boolean inventoryCountsAsEmpty(TileEntity te, InventoryAdaptor ad, Forge
return isEmpty;
}

public void notifyPushedPattern(IInterfaceHost pushingHost) {
if (this.getInstalledUpgrades(Upgrades.ADVANCED_BLOCKING) == 0) return;
final TileEntity tile = this.iHost.getTileEntity();
final World w = tile.getWorldObj();

final EnumSet<ForgeDirection> possibleDirections = this.iHost.getTargets();

for (ForgeDirection s : possibleDirections) {
final TileEntity te = w
.getTileEntity(tile.xCoord + s.offsetX, tile.yCoord + s.offsetY, tile.zCoord + s.offsetZ);
if (te == null) continue;
try {
if (te instanceof IInterfaceHost host) {

if (host.getInterfaceDuality().sameGrid(this.gridProxy.getGrid())) {
continue;
}
if (host == pushingHost) {
continue;
}
host.getInterfaceDuality().receivePatternPushedEvent();

} else if (te instanceof TileCableBus cableBus) {
IPart part = cableBus.getPart(s.getOpposite());
if (part instanceof IInterfaceHost host) {
if (host == pushingHost) {
continue;
}
host.getInterfaceDuality().receivePatternPushedEvent();
}
}
} catch (final GridAccessException e) {
continue;
}
}
}

public void receivePatternPushedEvent() {
this.lastInputHash = 0;
}

@Override
public boolean pushPattern(final ICraftingPatternDetails patternDetails, final InventoryCrafting table) {
if (this.hasItemsToSend() || !this.gridProxy.isActive() || !this.craftingList.contains(patternDetails)) {
Expand All @@ -910,10 +953,7 @@ public boolean pushPattern(final ICraftingPatternDetails patternDetails, final I
if (te instanceof ICraftingMachine cm) {
if (cm.acceptsPlans()) {
if (cm.pushPattern(patternDetails, table, s.getOpposite())) {
if (this.isSmartBlocking()) {
this.lastInputHash = patternDetails.hashCode();
}
onPushPatternSuccess(patternDetails);
onPushPatternSuccess(te, s.getOpposite(), patternDetails);
return true;
}
continue;
Expand Down Expand Up @@ -944,12 +984,9 @@ public boolean pushPattern(final ICraftingPatternDetails patternDetails, final I
this.addToSendList(ad.addItems(is, getInsertionMode()));
}
}
if (this.isSmartBlocking()) {
this.lastInputHash = patternDetails.hashCode();
}
out.add(s);
this.pushItemsOut(out);
onPushPatternSuccess(patternDetails);
onPushPatternSuccess(te, s.getOpposite(), patternDetails);
return true;
}
} else if (EIO && te instanceof IItemDuct) {
Expand All @@ -967,12 +1004,9 @@ public boolean pushPattern(final ICraftingPatternDetails patternDetails, final I
}
}
if (hadAcceptedSome) {
if (this.isSmartBlocking()) {
this.lastInputHash = patternDetails.hashCode();
}
out.add(s);
this.pushItemsOut(out);
onPushPatternSuccess(patternDetails);
onPushPatternSuccess(te, s.getOpposite(), patternDetails);
return true;
}
}
Expand Down Expand Up @@ -1309,7 +1343,32 @@ public void resetCraftingLock() {
}
}

private void onPushPatternSuccess(ICraftingPatternDetails pattern) {
private void onPushPatternSuccess(TileEntity te, ForgeDirection s, ICraftingPatternDetails pattern) {
if (this.isSmartBlocking()) {
this.lastInputHash = pattern.hashCode();
if (te instanceof IInterfaceHost oppositeHost) {
try {
if (oppositeHost.getInstalledUpgrades(Upgrades.ADVANCED_BLOCKING) > 0) {
oppositeHost.getInterfaceDuality().gridProxy.getGrid()
.postEvent(new MENetworkCraftingPushedPattern(this.iHost));
}
} catch (GridAccessException e) {
// :P
}
} else if (te instanceof TileCableBus cableBus) {
IPart part = cableBus.getPart(s);
if (part instanceof IInterfaceHost oppositeHost) {
try {
if (oppositeHost.getInstalledUpgrades(Upgrades.ADVANCED_BLOCKING) > 0) {
oppositeHost.getInterfaceDuality().gridProxy.getGrid()
.postEvent(new MENetworkCraftingPushedPattern(this.iHost));
}
} catch (GridAccessException e) {
// :P
}
}
}
}
resetCraftingLock();

LockCraftingMode lockMode = (LockCraftingMode) cm.getSetting(Settings.LOCK_CRAFTING_MODE);
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/appeng/parts/misc/PartInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import appeng.api.networking.crafting.ICraftingPatternDetails;
import appeng.api.networking.crafting.ICraftingProviderHelper;
import appeng.api.networking.events.MENetworkChannelsChanged;
import appeng.api.networking.events.MENetworkCraftingPushedPattern;
import appeng.api.networking.events.MENetworkEventSubscribe;
import appeng.api.networking.events.MENetworkPowerStatusChange;
import appeng.api.networking.security.BaseActionSource;
Expand Down Expand Up @@ -82,6 +83,11 @@ public void stateChange(final MENetworkPowerStatusChange c) {
this.duality.notifyNeighbors();
}

@MENetworkEventSubscribe
public void pushedPattern(final MENetworkCraftingPushedPattern c) {
this.duality.notifyPushedPattern(c.host);
}

@Override
public void getBoxes(final IPartCollisionHelper bch) {
bch.addBox(2, 2, 14, 14, 14, 16);
Expand Down

0 comments on commit 0ee77ed

Please sign in to comment.