mirror of
https://github.com/GTNewHorizons/ThaumicEnergistics.git
synced 2026-10-25 20:32:27 +00:00
Fix Arcane Assembler crafting tasks not viewable in tree view (#97)
This commit is contained in:
1 parent
283bb6049c
commit
4a6c45e2e5
7 files changed
+182
-128
No files matched your search
@@ -42,4 +42,11 @@ public class ClientProxy extends CommonProxy {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerItems() {
|
||||
super.registerItems();
|
||||
// hide technical item from NEI
|
||||
codechicken.nei.api.API.hideItem(ItemEnum.ARCANE_PATTERN.getStack());
|
||||
}
|
||||
}
|
||||
@@ -490,7 +490,7 @@ public class ContainerKnowledgeInscriber extends ContainerWithPlayerInventory {
|
||||
|
||||
// Create the pattern
|
||||
ArcaneCraftingPattern pattern = new ArcaneCraftingPattern(
|
||||
this.kCoreSlot.getStack(),
|
||||
|
||||
recipeAspects,
|
||||
this.resultSlot.getStack(),
|
||||
inputs);
|
||||
|
||||
+69
-112
@@ -2,7 +2,7 @@ package thaumicenergistics.common.integration.tc;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -13,11 +13,13 @@ import net.minecraftforge.oredict.OreDictionary;
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.networking.crafting.ICraftingPatternDetails;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.helpers.PatternHelper;
|
||||
import appeng.util.item.AEItemStack;
|
||||
import thaumcraft.api.ThaumcraftApiHelper;
|
||||
import thaumcraft.api.aspects.Aspect;
|
||||
import thaumcraft.api.aspects.AspectList;
|
||||
import thaumcraft.common.items.ItemEldritchObject;
|
||||
import thaumicenergistics.common.items.ItemArcaneCraftingPattern;
|
||||
|
||||
public class ArcaneCraftingPattern implements ICraftingPatternDetails {
|
||||
|
||||
@@ -30,6 +32,7 @@ public class ArcaneCraftingPattern implements ICraftingPatternDetails {
|
||||
/**
|
||||
* Aspects required.
|
||||
*/
|
||||
@Nonnull
|
||||
protected AspectList aspects;
|
||||
|
||||
/**
|
||||
@@ -42,11 +45,6 @@ public class ArcaneCraftingPattern implements ICraftingPatternDetails {
|
||||
*/
|
||||
protected IAEItemStack result;
|
||||
|
||||
/**
|
||||
* The knowledge core this pattern belongs to.
|
||||
*/
|
||||
protected ItemStack knowledgeCoreHost;
|
||||
|
||||
/**
|
||||
* Cached array of required aspects
|
||||
*/
|
||||
@@ -56,11 +54,7 @@ public class ArcaneCraftingPattern implements ICraftingPatternDetails {
|
||||
* Ingredients as AE itemstacks.
|
||||
*/
|
||||
protected IAEItemStack[] ingredientsAE = null;
|
||||
|
||||
/**
|
||||
* List of all output items, results + containers
|
||||
*/
|
||||
protected IAEItemStack[] allResults = null;
|
||||
protected IAEItemStack[] ingredientsAECondensed = null;
|
||||
|
||||
/**
|
||||
* True if the recipe is valid.
|
||||
@@ -69,15 +63,12 @@ public class ArcaneCraftingPattern implements ICraftingPatternDetails {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param knowledgeCore
|
||||
* @param aspects
|
||||
* @param craftingResult
|
||||
* @param craftingIngredients
|
||||
*/
|
||||
public ArcaneCraftingPattern(final ItemStack knowledgeCore, final AspectList aspects,
|
||||
final ItemStack craftingResult, final Object[] craftingIngredients) {
|
||||
// Set the core
|
||||
this.knowledgeCoreHost = knowledgeCore;
|
||||
public ArcaneCraftingPattern(final AspectList aspects, final ItemStack craftingResult,
|
||||
final Object[] craftingIngredients) {
|
||||
|
||||
// Set the aspects
|
||||
this.aspects = aspects.copy();
|
||||
@@ -104,12 +95,9 @@ public class ArcaneCraftingPattern implements ICraftingPatternDetails {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param knowledgeCore
|
||||
* @param data
|
||||
*/
|
||||
public ArcaneCraftingPattern(@Nullable final ItemStack knowledgeCore, final NBTTagCompound data) {
|
||||
// Set the host
|
||||
this.knowledgeCoreHost = knowledgeCore;
|
||||
public ArcaneCraftingPattern(final NBTTagCompound data) {
|
||||
|
||||
// Create the aspect list
|
||||
this.aspects = new AspectList();
|
||||
@@ -217,47 +205,6 @@ public class ArcaneCraftingPattern implements ICraftingPatternDetails {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up all results, including container items.
|
||||
*/
|
||||
private void setupAEResults() {
|
||||
// Ensure the ingredient list is made
|
||||
if (this.ingredientsAE == null) {
|
||||
this.setupAEIngredientList();
|
||||
}
|
||||
|
||||
ArrayList<IAEItemStack> results = new ArrayList<IAEItemStack>();
|
||||
|
||||
// Add any container items
|
||||
for (IAEItemStack stack : this.ingredientsAE) {
|
||||
if (stack == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Container?
|
||||
if (stack.getItem().hasContainerItem(stack.getItemStack())) {
|
||||
results.add(
|
||||
AEApi.instance().storage()
|
||||
.createItemStack(stack.getItem().getContainerItem(stack.getItemStack())));
|
||||
}
|
||||
|
||||
// Multiplier?
|
||||
else if (stack.getStackSize() > 1) {
|
||||
results.add(stack.copy().setStackSize(stack.getStackSize() - 1));
|
||||
}
|
||||
// Primordial Pearl?
|
||||
else if ((stack.getItem() instanceof ItemEldritchObject) && (stack.getItemDamage() == 3)) {
|
||||
results.add(stack);
|
||||
}
|
||||
}
|
||||
|
||||
// Add result
|
||||
results.add(this.result);
|
||||
|
||||
// Set the outputs
|
||||
this.allResults = results.toArray(new IAEItemStack[results.size()]);
|
||||
}
|
||||
|
||||
protected void setPatternValidity(final boolean valid) {
|
||||
// Set
|
||||
this.isValid = valid;
|
||||
@@ -281,36 +228,36 @@ public class ArcaneCraftingPattern implements ICraftingPatternDetails {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* This includes container items.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public IAEItemStack[] getAllResults() {
|
||||
if (this.allResults == null) {
|
||||
this.setupAEResults();
|
||||
}
|
||||
return this.allResults;
|
||||
}
|
||||
|
||||
public void updateInventory(InventoryCrafting table) {
|
||||
if (this.ingredientsAE == null) this.ingredientsAE = new AEItemStack[ArcaneCraftingPattern.GRID_SIZE];
|
||||
boolean inventoryUnchanged = true;
|
||||
public ItemStack[] getAllOutputs(InventoryCrafting table) {
|
||||
ArrayList<ItemStack> results = new ArrayList<>();
|
||||
for (int i = 0; i < 9; ++i) {
|
||||
ItemStack s = table.getStackInSlot(i);
|
||||
|
||||
if (s == null) {
|
||||
if (ingredientsAE[i] == null) continue;
|
||||
inventoryUnchanged = false;
|
||||
ingredientsAE[i] = null;
|
||||
} else {
|
||||
AEItemStack aestack = (AEItemStack) AEApi.instance().storage().createItemStack(s);
|
||||
if (ingredientsAE[i] == null || ingredientsAE[i].hashCode() != aestack.hashCode()) {
|
||||
ingredientsAE[i] = aestack;
|
||||
inventoryUnchanged = false;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
// Container?
|
||||
if (s.getItem().hasContainerItem(s)) {
|
||||
results.add(s.getItem().getContainerItem(s));
|
||||
}
|
||||
|
||||
// Multiplier?
|
||||
else if (s.stackSize > 1) {
|
||||
ItemStack copy = s.copy();
|
||||
copy.stackSize--;
|
||||
results.add(copy);
|
||||
}
|
||||
// Primordial Pearl?
|
||||
else if ((s.getItem() instanceof ItemEldritchObject) && (s.getItemDamage() == 3)) {
|
||||
results.add(s);
|
||||
}
|
||||
}
|
||||
if (!inventoryUnchanged) setupAEResults();
|
||||
|
||||
// Add result
|
||||
results.add(this.result.getItemStack());
|
||||
|
||||
return results.toArray(new ItemStack[results.size()]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -337,22 +284,11 @@ public class ArcaneCraftingPattern implements ICraftingPatternDetails {
|
||||
|
||||
@Override
|
||||
public IAEItemStack[] getCondensedInputs() {
|
||||
// Create a temp array
|
||||
ArrayList<IAEItemStack> cond = new ArrayList<IAEItemStack>();
|
||||
|
||||
if (this.ingredientsAE == null) {
|
||||
this.setupAEIngredientList();
|
||||
if (this.ingredientsAECondensed == null) {
|
||||
ingredientsAECondensed = PatternHelper.convertToCondensedList(getInputs());
|
||||
}
|
||||
|
||||
// Add non-null ingredients
|
||||
for (int index = 0; index < this.ingredientsAE.length; index++) {
|
||||
if (this.ingredientsAE[index] != null) {
|
||||
cond.add(this.ingredientsAE[index]);
|
||||
}
|
||||
}
|
||||
|
||||
// Return the ingredients
|
||||
return cond.toArray(new IAEItemStack[cond.size()]);
|
||||
return ingredientsAECondensed;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -387,7 +323,7 @@ public class ArcaneCraftingPattern implements ICraftingPatternDetails {
|
||||
|
||||
@Override
|
||||
public ItemStack getPattern() {
|
||||
return this.knowledgeCoreHost;
|
||||
return ItemArcaneCraftingPattern.getItemFromPattern(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -429,8 +365,8 @@ public class ArcaneCraftingPattern implements ICraftingPatternDetails {
|
||||
// Null detected
|
||||
return false;
|
||||
}
|
||||
|
||||
return ArcaneCraftingPattern.canSubstitueFor(ing, input);
|
||||
boolean sub = ArcaneCraftingPattern.canSubstitueFor(ing, input);
|
||||
return sub;
|
||||
}
|
||||
|
||||
public void readFromNBT(final NBTTagCompound data) {
|
||||
@@ -600,15 +536,6 @@ public class ArcaneCraftingPattern implements ICraftingPatternDetails {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the knowledge core.
|
||||
*
|
||||
* @param knowledgeCore
|
||||
*/
|
||||
public void setKnowledgeCore(final ItemStack knowledgeCore) {
|
||||
this.knowledgeCoreHost = knowledgeCore;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPriority(final int priority) {
|
||||
// Ignored.
|
||||
@@ -682,4 +609,34 @@ public class ArcaneCraftingPattern implements ICraftingPatternDetails {
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
|
||||
if (super.equals(obj)) {
|
||||
return true;
|
||||
} ;
|
||||
if (!(obj instanceof ArcaneCraftingPattern other)) {
|
||||
return false;
|
||||
}
|
||||
if (!(obj.hashCode() == this.hashCode())) {
|
||||
return false;
|
||||
}
|
||||
if (!(tag.equals(other.tag))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private int hash;
|
||||
private NBTTagCompound tag;
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
if (tag == null) {
|
||||
hash = writeToNBT(tag = new NBTTagCompound()).hashCode();
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
}
|
||||
@@ -87,7 +87,7 @@ public class HandlerKnowledgeCore {
|
||||
try {
|
||||
// Load the pattern
|
||||
ArcaneCraftingPattern pattern = new ArcaneCraftingPattern(
|
||||
this.kCore,
|
||||
|
||||
plist.getCompoundTagAt(index));
|
||||
|
||||
// Is the pattern valid?
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
package thaumicenergistics.common.items;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import appeng.api.implementations.ICraftingPatternItem;
|
||||
import appeng.api.networking.crafting.ICraftingPatternDetails;
|
||||
import thaumicenergistics.common.integration.tc.ArcaneCraftingPattern;
|
||||
|
||||
/**
|
||||
* This is a technical item used to serialize/deserialize Knowlegde Core crafting tasks. It cannot be crafted and should
|
||||
* be invisible to players.
|
||||
*/
|
||||
public class ItemArcaneCraftingPattern extends Item implements ICraftingPatternItem {
|
||||
|
||||
public ItemArcaneCraftingPattern() {
|
||||
this.setUnlocalizedName("itemArcaneCraftingPattern");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICraftingPatternDetails getPatternForItem(ItemStack is, World w) {
|
||||
if (is == null) return null;
|
||||
if (is.hasTagCompound()) {
|
||||
|
||||
NBTTagCompound tag = is.getTagCompound();
|
||||
NBTTagCompound pattern = tag.getCompoundTag("pattern");
|
||||
if (pattern != null) return new ArcaneCraftingPattern(pattern);
|
||||
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
public static ItemStack getItemFromPattern(ArcaneCraftingPattern arcaneCraftingPattern) {
|
||||
if (arcaneCraftingPattern == null) return null;
|
||||
ItemStack is = new ItemStack(ItemEnum.ARCANE_PATTERN.getItem());
|
||||
NBTTagCompound pattern = new NBTTagCompound();
|
||||
arcaneCraftingPattern.writeToNBT(pattern);
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
tag.setTag("pattern", pattern);
|
||||
is.setTagCompound(tag);
|
||||
return is;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -23,7 +23,8 @@ public enum ItemEnum {
|
||||
FOCUS_AEWRENCH("focus.aewrench", new ItemFocusAEWrench()),
|
||||
CRAFTING_ASPECT("crafting.aspect", new ItemCraftingAspect()),
|
||||
GOLEM_WIFI_BACKPACK("golem.wifi.backpack", new ItemGolemWirelessBackpack()),
|
||||
CELL_MICROSCOPE("cell.microscope", new ItemCellMicroscope());
|
||||
CELL_MICROSCOPE("cell.microscope", new ItemCellMicroscope()),
|
||||
ARCANE_PATTERN("arcane.pattern", new ItemArcaneCraftingPattern());
|
||||
|
||||
/**
|
||||
* Cache of the enum values
|
||||
|
||||
@@ -11,6 +11,7 @@ import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
@@ -57,6 +58,7 @@ import thaumicenergistics.api.ThEApi;
|
||||
import thaumicenergistics.api.grid.IDigiVisSource;
|
||||
import thaumicenergistics.client.gui.ThEGuiHelper;
|
||||
import thaumicenergistics.common.blocks.BlockArcaneAssembler;
|
||||
import thaumicenergistics.common.blocks.BlockEnum;
|
||||
import thaumicenergistics.common.integration.IWailaSource;
|
||||
import thaumicenergistics.common.integration.tc.ArcaneCraftingPattern;
|
||||
import thaumicenergistics.common.integration.tc.DigiVisSourceData;
|
||||
@@ -115,7 +117,8 @@ public class TileArcaneAssembler extends AENetworkInvTile implements ICraftingPr
|
||||
* NBT Keys
|
||||
*/
|
||||
private static final String NBTKEY_VIS_INTERFACE = "vis_interface", NBTKEY_UPGRADES = "upgradeCount",
|
||||
NBTKEY_UPGRADEINV = "upgrades", NBTKEY_CRAFTING = "isCrafting", NBTKEY_CRAFTING_PATTERN = "pattern";
|
||||
NBTKEY_UPGRADEINV = "upgrades", NBTKEY_CRAFTING = "isCrafting", NBTKEY_CRAFTING_PATTERN = "pattern",
|
||||
NBTKEY_RESULT = "result";
|
||||
|
||||
/**
|
||||
* NBT Key for stored vis.
|
||||
@@ -179,6 +182,11 @@ public class TileArcaneAssembler extends AENetworkInvTile implements ICraftingPr
|
||||
*/
|
||||
private ArcaneCraftingPattern currentPattern = null;
|
||||
|
||||
/**
|
||||
* The items to be returned when crafting finishes.
|
||||
*/
|
||||
private ItemStack[] currentResult;
|
||||
|
||||
/**
|
||||
* Handles interaction with the knowledge core.
|
||||
*/
|
||||
@@ -342,9 +350,11 @@ public class TileArcaneAssembler extends AENetworkInvTile implements ICraftingPr
|
||||
|
||||
// Simulate placing the items
|
||||
boolean rejected = false;
|
||||
for (IAEItemStack output : this.currentPattern.getAllResults()) {
|
||||
IAEItemStack rejectedResult = storageGrid.getItemInventory()
|
||||
.injectItems(output, Actionable.SIMULATE, this.mySource);
|
||||
for (ItemStack output : this.currentResult) {
|
||||
IAEItemStack rejectedResult = storageGrid.getItemInventory().injectItems(
|
||||
AEApi.instance().storage().createItemStack(output),
|
||||
Actionable.SIMULATE,
|
||||
this.mySource);
|
||||
if ((rejectedResult != null) && (rejectedResult.getStackSize() > 0)) {
|
||||
rejected = true;
|
||||
break;
|
||||
@@ -354,8 +364,11 @@ public class TileArcaneAssembler extends AENetworkInvTile implements ICraftingPr
|
||||
// Were all items accepted?
|
||||
if (!rejected) {
|
||||
// Inject into the network
|
||||
for (IAEItemStack output : this.currentPattern.getAllResults()) {
|
||||
storageGrid.getItemInventory().injectItems(output, Actionable.MODULATE, this.mySource);
|
||||
for (ItemStack output : this.currentResult) {
|
||||
storageGrid.getItemInventory().injectItems(
|
||||
AEApi.instance().storage().createItemStack(output),
|
||||
Actionable.MODULATE,
|
||||
this.mySource);
|
||||
}
|
||||
|
||||
// Mark the assembler as no longer crafting
|
||||
@@ -365,6 +378,7 @@ public class TileArcaneAssembler extends AENetworkInvTile implements ICraftingPr
|
||||
|
||||
// Mark for network update
|
||||
this.markForDelayedUpdate();
|
||||
this.currentResult = null;
|
||||
}
|
||||
} catch (GridAccessException ignored) {}
|
||||
} else {
|
||||
@@ -854,11 +868,7 @@ public class TileArcaneAssembler extends AENetworkInvTile implements ICraftingPr
|
||||
|
||||
// Is there a knowledge core?
|
||||
if (this.internalInventory.getHasStack(KCORE_SLOT_INDEX)) {
|
||||
// Is there a pattern?
|
||||
if (this.currentPattern != null) {
|
||||
// Set the patterns core
|
||||
this.currentPattern.setKnowledgeCore(this.internalInventory.getStackInSlot(KCORE_SLOT_INDEX));
|
||||
}
|
||||
|
||||
} else if (this.currentPattern != null) {
|
||||
// Clear the pattern
|
||||
this.isCrafting = false;
|
||||
@@ -1032,7 +1042,7 @@ public class TileArcaneAssembler extends AENetworkInvTile implements ICraftingPr
|
||||
|
||||
// Set the pattern that is being crafted
|
||||
this.currentPattern = (ArcaneCraftingPattern) patternDetails;
|
||||
currentPattern.updateInventory(table);
|
||||
this.currentResult = currentPattern.getAllOutputs(table);
|
||||
|
||||
// Set the target item
|
||||
this.internalInventory
|
||||
@@ -1088,9 +1098,21 @@ public class TileArcaneAssembler extends AENetworkInvTile implements ICraftingPr
|
||||
// Read the pattern
|
||||
if (data.hasKey(TileArcaneAssembler.NBTKEY_CRAFTING_PATTERN)) {
|
||||
this.currentPattern = new ArcaneCraftingPattern(
|
||||
null,
|
||||
|
||||
data.getCompoundTag(TileArcaneAssembler.NBTKEY_CRAFTING_PATTERN));
|
||||
}
|
||||
// Read the cached result
|
||||
if (data.hasKey(TileArcaneAssembler.NBTKEY_RESULT)) {
|
||||
ArrayList<ItemStack> resultArray = new ArrayList<>();
|
||||
NBTTagList resultList = data.getTagList(TileArcaneAssembler.NBTKEY_RESULT, 10);
|
||||
for (int i = 0; i < resultList.tagCount(); i++) {
|
||||
NBTTagCompound tag = resultList.getCompoundTagAt(i);
|
||||
resultArray.add(ItemStack.loadItemStackFromNBT(tag));
|
||||
}
|
||||
if (!resultArray.isEmpty()) this.currentResult = resultArray.toArray(new ItemStack[0]);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1136,6 +1158,17 @@ public class TileArcaneAssembler extends AENetworkInvTile implements ICraftingPr
|
||||
TileArcaneAssembler.NBTKEY_CRAFTING_PATTERN,
|
||||
this.currentPattern.writeToNBT(new NBTTagCompound()));
|
||||
}
|
||||
// Write the cached result
|
||||
if (this.currentResult != null) {
|
||||
NBTTagList resultList = new NBTTagList();
|
||||
data.setTag(TileArcaneAssembler.NBTKEY_RESULT, resultList);
|
||||
for (ItemStack item : currentResult) {
|
||||
if (item != null) resultList.appendTag(item.writeToNBT(new NBTTagCompound()));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1148,4 +1181,12 @@ public class TileArcaneAssembler extends AENetworkInvTile implements ICraftingPr
|
||||
this.storedVis.writeToNBT(data, TileArcaneAssembler.NBTKEY_STORED_VIS);
|
||||
}
|
||||
}
|
||||
|
||||
private ItemStack crafterIcon;
|
||||
|
||||
@Override
|
||||
public ItemStack getCrafterIcon() {
|
||||
if (this.crafterIcon == null) this.crafterIcon = new ItemStack(BlockEnum.ARCANE_ASSEMBLER.getBlock());
|
||||
return this.crafterIcon;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user