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

Fixed essentia level maintaining #245

Merged
merged 14 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from 8 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
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.glodblock.github.api.registries.ILevelViewable;
import com.glodblock.github.common.Config;
import com.glodblock.github.common.item.ItemFluidDrop;
import com.glodblock.github.crossmod.thaumcraft.ThaumicEnergisticsCrafting;
import com.glodblock.github.inventory.AeItemStackHandler;
import com.glodblock.github.inventory.AeStackInventory;
import com.glodblock.github.inventory.AeStackInventoryImpl;
Expand Down Expand Up @@ -169,19 +170,41 @@ private TickRateModulation doWork() {
if (!isEnable || batchSize == 0) requests.updateState(i, State.None);
if (batchSize > 0) {
IAEItemStack craftItem = requests.getCraftItem(i);

if (ThaumicEnergisticsCrafting.isAspectStack(craftItem.getItemStack())) {
Dream-Master marked this conversation as resolved.
Show resolved Hide resolved
craftItem = ThaumicEnergisticsCrafting.convertAspectStack(craftItem);
}

IAEItemStack aeItem = inv.findPrecise(craftItem);

long stackSize = aeItem == null ? 0 : aeItem.getStackSize();

if (aeItem != null && ThaumicEnergisticsCrafting.isAspectStack(aeItem.getItemStack())) {
stackSize = ThaumicEnergisticsCrafting.getEssentiaAmount(aeItem, grid);
RecursivePineapple marked this conversation as resolved.
Show resolved Hide resolved
}

boolean isDone = requests.isDone(i);
boolean isCraftable = aeItem != null && aeItem.isCraftable();
boolean shouldCraft = isCraftable && aeItem.getStackSize() < quantity;
boolean shouldCraft = isCraftable && stackSize < quantity;

if (isDone) requests.updateState(i, State.Idle);
if (!isCraftable) requests.updateState(i, State.Error);
if (allBusy || !isDone
|| !shouldCraft
|| craftingGrid.canEmitFor(craftItem)
|| craftingGrid.isRequesting(craftItem))

if (allBusy || !isDone || !shouldCraft) {
continue;
}

if (craftingGrid.canEmitFor(craftItem)) {
continue;
}

if (craftingGrid.isRequesting(craftItem)) {
continue;
}

// do crafting
Future<ICraftingJob> jobTask = requests.getJob(i);

if (jobTask == null) {
if (itemToBegin == null) {
itemToBegin = craftItem;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package com.glodblock.github.crossmod.thaumcraft;

import java.util.Objects;

import javax.annotation.Nullable;

import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;

import appeng.api.networking.IGrid;
import appeng.api.storage.data.IAEItemStack;
import appeng.util.item.AEItemStack;
import cpw.mods.fml.common.Optional.Method;
import cpw.mods.fml.common.registry.GameRegistry;
import thaumcraft.api.aspects.Aspect;
import thaumicenergistics.api.grid.IEssentiaGrid;
import thaumicenergistics.common.items.ItemCraftingAspect;

public class ThaumicEnergisticsCrafting {
RecursivePineapple marked this conversation as resolved.
Show resolved Hide resolved

public static Item neiAddonAspect, thaumicEnergisticsAspect;

public static void postInit() {
neiAddonAspect = GameRegistry.findItem("thaumcraftneiplugin", "Aspect");
thaumicEnergisticsAspect = GameRegistry.findItem("thaumicenergistics", "crafting.aspect");
}

/**
* Checks if a stack is an aspect preview (nei addon or thaumic energistics). Does not mean that the stack contains
* an aspect.
*/
public static boolean isAspectStack(ItemStack stack) {
if (stack == null) return false;

return stack.getItem() == neiAddonAspect || stack.getItem() == thaumicEnergisticsAspect;
}

@Nullable
@Method(modid = "thaumicenergistics")
public static String getAspectName(ItemStack stack) {
if (stack == null) return null;

if (stack.getItem() == neiAddonAspect) {
NBTTagCompound tag = stack.getTagCompound();
if (tag == null || !(tag.getTag("Aspects") instanceof NBTTagList aspects)) return null;
if (aspects.tagCount() != 1) return null;
String aspect = aspects.getCompoundTagAt(0).getString("key");
if (aspect.isEmpty()) return null;

return aspect;
OneEyeMaker marked this conversation as resolved.
Show resolved Hide resolved
}

if (stack.getItem() == thaumicEnergisticsAspect) {
return ItemCraftingAspect.getAspect(stack).getTag();
}

return null;
}

@Method(modid = "thaumicenergistics")
public static ItemStack getAspectStack(String aspectName, int stackSize) {
return ItemCraftingAspect.createStackForAspect(Aspect.getAspect(aspectName), stackSize);
}

/**
* Converts an aspect stack into a thaumic energistics stack.
*/
public static IAEItemStack convertAspectStack(IAEItemStack stack) {
if (stack == null) return null;

String aspect = getAspectName(stack.getItemStack());

if (aspect == null) return stack;

return Objects.requireNonNull(AEItemStack.create(getAspectStack(aspect, 1))).setStackSize(stack.getStackSize());
RecursivePineapple marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* Gets the amount of essentia stored in a grid for a given aspect preview.
*/
@Method(modid = "thaumicenergistics")
public static long getEssentiaAmount(IAEItemStack stack, IGrid grid) {
String aspectName = getAspectName(stack.getItemStack());

if (aspectName == null) return 0;

Aspect aspect = Aspect.getAspect(aspectName);

if (aspect == null) return 0;

IEssentiaGrid essentiaGrid = grid.getCache(IEssentiaGrid.class);

return essentiaGrid.getEssentiaAmount(aspect);
}
}
4 changes: 4 additions & 0 deletions src/main/java/com/glodblock/github/proxy/CommonProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.glodblock.github.common.tile.TileWalrus;
import com.glodblock.github.crossmod.extracells.EC2Replacer;
import com.glodblock.github.crossmod.thaumcraft.AspectUtil;
import com.glodblock.github.crossmod.thaumcraft.ThaumicEnergisticsCrafting;
import com.glodblock.github.inventory.external.AEFluidInterfaceHandler;
import com.glodblock.github.loader.ItemAndBlockHolder;
import com.glodblock.github.network.SPacketMEUpdateBuffer;
Expand Down Expand Up @@ -46,6 +47,9 @@ public void postInit(FMLPostInitializationEvent event) {
if (!ModAndClassUtil.EC2 && Config.replaceEC2) {
EC2Replacer.initReplacer();
}
if (ModAndClassUtil.ThE) {
ThaumicEnergisticsCrafting.postInit();
}
if (ModAndClassUtil.isBigInterface) {
Upgrades.PATTERN_CAPACITY.registerItem(new ItemStack(ItemAndBlockHolder.FLUID_INTERFACE), 3);
Upgrades.PATTERN_CAPACITY.registerItem(new ItemStack(ItemAndBlockHolder.INTERFACE), 3);
Expand Down