mirror of
https://github.com/GTNewHorizons/AE2FluidCraft-Rework.git
synced 2026-11-16 10:14:40 +00:00
Add LevelMaintainerTerminal rework logic inside TileLevelMaintainer (#162)
* Use new interface terminal API * Update dependencies.gradle * feat: Update core hooks and integrations * api: Add `LevelTerminalRegistry` functionality * feat: Use `customName` to display in `GuiFluidLevelEmitter` * feat: Rework scheduling and data storage in `TileLevelMaintainer` functionality * feat: Add new item `LevelTerminal` * feat: Support back navigation functionality * feat: add back navigation in `LevelMaintainer` from terminal * use `IGuiTooltipHandler` directly from ae2 include #160 * fix correct `InterfaceTerminalSupportedClassProvider` deprecation * Implement new version of `InterfaceWireless` based on `InterfaceTerminal` * Fix `LevelTerminal` data recursion and few in fixes gui * Use `aeRenderItem` directly and fix `zIndex` in custom slots * Fix rendering numbers bigger than 2.1G through `aeRenderItem` * Fix fails on `getCraftingItem` no root cause was found * Fix add packet logging and try to not fail after receive corrupted packet * Fix add logging around empty configuration * Fix packet corruption and log invalid data * Fix packet corruption with level emitters * Correct handle overwrite packet * Fix intercept dnd click from GT5 hook for `AppEngGuiHandler` keyword `net.bdew.neiaddons.appeng.AppEngGuiHandler` * update be+deps * Update dependencies.gradle * Update dependencies.gradle * Fix `zIndexes` for compatability with `DuraDisplay` * Update AE2 and fix compatability * Change `ForgeDirection` side serialization to `byte` * Fix tooltip zIndexes * Rename all rest parts related to `Level terminal` * Code cleanup after review * Remove duplicated dependency declaration --------- Co-authored-by: Firenoo <[email protected]> Co-authored-by: Martin Robertz <[email protected]>
This commit is contained in:
80 files changed
+6169
-1785
No files matched your search
@@ -1,11 +1,18 @@
|
||||
package com.glodblock.github.common.tile;
|
||||
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.function.UnaryOperator;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import com.glodblock.github.api.registries.ILevelViewable;
|
||||
import com.glodblock.github.common.Config;
|
||||
import com.glodblock.github.common.item.ItemFluidDrop;
|
||||
import com.glodblock.github.inventory.AeItemStackHandler;
|
||||
import com.glodblock.github.inventory.AeStackInventory;
|
||||
@@ -37,7 +44,6 @@ import appeng.api.storage.data.IAEFluidStack;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
import appeng.core.AELog;
|
||||
import appeng.crafting.CraftingLink;
|
||||
import appeng.helpers.NonNullArrayIterator;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.tile.TileEvent;
|
||||
@@ -45,139 +51,151 @@ import appeng.tile.events.TileEventType;
|
||||
import appeng.tile.grid.AENetworkTile;
|
||||
import appeng.tile.inventory.IAEAppEngInventory;
|
||||
import appeng.tile.inventory.InvOperation;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.item.AEItemStack;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public class TileLevelMaintainer extends AENetworkTile
|
||||
implements IAEAppEngInventory, IGridTickable, ICraftingRequester, IPowerChannelState {
|
||||
implements IAEAppEngInventory, IGridTickable, ICraftingRequester, IPowerChannelState, ILevelViewable {
|
||||
|
||||
public static final int REQ_COUNT = 5;
|
||||
public final InventoryRequest requests = new InventoryRequest(this);
|
||||
private final BaseActionSource source;
|
||||
private final IInventory inv = new AeItemStackHandler(requests.getRequestStacks());
|
||||
private final IInventory inv = new AeItemStackHandler(requests.requestStacks);
|
||||
private boolean isPowered = false;
|
||||
|
||||
public TileLevelMaintainer() {
|
||||
getProxy().setIdlePowerUsage(1D);
|
||||
getProxy().setFlags(GridFlags.REQUIRE_CHANNEL);
|
||||
this.source = new MachineSource(this);
|
||||
source = new MachineSource(this);
|
||||
}
|
||||
|
||||
public AeStackInventory<IAEItemStack> getRequestSlots() {
|
||||
return requests.getRequestStacks();
|
||||
return requests.requestStacks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImmutableSet<ICraftingLink> getRequestedJobs() {
|
||||
return ImmutableSet.copyOf(new NonNullArrayIterator<>(this.requests.getLinks()));
|
||||
}
|
||||
|
||||
private IAEItemStack setState(ICraftingLink link, IAEItemStack items) {
|
||||
if (items != null) {
|
||||
requests.setState(link, State.Exporting);
|
||||
} else {
|
||||
requests.setState(link, State.Crafting);
|
||||
}
|
||||
return items;
|
||||
return ImmutableSet.copyOf(new NonNullArrayIterator<>(requests.links));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack injectCraftedItems(ICraftingLink link, IAEItemStack items, Actionable mode) {
|
||||
int idx = requests.getIdxByLink(link);
|
||||
try {
|
||||
if (this.getProxy().isActive()) {
|
||||
final IEnergyGrid energy = this.getProxy().getEnergy();
|
||||
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 notInserted = this.getProxy().getStorage().getFluidInventory()
|
||||
.injectItems(ItemFluidDrop.getAeFluidStack(items), mode, this.source);
|
||||
if (notInserted != null) {
|
||||
items.setStackSize(notInserted.getStackSize());
|
||||
return setState(link, items);
|
||||
IAEFluidStack notInjectedItems = getProxy().getStorage().getFluidInventory()
|
||||
.injectItems(ItemFluidDrop.getAeFluidStack(items), mode, source);
|
||||
if (notInjectedItems != null) {
|
||||
items.setStackSize(notInjectedItems.getStackSize());
|
||||
requests.updateState(idx, State.Export);
|
||||
|
||||
return items;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
return setState(
|
||||
link,
|
||||
this.getProxy().getStorage().getItemInventory().injectItems(items, mode, this.source));
|
||||
return getProxy().getStorage().getItemInventory().injectItems(items, mode, source);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (GridAccessException e) {
|
||||
AELog.debug(e);
|
||||
}
|
||||
return setState(link, items);
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void jobStateChange(ICraftingLink link) {
|
||||
if (this.requests.getLinks() != null) {
|
||||
for (int x = 0; x < this.requests.getLinks().length; x++) {
|
||||
if (this.requests.getLinks()[x] == link) {
|
||||
this.requests.getLinks()[x] = link;
|
||||
return;
|
||||
}
|
||||
for (int x = 0; x < REQ_COUNT; x++) {
|
||||
if (requests.getLink(x) == link) {
|
||||
requests.updateLink(x, link);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickingRequest getTickingRequest(IGridNode node) {
|
||||
return new TickingRequest(5, 120, false, true);
|
||||
return new TickingRequest(Config.levelMaintainerMinTicks, Config.levelMaintainerMaxTicks, false, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickRateModulation tickingRequest(IGridNode node, int TicksSinceLastCall) {
|
||||
return this.canDoBusWork() ? this.doWork() : TickRateModulation.IDLE;
|
||||
return canDoBusWork() ? doWork() : TickRateModulation.IDLE;
|
||||
}
|
||||
|
||||
private TickRateModulation doWork() {
|
||||
if (!this.getProxy().isActive() || !this.canDoBusWork()) {
|
||||
if (!getProxy().isActive() || !canDoBusWork()) {
|
||||
return TickRateModulation.IDLE;
|
||||
}
|
||||
boolean didSomething = false;
|
||||
try {
|
||||
ICraftingGrid cg = this.getProxy().getCrafting();
|
||||
IGrid grid = this.getProxy().getGrid();
|
||||
final IItemList<IAEItemStack> inv = this.getProxy().getStorage().getItemInventory().getStorageList();
|
||||
final ICraftingGrid craftingGrid = getProxy().getCrafting();
|
||||
final IGrid grid = getProxy().getGrid();
|
||||
final IItemList<IAEItemStack> inv = getProxy().getStorage().getItemInventory().getStorageList();
|
||||
for (int i = 0; i < REQ_COUNT; i++) {
|
||||
IAEItemStack is = requests.getRequestQtyStack(i);
|
||||
if (is != null && requests.getBatchSize(i) > 0) {
|
||||
long quantity = requests.getQuantity(i);
|
||||
long batchSize = requests.getBatchSize(i);
|
||||
boolean isEnable = requests.isEnable(i);
|
||||
if (!isEnable || batchSize == 0) requests.updateState(i, State.None);
|
||||
if (batchSize > 0) {
|
||||
IAEItemStack craftItem = requests.getCraftItem(i);
|
||||
if (this.requests.isDone(i)) this.requests.setState(i, State.Idling);
|
||||
if (cg.canEmitFor(craftItem) || cg.isRequesting(craftItem)
|
||||
|| inv.findPrecise(is) == null
|
||||
|| !inv.findPrecise(is).isCraftable()
|
||||
|| inv.findPrecise(is).getStackSize() >= is.getStackSize()
|
||||
|| !this.requests.isDone(i))
|
||||
IAEItemStack aeItem = inv.findPrecise(craftItem);
|
||||
boolean isDone = requests.isDone(i);
|
||||
boolean isCraftable = aeItem != null && aeItem.isCraftable();
|
||||
boolean shouldCraft = isCraftable && aeItem.getStackSize() < quantity;
|
||||
if (isDone) requests.updateState(i, State.Idle);
|
||||
if (!isCraftable) requests.updateState(i, State.Error);
|
||||
if (craftingGrid.canEmitFor(craftItem) || craftingGrid.isRequesting(craftItem)
|
||||
|| !isDone
|
||||
|| !shouldCraft)
|
||||
continue;
|
||||
// do crafting
|
||||
Future<ICraftingJob> jobTask = requests.getJobs()[i];
|
||||
Future<ICraftingJob> jobTask = requests.getJob(i);
|
||||
if (jobTask == null) {
|
||||
requests.getJobs()[i] = cg.beginCraftingJob(getWorldObj(), grid, this.source, craftItem, null);
|
||||
requests.updateJob(
|
||||
i,
|
||||
craftingGrid.beginCraftingJob(getWorldObj(), grid, source, craftItem, null));
|
||||
requests.updateState(i, State.Craft);
|
||||
|
||||
// calculate only one job per tick request
|
||||
return TickRateModulation.SAME;
|
||||
} else if (jobTask.isDone()) {
|
||||
requests.setState(i, State.Idling);
|
||||
requests.updateState(i, State.Craft);
|
||||
try {
|
||||
ICraftingJob job = jobTask.get();
|
||||
if (job != null) {
|
||||
ICraftingLink link = cg.submitJob(job, this, null, false, this.source);
|
||||
requests.jobs[i] = null;
|
||||
ICraftingLink link = craftingGrid.submitJob(job, this, null, false, source);
|
||||
requests.updateJob(i, null);
|
||||
if (link != null) {
|
||||
didSomething = true;
|
||||
requests.setState(i, State.Crafting);
|
||||
requests.getLinks()[i] = link;
|
||||
requests.updateState(i, State.Craft);
|
||||
requests.updateLink(i, link);
|
||||
|
||||
// submit only one job per tick request
|
||||
return TickRateModulation.SAME;
|
||||
} else {
|
||||
requests.updateState(i, State.Error);
|
||||
}
|
||||
} else {
|
||||
requests.updateState(i, State.Error);
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
|
||||
requests.updateState(i, State.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (final GridAccessException ignore) {}
|
||||
return didSomething ? TickRateModulation.FASTER : TickRateModulation.SLOWER;
|
||||
} catch (final GridAccessException ignore) {
|
||||
|
||||
}
|
||||
|
||||
return TickRateModulation.SAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -196,7 +214,7 @@ public class TileLevelMaintainer extends AENetworkTile
|
||||
}
|
||||
|
||||
protected boolean canDoBusWork() {
|
||||
return this.getProxy().isActive();
|
||||
return getProxy().isActive();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -204,275 +222,398 @@ public class TileLevelMaintainer extends AENetworkTile
|
||||
|
||||
@Override
|
||||
public boolean isPowered() {
|
||||
return this.isPowered;
|
||||
return isPowered;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActive() {
|
||||
return this.isPowered;
|
||||
return isPowered;
|
||||
}
|
||||
|
||||
public InventoryRequest getRequestInventory() {
|
||||
return this.requests;
|
||||
return requests;
|
||||
}
|
||||
|
||||
public IInventory getInventory() {
|
||||
return inv;
|
||||
}
|
||||
|
||||
public IInventory getInventoryByName(String name) {
|
||||
if (name == "config") return new AeItemStackHandler(requests.requestStacks);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void updateQuantity(int idx, long size) {
|
||||
this.requests.updateQuantity(idx, size);
|
||||
requests.updateQuantity(idx, size);
|
||||
}
|
||||
|
||||
public void updateBatchSize(int idx, long size) {
|
||||
this.requests.updateBatchSize(idx, size);
|
||||
requests.updateBatchSize(idx, size);
|
||||
}
|
||||
|
||||
public void setRequestStatus(int idx, boolean enable) {
|
||||
this.requests.setEnable(idx, enable);
|
||||
public void updateStatus(int idx, boolean enable) {
|
||||
requests.updateStatus(idx, enable);
|
||||
}
|
||||
|
||||
private void readLinkFromNBT(NBTTagCompound data) {
|
||||
for (int i = 0; i < REQ_COUNT; i++) {
|
||||
final NBTTagCompound stackData = requests.getItemStack(i).getTagCompound();
|
||||
if (stackData != null && stackData.hasNoTags()
|
||||
&& !stackData.hasKey(TLMTags.Link.tagName)
|
||||
&& stackData.getCompoundTag(TLMTags.Link.tagName).hasNoTags()) {
|
||||
requests.updateLink(i, null);
|
||||
requests.updateState(i, State.Idle);
|
||||
} else {
|
||||
NBTTagCompound linkData = stackData.getCompoundTag(TLMTags.Link.tagName);
|
||||
requests.updateLink(i, AEApi.instance().storage().loadCraftingLink(linkData, this));
|
||||
if (!requests.isDone(i)) requests.updateState(i, State.Craft);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
@Deprecated
|
||||
private void readLinkFromNBT__old(NBTTagCompound data) {
|
||||
try {
|
||||
for (int i = 0; i < this.requests.getLinks().length; i++) {
|
||||
for (int i = 0; i < REQ_COUNT; i++) {
|
||||
final NBTTagCompound link = data.getCompoundTag("links-" + i);
|
||||
if (link != null && link.hasNoTags()) {
|
||||
this.requests.getLinks()[i] = null;
|
||||
requests.updateLink(i, null);
|
||||
} else {
|
||||
this.requests.getLinks()[i] = AEApi.instance().storage().loadCraftingLink(link, this);
|
||||
if (!this.requests.isDone(i)) this.requests.setState(i, State.Crafting);
|
||||
requests.updateLink(i, AEApi.instance().storage().loadCraftingLink(link, this));
|
||||
if (!requests.isDone(i)) requests.updateState(i, State.Craft);
|
||||
}
|
||||
}
|
||||
} catch (Exception ignore) {}
|
||||
}
|
||||
|
||||
private NBTTagCompound writeLinkToNBT(NBTTagCompound data) {
|
||||
for (int i = 0; i < this.requests.getLinks().length; i++) {
|
||||
if (this.requests.getLinks()[i] != null) {
|
||||
CraftingLink link = (CraftingLink) this.requests.getLinks()[i];
|
||||
NBTTagCompound linkData = new NBTTagCompound();
|
||||
link.writeToNBT(linkData);
|
||||
data.setTag("links-" + i, linkData);
|
||||
}
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
@TileEvent(TileEventType.WORLD_NBT_WRITE)
|
||||
public NBTTagCompound writeToNBTEvent(NBTTagCompound data) {
|
||||
this.requests.requestStacks.writeToNbt(data, "Inventory");
|
||||
this.requests.requestBatches.writeToNbt(data, "Batch");
|
||||
this.requests.requestQtys.writeToNbt(data, "Count");
|
||||
return writeLinkToNBT(data);
|
||||
public void writeToNBTEvent(NBTTagCompound data) {
|
||||
requests.requestStacks.writeToNbt(data, TLMTags.RequestStacks.tagName);
|
||||
}
|
||||
|
||||
@TileEvent(TileEventType.WORLD_NBT_READ)
|
||||
public void readFromNBTEvent(NBTTagCompound data) {
|
||||
this.requests.requestStacks.readFromNbt(data, "Inventory");
|
||||
this.requests.requestBatches.readFromNbt(data, "Batch");
|
||||
this.requests.requestQtys.readFromNbt(data, "Count");
|
||||
this.readLinkFromNBT(data);
|
||||
if (data.hasKey(TLMTags.RequestStacks.tagName)) {
|
||||
requests.requestStacks.readFromNbt(data, TLMTags.RequestStacks.tagName);
|
||||
if (Platform.isServer()) {
|
||||
for (int i = 0; i < REQ_COUNT; i++) {
|
||||
if (requests.requestStacks.getStack(i) != null) {
|
||||
ItemStack storageStack = requests.requestStacks.getStack(i).getItemStack();
|
||||
ItemStack itemStack = loadItemStackFromTag(storageStack);
|
||||
ItemStack craftStack = removeRecursion(storageStack);
|
||||
if (!ItemStack.areItemStacksEqual(itemStack, craftStack)) {
|
||||
requests.updateStack(i, craftStack);
|
||||
AELog.info(
|
||||
"[TileLevelMaintainer] Replace craft stack from: " + itemStack.toString()
|
||||
+ ":"
|
||||
+ (itemStack.hasTagCompound() ? itemStack.getTagCompound() : "{no tags}")
|
||||
+ "; with: "
|
||||
+ craftStack
|
||||
+ ":"
|
||||
+ (craftStack.hasTagCompound() ? craftStack.getTagCompound()
|
||||
: "{no tags}"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Migration from old data storage
|
||||
long[] batches = new long[REQ_COUNT];
|
||||
long[] quantyties = new long[REQ_COUNT];
|
||||
requests.requestStacks.readFromNbt(data, "Batch");
|
||||
for (int i = 0; i < REQ_COUNT; i++) {
|
||||
IAEItemStack batchStack = requests.requestStacks.getStack(i);
|
||||
batches[i] = batchStack != null ? batchStack.getStackSize() : 0;
|
||||
}
|
||||
requests.requestStacks.readFromNbt(data, "Count");
|
||||
for (int i = 0; i < REQ_COUNT; i++) {
|
||||
IAEItemStack quantityStack = requests.requestStacks.getStack(i);
|
||||
quantyties[i] = quantityStack != null ? quantityStack.getStackSize() : 0;
|
||||
}
|
||||
requests.requestStacks.readFromNbt(data, "Inventory");
|
||||
for (int i = 0; i < REQ_COUNT; i++) {
|
||||
IAEItemStack requestsStack = requests.requestStacks.getStack(i);
|
||||
if (requestsStack != null) {
|
||||
requests.updateStack(i, requestsStack.getItemStack());
|
||||
requests.updateBatchSize(i, batches[i]);
|
||||
requests.updateQuantity(i, quantyties[i]);
|
||||
}
|
||||
}
|
||||
readLinkFromNBT__old(data);
|
||||
}
|
||||
}
|
||||
|
||||
private ItemStack removeRecursion(ItemStack itemStack) {
|
||||
if (itemStack.hasTagCompound() && itemStack.getTagCompound().hasKey(TLMTags.Stack.tagName)) {
|
||||
return removeRecursion(loadItemStackFromTag(itemStack));
|
||||
}
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static ItemStack loadItemStackFromTag(ItemStack itemStack) {
|
||||
return ItemStack.loadItemStackFromNBT(itemStack.getTagCompound().getCompoundTag(TLMTags.Stack.tagName));
|
||||
}
|
||||
|
||||
@TileEvent(TileEventType.NETWORK_READ)
|
||||
public boolean readFromStream(final ByteBuf data) {
|
||||
final boolean oldPower = this.isPowered;
|
||||
this.isPowered = data.readBoolean();
|
||||
return this.isPowered != oldPower;
|
||||
final boolean oldPower = isPowered;
|
||||
isPowered = data.readBoolean();
|
||||
return isPowered != oldPower;
|
||||
}
|
||||
|
||||
@TileEvent(TileEventType.NETWORK_WRITE)
|
||||
public void writeToStream(final ByteBuf data) {
|
||||
data.writeBoolean(this.isActive());
|
||||
data.writeBoolean(isActive());
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void stateChange(final MENetworkPowerStatusChange p) {
|
||||
this.updatePowerState();
|
||||
updatePowerState();
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public final void bootingRender(final MENetworkBootingStatusChange c) {
|
||||
this.updatePowerState();
|
||||
updatePowerState();
|
||||
}
|
||||
|
||||
private void updatePowerState() {
|
||||
boolean newState = false;
|
||||
|
||||
try {
|
||||
newState = this.getProxy().isActive()
|
||||
&& this.getProxy().getEnergy().extractAEPower(1, Actionable.SIMULATE, PowerMultiplier.CONFIG)
|
||||
> 0.0001;
|
||||
newState = getProxy().isActive()
|
||||
&& getProxy().getEnergy().extractAEPower(1, Actionable.SIMULATE, PowerMultiplier.CONFIG) > 0.0001;
|
||||
} catch (final GridAccessException ignored) {
|
||||
|
||||
}
|
||||
if (newState != this.isPowered) {
|
||||
this.isPowered = newState;
|
||||
this.markForUpdate();
|
||||
if (newState != isPowered) {
|
||||
isPowered = newState;
|
||||
markForUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
public enum State {
|
||||
Nothing,
|
||||
Idling,
|
||||
Crafting,
|
||||
Exporting
|
||||
@Override
|
||||
public TileEntity getTile() {
|
||||
return this;
|
||||
}
|
||||
|
||||
public static class InventoryRequest {
|
||||
@Override
|
||||
public ForgeDirection getSide() {
|
||||
return ForgeDirection.UNKNOWN;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int rowSize() {
|
||||
return REQ_COUNT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getSelfItemStack() {
|
||||
return getItemFromTile(this);
|
||||
}
|
||||
|
||||
public enum State {
|
||||
None,
|
||||
Idle,
|
||||
Craft,
|
||||
Export,
|
||||
Error
|
||||
}
|
||||
|
||||
public enum TLMTags {
|
||||
|
||||
RequestStacks("RequestStacks"),
|
||||
Enable("Enable"),
|
||||
Quantity("Quantity"),
|
||||
Batch("Batch"),
|
||||
Link("Link"),
|
||||
State("State"),
|
||||
Index("Index"),
|
||||
Stack("Stack");
|
||||
|
||||
public final String tagName;
|
||||
|
||||
TLMTags(String tagName) {
|
||||
this.tagName = tagName;
|
||||
}
|
||||
}
|
||||
|
||||
public static final class InventoryRequest {
|
||||
|
||||
private final AeStackInventoryImpl<IAEItemStack> requestStacks;
|
||||
private final AeStackInventoryImpl<IAEItemStack> requestBatches;
|
||||
private final AeStackInventoryImpl<IAEItemStack> requestQtys;
|
||||
private final Future<ICraftingJob>[] jobs;
|
||||
private final ICraftingLink[] links;
|
||||
private final State[] state = new State[REQ_COUNT];
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public InventoryRequest(TileLevelMaintainer tile) {
|
||||
this.requestStacks = new AeStackInventoryImpl<>(StorageChannel.ITEMS, REQ_COUNT, tile);
|
||||
this.requestBatches = new AeStackInventoryImpl<>(StorageChannel.ITEMS, REQ_COUNT, tile);
|
||||
this.requestQtys = new AeStackInventoryImpl<>(StorageChannel.ITEMS, REQ_COUNT, tile);
|
||||
this.jobs = new Future[REQ_COUNT];
|
||||
this.links = new ICraftingLink[REQ_COUNT];
|
||||
}
|
||||
|
||||
public void setEnable(int idx, boolean enable) {
|
||||
IAEItemStack ias = this.getRequestStacks().getStack(idx);
|
||||
IAEItemStack ias1 = this.getRequestBatches().getStack(idx);
|
||||
if (ias != null && ias1 != null) {
|
||||
ItemStack is = ias1.getItemStack();
|
||||
NBTTagCompound data = new NBTTagCompound();
|
||||
data.setBoolean("Enable", enable);
|
||||
is.setTagCompound(data);
|
||||
IAEItemStack i = AEItemStack.create(is);
|
||||
i.setStackSize(ias1.getStackSize());
|
||||
this.getRequestBatches().setStack(idx, i);
|
||||
}
|
||||
requestStacks = new AeStackInventoryImpl<>(StorageChannel.ITEMS, REQ_COUNT, tile);
|
||||
jobs = new Future[REQ_COUNT];
|
||||
links = new ICraftingLink[REQ_COUNT];
|
||||
}
|
||||
|
||||
public State getState(int idx) {
|
||||
IAEItemStack ias = this.getRequestStacks().getStack(idx);
|
||||
IAEItemStack ias = requestStacks.getStack(idx);
|
||||
if (ias == null) {
|
||||
return State.Nothing;
|
||||
return State.None;
|
||||
} else {
|
||||
return this.state[idx] == null ? State.Idling : this.state[idx];
|
||||
return state[idx] == null ? State.Idle : state[idx];
|
||||
}
|
||||
}
|
||||
|
||||
public void setState(ICraftingLink link, State state) {
|
||||
int i = 0;
|
||||
for (ICraftingLink link1 : this.getLinks()) {
|
||||
if (link == link1) {
|
||||
this.setState(i, state);
|
||||
break;
|
||||
public int getIdxByLink(ICraftingLink link) {
|
||||
for (int i = 0; i < REQ_COUNT; i++) {
|
||||
if (links[i] == link) {
|
||||
return i;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
public void setState(int idx, State state) {
|
||||
this.state[idx] = state;
|
||||
}
|
||||
|
||||
public boolean isEnable(int idx) {
|
||||
IAEItemStack ias = this.getRequestBatches().getStack(idx);
|
||||
if (ias != null) {
|
||||
ItemStack is = ias.getItemStack();
|
||||
try {
|
||||
return is.getTagCompound().getBoolean("Enable");
|
||||
} catch (NullPointerException e) {
|
||||
// support old version
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isDone(int index) {
|
||||
if (this.getLinks()[index] != null) {
|
||||
return this.getLinks()[index].isDone() || this.getLinks()[index].isCanceled();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public Future<ICraftingJob>[] getJobs() {
|
||||
return this.jobs;
|
||||
}
|
||||
|
||||
public ICraftingLink[] getLinks() {
|
||||
return links;
|
||||
}
|
||||
|
||||
public AeStackInventory<IAEItemStack> getRequestQtys() {
|
||||
return this.requestQtys;
|
||||
}
|
||||
|
||||
public AeStackInventory<IAEItemStack> getRequestBatches() {
|
||||
return this.requestBatches;
|
||||
}
|
||||
|
||||
public AeStackInventory<IAEItemStack> getRequestStacks() {
|
||||
return this.requestStacks;
|
||||
}
|
||||
|
||||
public void updateQuantity(int idx, long size) {
|
||||
IAEItemStack is = this.getRequestStacks().getStack(idx);
|
||||
if (is != null) {
|
||||
IAEItemStack i = is.copy();
|
||||
i.setStackSize(size);
|
||||
this.getRequestQtys().setStack(idx, i);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateBatchSize(int idx, long size) {
|
||||
IAEItemStack ias = this.getRequestStacks().getStack(idx);
|
||||
if (ias != null) {
|
||||
ItemStack is = ias.copy().getItemStack();
|
||||
NBTTagCompound data = new NBTTagCompound();
|
||||
data.setBoolean("Enable", true);
|
||||
is.setTagCompound(data);
|
||||
IAEItemStack i = AEItemStack.create(is);
|
||||
i.setStackSize(size);
|
||||
this.getRequestBatches().setStack(idx, i);
|
||||
}
|
||||
}
|
||||
|
||||
public IAEItemStack getRequestQtyStack(int idx) {
|
||||
IAEItemStack is = this.getRequestStacks().getStack(idx);
|
||||
if (is == null) return null;
|
||||
IAEItemStack qis = this.getRequestQtys().getStack(idx);
|
||||
if (qis == null || !is.isSameType(qis)) return null;
|
||||
return this.getRequestQtys().getStack(idx);
|
||||
}
|
||||
|
||||
public long getQuantity(int idx) {
|
||||
IAEItemStack ias = this.getRequestQtyStack(idx);
|
||||
if (ias == null) {
|
||||
return 0;
|
||||
}
|
||||
return ias.getStackSize();
|
||||
}
|
||||
|
||||
public long getBatchSize(int idx) {
|
||||
if (!this.isEnable(idx)) return 0;
|
||||
IAEItemStack is = this.getRequestStacks().getStack(idx);
|
||||
IAEItemStack is1 = this.getRequestBatches().getStack(idx);
|
||||
if (is != null && is1 != null) {
|
||||
return is1.getStackSize();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public IAEItemStack getCraftItem(int idx) {
|
||||
IAEItemStack is = this.getRequestQtyStack(idx);
|
||||
if (is != null) {
|
||||
IAEItemStack ias = is.copy();
|
||||
ias.setStackSize(this.getBatchSize(idx));
|
||||
return ias;
|
||||
public boolean isEnable(int idx) {
|
||||
IAEItemStack ias = requestStacks.getStack(idx);
|
||||
if (ias == null) {
|
||||
return true;
|
||||
}
|
||||
return null;
|
||||
|
||||
ItemStack is = ias.getItemStack();
|
||||
return is.hasTagCompound() ? is.getTagCompound().getBoolean(TLMTags.Enable.tagName) : true;
|
||||
}
|
||||
|
||||
public boolean isDone(int index) {
|
||||
if (links[index] == null) {
|
||||
return true;
|
||||
}
|
||||
return links[index].isDone() || links[index].isCanceled();
|
||||
}
|
||||
|
||||
public Future<ICraftingJob> getJob(int idx) {
|
||||
return jobs[idx];
|
||||
}
|
||||
|
||||
public ICraftingLink getLink(int idx) {
|
||||
return links[idx];
|
||||
}
|
||||
|
||||
public void updateJob(int idx, Future<ICraftingJob> job) {
|
||||
jobs[idx] = job;
|
||||
}
|
||||
|
||||
private void updateField(int idx, UnaryOperator<NBTTagCompound> updater) {
|
||||
IAEItemStack ias = requestStacks.getStack(idx);
|
||||
if (ias == null) return;
|
||||
|
||||
ItemStack itemStack = ias.getItemStack();
|
||||
NBTTagCompound data = itemStack.hasTagCompound() ? itemStack.getTagCompound() : new NBTTagCompound();
|
||||
data.setInteger(TLMTags.Index.tagName, idx);
|
||||
itemStack.setTagCompound(updater.apply(data));
|
||||
IAEItemStack newRequestStack = AEItemStack.create(itemStack);
|
||||
newRequestStack.setStackSize(ias.getStackSize());
|
||||
requestStacks.setStack(idx, newRequestStack);
|
||||
|
||||
}
|
||||
|
||||
public void updateLink(int idx, ICraftingLink link) {
|
||||
links[idx] = link;
|
||||
|
||||
updateField(idx, data -> {
|
||||
NBTTagCompound linkData = new NBTTagCompound();
|
||||
if (link != null) link.writeToNBT(linkData);
|
||||
data.setTag(TLMTags.Link.tagName, linkData);
|
||||
|
||||
return data;
|
||||
});
|
||||
}
|
||||
|
||||
public void updateState(int idx, State nextState) {
|
||||
state[idx] = nextState;
|
||||
|
||||
updateField(idx, data -> {
|
||||
data.setInteger(TLMTags.State.tagName, nextState.ordinal());
|
||||
|
||||
return data;
|
||||
});
|
||||
}
|
||||
|
||||
public void updateStatus(int idx, boolean enable) {
|
||||
updateField(idx, data -> {
|
||||
State nextState = enable ? State.Idle : State.None;
|
||||
|
||||
data.setBoolean(TLMTags.Enable.tagName, enable);
|
||||
data.setInteger(TLMTags.State.tagName, nextState.ordinal());
|
||||
return data;
|
||||
});
|
||||
}
|
||||
|
||||
public void updateQuantity(int idx, long quantity) {
|
||||
updateField(idx, data -> {
|
||||
data.setLong(TLMTags.Quantity.tagName, quantity);
|
||||
|
||||
return data;
|
||||
});
|
||||
}
|
||||
|
||||
public void updateBatchSize(int idx, long batch) {
|
||||
updateField(idx, data -> {
|
||||
data.setLong(TLMTags.Batch.tagName, batch);
|
||||
data.setBoolean(TLMTags.Enable.tagName, true);
|
||||
|
||||
return data;
|
||||
});
|
||||
}
|
||||
|
||||
public void updateStack(int idx, ItemStack itemStack) {
|
||||
updateField(idx, data -> {
|
||||
NBTTagCompound stackData = new NBTTagCompound();
|
||||
if (itemStack != null) itemStack.writeToNBT(stackData);
|
||||
data.setTag(TLMTags.Stack.tagName, stackData);
|
||||
|
||||
return data;
|
||||
});
|
||||
}
|
||||
|
||||
public IAEItemStack getAEItemStack(int idx) {
|
||||
return requestStacks.getStack(idx);
|
||||
}
|
||||
|
||||
public ItemStack getItemStack(int idx) {
|
||||
return requestStacks.getStack(idx).getItemStack();
|
||||
}
|
||||
|
||||
public long getQuantity(int idx) {
|
||||
if (!isEnable(idx)) return 0;
|
||||
IAEItemStack ias = requestStacks.getStack(idx);
|
||||
if (ias == null) return 0;
|
||||
ItemStack itemStack = ias.getItemStack();
|
||||
if (!itemStack.hasTagCompound()) return 0;
|
||||
|
||||
return itemStack.getTagCompound().getLong(TLMTags.Quantity.tagName);
|
||||
}
|
||||
|
||||
public long getBatchSize(int idx) {
|
||||
if (!isEnable(idx)) return 0;
|
||||
IAEItemStack ias = requestStacks.getStack(idx);
|
||||
if (ias == null) return 0;
|
||||
ItemStack itemStack = ias.getItemStack();
|
||||
if (!itemStack.hasTagCompound()) return 0;
|
||||
|
||||
return itemStack.getTagCompound().getLong(TLMTags.Batch.tagName);
|
||||
}
|
||||
|
||||
public IAEItemStack getCraftItem(int idx) {
|
||||
IAEItemStack is = requestStacks.getStack(idx);
|
||||
if (is == null) return null;
|
||||
if (is.getItemStack() == null) return null;
|
||||
ItemStack qis = loadItemStackFromTag(is.getItemStack());
|
||||
if (qis == null) return null;
|
||||
IAEItemStack qais = AEItemStack.create(qis);
|
||||
qais.setStackSize(getBatchSize(idx));
|
||||
|
||||
return qais;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user