forked from AE2-UEL/AE2FluidCraft-Rework
-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed essentia level maintaining (#245)
Co-authored-by: Martin Robertz <[email protected]> Co-authored-by: Maya <[email protected]> Co-authored-by: lailani-f <[email protected]>
- Loading branch information
1 parent
353b9a4
commit 9fbea64
Showing
3 changed files
with
148 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
src/main/java/com/glodblock/github/crossmod/thaumcraft/ThaumicEnergisticsCrafting.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
|
||
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()); | ||
} | ||
|
||
/** | ||
* 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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters