Make two provider can order essentia aspect automatic (#65)

and fix spelling errors
This commit is contained in:
MCTBL authored and GitHub committed 2024-07-14 08:57:30 +07:00
1 parent ea47f19929
commit 4c490f2e8a
6 files changed
+78 -7

No files matched your search

+1 -1
View File
@@ -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
+1 -1
View File
@@ -17,7 +17,7 @@ pluginManagement {
}
plugins {
id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.22'
id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.23'
}
@@ -105,7 +105,7 @@ public class PartEssentiaExportBus extends ThEPartEssentiaIOBus_Base implements
return false;
}
if (isCraftingOnly()) {
handleCratting(amountToFillContainer, slot, filterAspect);
handleCrafting(amountToFillContainer, slot, filterAspect);
continue;
}
@@ -120,7 +120,7 @@ public class PartEssentiaExportBus extends ThEPartEssentiaIOBus_Base implements
// Was any extracted?
if (extractedAmount <= 0) {
if (hasCraftingCard) {
handleCratting(amountToFillContainer, slot, filterAspect);
handleCrafting(amountToFillContainer, slot, filterAspect);
}
// Unable to extract from network
continue;
@@ -140,7 +140,7 @@ public class PartEssentiaExportBus extends ThEPartEssentiaIOBus_Base implements
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()
@@ -137,7 +137,12 @@ public class TileEssentiaProvider extends TileProviderBase implements IEssentiaT
// 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
@@ -103,6 +103,8 @@ public class TileInfusionProvider extends TileProviderBase implements IAspectSou
this.doParticalFX(tag.getColor());
return true;
} else {
this.orderSomeEssentia(tag);
}
return false;
@@ -9,15 +9,22 @@ import net.minecraft.nbt.NBTTagCompound;
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;
@@ -33,10 +40,12 @@ import thaumcraft.api.aspects.Aspect;
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}.
@@ -44,7 +53,8 @@ import thaumicenergistics.common.utils.EffectiveSide;
* @author Nividica
*
*/
public abstract class TileProviderBase extends AENetworkTile implements IColorableTile, IWailaSource {
public abstract class TileProviderBase extends AENetworkTile
implements IColorableTile, IWailaSource, ICraftingRequester {
/**
* NBT keys
@@ -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);
@@ -501,4 +513,56 @@ public abstract class TileProviderBase extends AENetworkTile implements IColorab
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);
}
}