Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make two provider can order essentia aspect automatic #65

Merged
merged 1 commit into from
Jul 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pluginManagement {
}

plugins {
id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.22'
id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.23'
}


Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public boolean doWork(final int amountToFillContainer) {
return false;
}
if (isCraftingOnly()) {
handleCratting(amountToFillContainer, slot, filterAspect);
handleCrafting(amountToFillContainer, slot, filterAspect);
continue;
}

Expand All @@ -120,7 +120,7 @@ public boolean doWork(final int amountToFillContainer) {
// Was any extracted?
if (extractedAmount <= 0) {
if (hasCraftingCard) {
handleCratting(amountToFillContainer, slot, filterAspect);
handleCrafting(amountToFillContainer, slot, filterAspect);
}
// Unable to extract from network
continue;
Expand All @@ -140,7 +140,7 @@ public boolean doWork(final int amountToFillContainer) {
return false;
}

private void handleCratting(int amountToFillContainer, int slot, Aspect filterAspect) {
private void handleCrafting(int amountToFillContainer, int slot, Aspect filterAspect) {
IGrid grid = getGridNode().getGrid();
final ICraftingGrid cg = grid.getCache(ICraftingGrid.class);
IAEItemStack result = AEApi.instance().storage()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,12 @@ public int getEssentiaAmount(final ForgeDirection side) {

// Does the neighbor want anything?
if (wantedAspect != null) {
return (int) Math.min(this.getAspectAmountInNetwork(wantedAspect), Integer.MAX_VALUE);
long aspectAmountInNetwork = this.getAspectAmountInNetwork(wantedAspect);
if (aspectAmountInNetwork == 0) {
this.orderSomeEssentia(wantedAspect);
} else {
return (int) Math.min(aspectAmountInNetwork, Integer.MAX_VALUE);
}
}

// No match or no request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ public boolean takeFromContainer(final Aspect tag, final int amount) {
this.doParticalFX(tag.getColor());

return true;
} else {
this.orderSomeEssentia(tag);
}

return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,22 @@
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;

import com.google.common.collect.ImmutableSet;

import appeng.api.AEApi;
import appeng.api.config.Actionable;
import appeng.api.implementations.tiles.IColorableTile;
import appeng.api.networking.GridFlags;
import appeng.api.networking.IGrid;
import appeng.api.networking.IGridNode;
import appeng.api.networking.crafting.ICraftingGrid;
import appeng.api.networking.crafting.ICraftingLink;
import appeng.api.networking.crafting.ICraftingRequester;
import appeng.api.networking.events.MENetworkChannelsChanged;
import appeng.api.networking.events.MENetworkEventSubscribe;
import appeng.api.networking.events.MENetworkPowerStatusChange;
import appeng.api.networking.security.MachineSource;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.util.AECableType;
import appeng.api.util.AEColor;
import appeng.core.localization.WailaText;
Expand All @@ -33,18 +40,21 @@
import thaumicenergistics.api.grid.IEssentiaGrid;
import thaumicenergistics.api.grid.IMEEssentiaMonitor;
import thaumicenergistics.common.integration.IWailaSource;
import thaumicenergistics.common.items.ItemCraftingAspect;
import thaumicenergistics.common.registries.EnumCache;
import thaumicenergistics.common.tiles.TileEssentiaProvider;
import thaumicenergistics.common.tiles.TileInfusionProvider;
import thaumicenergistics.common.utils.EffectiveSide;
import thaumicenergistics.implementaion.ThEMultiCraftingTracker;

/**
* Base class of {@link TileEssentiaProvider} and {@link TileInfusionProvider}.
*
* @author Nividica
*
*/
public abstract class TileProviderBase extends AENetworkTile implements IColorableTile, IWailaSource {
public abstract class TileProviderBase extends AENetworkTile
implements IColorableTile, IWailaSource, ICraftingRequester {

/**
* NBT keys
Expand Down Expand Up @@ -77,6 +87,8 @@ public abstract class TileProviderBase extends AENetworkTile implements IColorab
*/
protected boolean isColorForced = false;

protected final ThEMultiCraftingTracker craftingTracker = new ThEMultiCraftingTracker(this, 1);

public TileProviderBase() {
// Create the source
this.asMachineSource = new MachineSource(this);
Expand Down Expand Up @@ -501,4 +513,56 @@ public void setupProvider(final int attachmentSide) {
this.getProxy().setIdlePowerUsage(this.getIdlePowerusage());
}
}

/**
* When network Essentia is not enough, let provider can auto order some. With default amount 32.
*
* @param aspect
* @return orderIsSuccessful
*/
public boolean orderSomeEssentia(final Aspect aspect) {
return this.orderSomeEssentia(aspect, 32);
}

/**
* When network Essentia is not enough, let provider can auto order some.
*
* @param aspect
* @param amount
* @return orderIsSuccessful
*/
public boolean orderSomeEssentia(final Aspect aspect, final int amount) {
try {
ICraftingGrid craftingGrid = this.getProxy().getCrafting();
IGrid grid = this.getProxy().getGrid();
IAEItemStack itemStack = AEApi.instance().storage()
.createItemStack(ItemCraftingAspect.createStackForAspect(aspect, 1));
if (!craftingGrid.isRequesting(itemStack)) {
return this.craftingTracker.handleCrafting(
0,
32,
itemStack,
this.getWorldObj(),
grid,
craftingGrid,
this.getMachineSource());
}
} catch (Exception e) {}
return false;
}

@Override
public ImmutableSet<ICraftingLink> getRequestedJobs() {
return craftingTracker.getRequestedJobs();
}

@Override
public IAEItemStack injectCraftedItems(ICraftingLink link, IAEItemStack items, Actionable mode) {
return items;
}

@Override
public void jobStateChange(final ICraftingLink link) {
this.craftingTracker.jobStateChange(link);
}
}