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 all 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,9 +14,11 @@
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;
import com.glodblock.github.util.ModAndClassUtil;
import com.google.common.collect.ImmutableSet;

import appeng.api.AEApi;
Expand Down Expand Up @@ -169,19 +171,45 @@ private TickRateModulation doWork() {
if (!isEnable || batchSize == 0) requests.updateState(i, State.None);
if (batchSize > 0) {
IAEItemStack craftItem = requests.getCraftItem(i);

if (ModAndClassUtil.ThE) {
if (craftItem != null && ThaumicEnergisticsCrafting.isAspectStack(craftItem.getItemStack())) {
craftItem = ThaumicEnergisticsCrafting.convertAspectStack(craftItem);
}
}

IAEItemStack aeItem = inv.findPrecise(craftItem);

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

if (ModAndClassUtil.ThE) {
if (aeItem != null && ThaumicEnergisticsCrafting.isAspectStack(aeItem.getItemStack())) {
stackSize = ThaumicEnergisticsCrafting.getEssentiaAmount(aeItem, grid);
}
}

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,111 @@
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 com.glodblock.github.util.ModAndClassUtil;

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 (!ModAndClassUtil.ThE || stack == null) return false;

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

@Method(modid = "thaumicenergistics")
private static @Nullable Aspect getAspect(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.getAspect(aspect);
}

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

return null;
}

@Method(modid = "thaumicenergistics")
private static ItemStack getAspectStack(Aspect aspect, int stackSize) {
return ItemCraftingAspect.createStackForAspect(aspect, stackSize);
}

/**
* Converts an aspect stack into a thaumic energistics stack.
*/
public static IAEItemStack convertAspectStack(IAEItemStack stack) {
if (ModAndClassUtil.ThE) {
return convertAspectStackImpl(stack);
} else {
return stack;
}
}

@Method(modid = "thaumicenergistics")
private static IAEItemStack convertAspectStackImpl(IAEItemStack stack) {
if (stack == null) return null;

Aspect aspect = getAspect(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.
*/
public static long getEssentiaAmount(IAEItemStack stack, IGrid grid) {
if (ModAndClassUtil.ThE) {
return getEssentiaAmountImpl(stack, grid);
} else {
return 0;
}
}

@Method(modid = "thaumicenergistics")
private static long getEssentiaAmountImpl(IAEItemStack stack, IGrid grid) {
Aspect aspect = getAspect(stack.getItemStack());

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