mirror of
https://github.com/GTNewHorizons/AE2FluidCraft-Rework.git
synced 2026-11-16 18:44:42 +00:00
Adapt to AE2 Stack Type API changes (#375)
Co-authored-by: Martin Robertz <[email protected]>
This commit is contained in:
1 parent
f02e72e96a
commit
dfabc1c62b
46 files changed
+225
-1364
No files matched your search
@@ -18,7 +18,6 @@ import org.jetbrains.annotations.Nullable;
|
||||
import com.glodblock.github.common.Config;
|
||||
import com.glodblock.github.common.item.ItemFluidDrop;
|
||||
import com.glodblock.github.crossmod.thaumcraft.ThaumicEnergisticsCrafting;
|
||||
import com.glodblock.github.util.ModAndClassUtil;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
@@ -45,11 +44,10 @@ import appeng.api.networking.security.MachineSource;
|
||||
import appeng.api.networking.ticking.IGridTickable;
|
||||
import appeng.api.networking.ticking.TickRateModulation;
|
||||
import appeng.api.networking.ticking.TickingRequest;
|
||||
import appeng.api.storage.IMEMonitor;
|
||||
import appeng.api.storage.StorageName;
|
||||
import appeng.api.storage.data.IAEFluidStack;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
import appeng.core.AELog;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.tile.TileEvent;
|
||||
@@ -99,30 +97,35 @@ public class TileLevelMaintainer extends AENetworkTile
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack injectCraftedItems(ICraftingLink link, IAEItemStack items, Actionable mode) {
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public IAEStack<?> injectCraftedItems(ICraftingLink link, IAEStack<?> stack, Actionable mode) {
|
||||
int idx = this.getRequestIndexByLink(link);
|
||||
|
||||
try {
|
||||
if (getProxy().isActive()) {
|
||||
final IEnergyGrid energy = getProxy().getEnergy();
|
||||
final double power = Math
|
||||
.ceil(ItemFluidDrop.isFluidStack(items) ? items.getStackSize() / 1000D : items.getStackSize());
|
||||
if (energy.extractAEPower(power, mode, PowerMultiplier.CONFIG) > power - 0.01) {
|
||||
if (ItemFluidDrop.isFluidStack(items)) {
|
||||
IAEFluidStack notInjectedItems = getProxy().getStorage().getFluidInventory()
|
||||
.injectItems(ItemFluidDrop.getAeFluidStack(items), mode, source);
|
||||
if (notInjectedItems != null) {
|
||||
items.setStackSize(notInjectedItems.getStackSize());
|
||||
if (idx != -1) {
|
||||
this.updateState(idx, LevelState.Export);
|
||||
}
|
||||
final double power = Math.ceil((double) stack.getStackSize() / stack.getAmountPerUnit());
|
||||
|
||||
return items;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
if (energy.extractAEPower(power, mode, PowerMultiplier.CONFIG) > power - 0.01) {
|
||||
IMEMonitor monitor = getProxy().getStorage().getMEMonitor(stack.getStackType());
|
||||
if (monitor == null) return stack;
|
||||
|
||||
IAEStack<?> notInjected;
|
||||
if (stack instanceof IAEItemStack ais && ItemFluidDrop.isFluidStack(ais)) {
|
||||
notInjected = getProxy().getStorage().getFluidInventory()
|
||||
.injectItems(ItemFluidDrop.getAeFluidStack(ais), mode, source);
|
||||
} else {
|
||||
return getProxy().getStorage().getItemInventory().injectItems(items, mode, source);
|
||||
notInjected = monitor.injectItems(stack, mode, source);
|
||||
}
|
||||
|
||||
if (notInjected != null) {
|
||||
if (idx != -1) {
|
||||
this.updateState(idx, LevelState.Export);
|
||||
}
|
||||
|
||||
return notInjected;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -130,7 +133,7 @@ public class TileLevelMaintainer extends AENetworkTile
|
||||
AELog.debug(e);
|
||||
}
|
||||
|
||||
return items;
|
||||
return stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -162,8 +165,6 @@ public class TileLevelMaintainer extends AENetworkTile
|
||||
try {
|
||||
final ICraftingGrid craftingGrid = getProxy().getCrafting();
|
||||
final IGrid grid = getProxy().getGrid();
|
||||
final IItemList<IAEItemStack> invItems = getProxy().getStorage().getItemInventory().getStorageList();
|
||||
final IItemList<IAEFluidStack> invFluid = getProxy().getStorage().getFluidInventory().getStorageList();
|
||||
|
||||
// Check there are available crafting CPUs before doing any work.
|
||||
// This hopefully stops level maintainers busy-looping calculating
|
||||
@@ -196,32 +197,17 @@ public class TileLevelMaintainer extends AENetworkTile
|
||||
continue;
|
||||
}
|
||||
|
||||
IAEStack<?> aeItem = null;
|
||||
|
||||
IAEStack<?> craftItem = requests[i].stack.copy();
|
||||
craftItem.setStackSize(batchSize);
|
||||
IMEMonitor monitor = getProxy().getStorage().getMEMonitor(craftItem.getStackType());
|
||||
if (monitor == null) continue;
|
||||
|
||||
if (craftItem instanceof IAEItemStack ais) {
|
||||
if (ModAndClassUtil.ThE && ThaumicEnergisticsCrafting.isAspectStack(ais.getItemStack())) {
|
||||
aeItem = ThaumicEnergisticsCrafting.convertAspectStack(ais);
|
||||
} else {
|
||||
aeItem = invItems.findPrecise(ais);
|
||||
}
|
||||
} else if (craftItem instanceof IAEFluidStack afs) {
|
||||
aeItem = invFluid.findPrecise(afs);
|
||||
}
|
||||
IAEStack<?> stackInStorage = monitor.getStorageList().findPrecise(craftItem);
|
||||
|
||||
long stackSize = aeItem == null ? 0 : aeItem.getStackSize();
|
||||
|
||||
if (ModAndClassUtil.ThE) {
|
||||
if (aeItem instanceof IAEItemStack ais
|
||||
&& ThaumicEnergisticsCrafting.isAspectStack(ais.getItemStack())) {
|
||||
stackSize = ThaumicEnergisticsCrafting.getEssentiaAmount(ais, grid);
|
||||
}
|
||||
}
|
||||
long stackSize = stackInStorage == null ? 0 : stackInStorage.getStackSize();
|
||||
|
||||
boolean isDone = this.isDone(i);
|
||||
boolean isCraftable = aeItem != null && aeItem.isCraftable();
|
||||
boolean isCraftable = stackInStorage != null && stackInStorage.isCraftable();
|
||||
boolean shouldCraft = isCraftable && stackSize < quantity;
|
||||
|
||||
if (isDone) {
|
||||
@@ -240,11 +226,11 @@ public class TileLevelMaintainer extends AENetworkTile
|
||||
continue;
|
||||
}
|
||||
|
||||
if (craftingGrid.canEmitFor(aeItem)) {
|
||||
if (craftingGrid.canEmitFor(stackInStorage)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (craftingGrid.isRequesting(aeItem)) {
|
||||
if (craftingGrid.isRequesting(stackInStorage)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -289,7 +275,7 @@ public class TileLevelMaintainer extends AENetworkTile
|
||||
// No jobs to submit, start calculating some item.
|
||||
|
||||
requests[itemToBeginIdx].job = craftingGrid
|
||||
.beginCraftingJob(getWorldObj(), grid, source, itemToBegin, null);
|
||||
.beginCraftingJob(this.worldObj, grid, source, itemToBegin, null);
|
||||
this.updateState(itemToBeginIdx, LevelState.Craft);
|
||||
|
||||
// Try the next item next time.
|
||||
@@ -644,6 +630,10 @@ public class TileLevelMaintainer extends AENetworkTile
|
||||
if (stack == null) {
|
||||
throw new IllegalArgumentException("ItemStack cannot be null!");
|
||||
}
|
||||
|
||||
// Migrate old aspect stack
|
||||
stack = ThaumicEnergisticsCrafting.convertItemAspectStack(stack);
|
||||
|
||||
quantity = tag.getLong(NBT_QUANTITY);
|
||||
batchSize = tag.getLong(NBT_BATCH);
|
||||
enable = tag.getBoolean(NBT_ENABLE);
|
||||
@@ -660,6 +650,10 @@ public class TileLevelMaintainer extends AENetworkTile
|
||||
|
||||
public void loadFromNBT(NBTTagCompound tag) {
|
||||
stack = Platform.readStackNBT(tag.getCompoundTag(NBT_STACK), true);
|
||||
|
||||
// Migrate old aspect stack
|
||||
stack = ThaumicEnergisticsCrafting.convertItemAspectStack(stack);
|
||||
|
||||
quantity = tag.getLong(NBT_QUANTITY);
|
||||
batchSize = tag.getLong(NBT_BATCH);
|
||||
enable = tag.getBoolean(NBT_ENABLE);
|
||||
|
||||
Reference in new issue
Block a user