mirror of
https://github.com/GTNewHorizons/AE2FluidCraft-Rework.git
synced 2026-11-16 18:44:42 +00:00
Adapt to AE2 Stack Type API changes (#375)
Co-authored-by: Martin Robertz <[email protected]>
This commit is contained in:
1 parent
f02e72e96a
commit
dfabc1c62b
46 files changed
+225
-1364
No files matched your search
@@ -1,38 +0,0 @@
|
||||
package com.glodblock.github.crossmod.thaumcraft;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import com.glodblock.github.util.RenderUtil;
|
||||
|
||||
import thaumcraft.api.aspects.Aspect;
|
||||
import thaumcraft.client.lib.UtilsFX;
|
||||
|
||||
public class AspectRender {
|
||||
|
||||
public static final ResourceLocation UNKNOWN_TEXTURE = new ResourceLocation(
|
||||
"thaumcraft",
|
||||
"textures/aspects/_unknown.png");
|
||||
|
||||
public static void drawAspect(EntityPlayer player, int posX, int posY, float zLevel, Aspect aspect, long amount) {
|
||||
if (aspect == null || amount <= 0) {
|
||||
return;
|
||||
}
|
||||
if (AspectUtil.isPlayerDiscoveredAspect(player, aspect)) {
|
||||
UtilsFX.drawTag(posX, posY, aspect, 0, 0, zLevel);
|
||||
} else {
|
||||
Minecraft.getMinecraft().renderEngine.bindTexture(UNKNOWN_TEXTURE);
|
||||
RenderUtil.setGLColorFromInt(aspect.getColor());
|
||||
GL11.glDisable(GL11.GL_LIGHTING);
|
||||
GL11.glEnable(GL11.GL_BLEND);
|
||||
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
||||
UtilsFX.drawTexturedQuadFull(posX, posY, zLevel);
|
||||
GL11.glEnable(GL11.GL_LIGHTING);
|
||||
GL11.glDisable(GL11.GL_BLEND);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,154 +0,0 @@
|
||||
package com.glodblock.github.crossmod.thaumcraft;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
import org.apache.commons.lang3.tuple.ImmutablePair;
|
||||
import org.apache.commons.lang3.tuple.MutablePair;
|
||||
|
||||
import appeng.api.storage.data.IAEFluidStack;
|
||||
import appeng.util.item.AEFluidStack;
|
||||
import cpw.mods.fml.common.Optional;
|
||||
import thaumcraft.api.aspects.Aspect;
|
||||
import thaumcraft.api.aspects.IEssentiaContainerItem;
|
||||
import thaumcraft.common.Thaumcraft;
|
||||
import thaumicenergistics.api.ThEApi;
|
||||
import thaumicenergistics.api.storage.IAspectStack;
|
||||
import thaumicenergistics.common.fluids.GaseousEssentia;
|
||||
import thaumicenergistics.common.integration.tc.EssentiaItemContainerHelper;
|
||||
import thaumicenergistics.common.storage.AspectStack;
|
||||
|
||||
public class AspectUtil {
|
||||
|
||||
public static final EssentiaItemContainerHelper HELPER = EssentiaItemContainerHelper.INSTANCE;
|
||||
public static int R = 128;
|
||||
|
||||
@Optional.Method(modid = "thaumicenergistics")
|
||||
public static void init() {
|
||||
R = ThEApi.instance().config().conversionMultiplier();
|
||||
}
|
||||
|
||||
public static boolean isPlayerDiscoveredAspect(final EntityPlayer player, final Aspect aspect) {
|
||||
if (player != null && aspect != null) {
|
||||
return Thaumcraft.proxy.getPlayerKnowledge().hasDiscoveredAspect(player.getCommandSenderName(), aspect);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isEssentiaGas(Fluid fluid) {
|
||||
return fluid instanceof GaseousEssentia;
|
||||
}
|
||||
|
||||
public static boolean isEssentiaGas(FluidStack fluid) {
|
||||
return fluid != null && fluid.getFluid() instanceof GaseousEssentia;
|
||||
}
|
||||
|
||||
public static boolean isEssentiaGas(IAEFluidStack fluid) {
|
||||
return fluid != null && fluid.getFluid() instanceof GaseousEssentia;
|
||||
}
|
||||
|
||||
public static Aspect getAspectFromGas(FluidStack fluid) {
|
||||
if (!isEssentiaGas(fluid)) {
|
||||
return null;
|
||||
}
|
||||
GaseousEssentia gas = (GaseousEssentia) fluid.getFluid();
|
||||
return gas.getAspect();
|
||||
}
|
||||
|
||||
public static Aspect getAspectFromJar(ItemStack stack) {
|
||||
if (isEssentiaContainer(stack)) {
|
||||
return HELPER.getAspectInContainer(stack);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Aspect getAspectFromGas(IAEFluidStack fluid) {
|
||||
if (isEssentiaGas(fluid)) {
|
||||
return null;
|
||||
}
|
||||
GaseousEssentia gas = (GaseousEssentia) fluid.getFluid();
|
||||
return gas.getAspect();
|
||||
}
|
||||
|
||||
public static FluidStack getGasFromAspect(IAspectStack aspectStack) {
|
||||
if (aspectStack == null || aspectStack.isEmpty()) return null;
|
||||
return new FluidStack(
|
||||
GaseousEssentia.getGasFromAspect(aspectStack.getAspect()),
|
||||
(int) aspectStack.getStackSize() * R);
|
||||
}
|
||||
|
||||
public static boolean isEssentiaContainer(ItemStack stack) {
|
||||
return HELPER.getItemType(stack) != EssentiaItemContainerHelper.AspectItemType.Invalid
|
||||
&& HELPER.getItemType(stack) != EssentiaItemContainerHelper.AspectItemType.ItemAspect;
|
||||
}
|
||||
|
||||
public static AEFluidStack getAEGasFromContainer(ItemStack stack) {
|
||||
if (isEssentiaContainer(stack) && !isEmptyEssentiaContainer(stack)) {
|
||||
IAspectStack aspectStack = HELPER.getAspectStackFromContainer(stack);
|
||||
aspectStack.setStackSize(stack.stackSize * aspectStack.getStackSize());
|
||||
FluidStack gas = getGasFromAspect(aspectStack);
|
||||
return AEFluidStack.create(gas);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean isEmptyEssentiaContainer(ItemStack stack) {
|
||||
return HELPER.isContainerEmpty(stack) && isEssentiaContainer(stack);
|
||||
}
|
||||
|
||||
public static ItemStack setAspectAmount(ItemStack itemStack, int amount, Aspect aspect) {
|
||||
if (isEssentiaContainer(itemStack)) {
|
||||
IEssentiaContainerItem container = (IEssentiaContainerItem) itemStack.getItem();
|
||||
assert container != null;
|
||||
container.getAspects(itemStack).aspects.put(aspect, amount);
|
||||
return itemStack;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static MutablePair<Integer, ItemStack> fillEssentiaFromGas(ItemStack itemStack, FluidStack fluid) {
|
||||
if (isEssentiaContainer(itemStack) && isEssentiaGas(fluid)) {
|
||||
if (itemStack.stackSize != 1) {
|
||||
return null;
|
||||
}
|
||||
Aspect aspect = getAspectFromGas(fluid);
|
||||
int amount = fluid.amount / R;
|
||||
EssentiaItemContainerHelper.AspectItemType iType = HELPER.getItemType(itemStack);
|
||||
if (iType == EssentiaItemContainerHelper.AspectItemType.JarLabel) {
|
||||
ItemStack label = itemStack.copy();
|
||||
HELPER.setLabelAspect(label, aspect);
|
||||
}
|
||||
int cap = HELPER.getContainerCapacity(itemStack);
|
||||
int tryFill = Math.min(cap, amount);
|
||||
ImmutablePair<Integer, ItemStack> result = HELPER
|
||||
.injectIntoContainer(itemStack, new AspectStack(aspect, tryFill));
|
||||
return result != null ? new MutablePair<>(result.left * R, result.right) : null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static MutablePair<Integer, ItemStack> drainEssentiaFromGas(ItemStack itemStack, FluidStack fluid) {
|
||||
if (isEssentiaContainer(itemStack) && isEssentiaGas(fluid)) {
|
||||
Aspect aspect = getAspectFromGas(fluid);
|
||||
int amount = fluid.amount / R;
|
||||
IAspectStack contents = HELPER.getAspectStackFromContainer(itemStack);
|
||||
int drained;
|
||||
ItemStack stack = null;
|
||||
if (contents == null || !Objects.equals(contents.getAspect(), aspect)) {
|
||||
drained = 0;
|
||||
} else {
|
||||
ImmutablePair<Integer, ItemStack> result = HELPER
|
||||
.extractFromContainer(itemStack, new AspectStack(aspect, amount));
|
||||
drained = result == null ? 0 : result.left;
|
||||
stack = result == null ? null : result.right;
|
||||
}
|
||||
return stack == null ? null : new MutablePair<>(drained * R, stack);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
+13
-54
@@ -1,7 +1,5 @@
|
||||
package com.glodblock.github.crossmod.thaumcraft;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
@@ -11,14 +9,13 @@ 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 appeng.api.storage.data.IAEStack;
|
||||
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;
|
||||
import thaumicenergistics.common.storage.AEEssentiaStack;
|
||||
|
||||
public class ThaumicEnergisticsCrafting {
|
||||
|
||||
@@ -39,6 +36,17 @@ public class ThaumicEnergisticsCrafting {
|
||||
return stack.getItem() == neiAddonAspect || stack.getItem() == thaumicEnergisticsAspect;
|
||||
}
|
||||
|
||||
public static IAEStack<?> convertItemAspectStack(IAEStack<?> stack) {
|
||||
if (stack instanceof IAEItemStack ais && isAspectStack(ais.getItemStack())) {
|
||||
Aspect aspect = getAspect(ais.getItemStack());
|
||||
if (aspect == null) return stack;
|
||||
|
||||
return new AEEssentiaStack(aspect, stack.getStackSize());
|
||||
} else {
|
||||
return stack;
|
||||
}
|
||||
}
|
||||
|
||||
@Method(modid = "thaumicenergistics")
|
||||
private static @Nullable Aspect getAspect(ItemStack stack) {
|
||||
if (stack == null) return null;
|
||||
@@ -59,53 +67,4 @@ public class ThaumicEnergisticsCrafting {
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -10,8 +10,6 @@ import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import com.glodblock.github.crossmod.waila.part.FluidInvWailaDataProvider;
|
||||
import com.glodblock.github.crossmod.waila.part.FluidMonitorWailaDataProvider;
|
||||
import com.glodblock.github.crossmod.waila.part.SpeedWailaDataProvider;
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
@@ -30,10 +28,8 @@ public class PartWailaDataProvider implements IWailaDataProvider {
|
||||
private final Tracer tracer = new Tracer();
|
||||
|
||||
public PartWailaDataProvider() {
|
||||
final IPartWailaDataProvider speed = new SpeedWailaDataProvider();
|
||||
final IPartWailaDataProvider fluidInv = new FluidInvWailaDataProvider();
|
||||
final IPartWailaDataProvider fluidMonitor = new FluidMonitorWailaDataProvider();
|
||||
this.providers = Lists.newArrayList(speed, fluidInv, fluidMonitor);
|
||||
this.providers = Lists.newArrayList(fluidInv);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -27,11 +27,6 @@ public class Tooltip {
|
||||
return String.format("0 mB / %s mB", NumberFormat.getInstance().format(capacity));
|
||||
}
|
||||
|
||||
public static String partFluidBusFormat(int amount) {
|
||||
return String
|
||||
.format("%s: %s mB/t", I18n.format(NameConst.WAILA_SPEED), NumberFormat.getInstance().format(amount));
|
||||
}
|
||||
|
||||
public static String tileFluidInterfaceFormat(String name, int amount, int face) {
|
||||
return String.format(
|
||||
"%s %s: %s mB",
|
||||
|
||||
-47
@@ -1,47 +0,0 @@
|
||||
package com.glodblock.github.crossmod.waila.part;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import com.glodblock.github.common.parts.base.FCPartMonitor;
|
||||
import com.glodblock.github.crossmod.waila.Tooltip;
|
||||
import com.glodblock.github.util.Util;
|
||||
|
||||
import appeng.api.parts.IPart;
|
||||
import appeng.api.storage.data.IAEFluidStack;
|
||||
import appeng.integration.modules.waila.part.BasePartWailaDataProvider;
|
||||
import mcp.mobius.waila.api.IWailaConfigHandler;
|
||||
import mcp.mobius.waila.api.IWailaDataAccessor;
|
||||
|
||||
public class FluidMonitorWailaDataProvider extends BasePartWailaDataProvider {
|
||||
|
||||
private final String key = "fluidStore";
|
||||
|
||||
@Override
|
||||
public List<String> getWailaBody(final IPart part, final List<String> currentToolTip,
|
||||
final IWailaDataAccessor accessor, final IWailaConfigHandler config) {
|
||||
if (part instanceof FCPartMonitor && accessor.getNBTData().hasKey(key)) {
|
||||
IAEFluidStack iaeFluidStack = Util.loadFluidStackFromNBT(accessor.getNBTData().getCompoundTag(key));
|
||||
if (iaeFluidStack != null) currentToolTip.add(
|
||||
Tooltip.fluidFormat(
|
||||
iaeFluidStack.getFluidStack().getLocalizedName(),
|
||||
iaeFluidStack.getStackSize()));
|
||||
}
|
||||
return currentToolTip;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound getNBTData(final EntityPlayerMP player, final IPart part, final TileEntity te,
|
||||
final NBTTagCompound tag, final World world, final int x, final int y, final int z) {
|
||||
if (part instanceof FCPartMonitor && ((FCPartMonitor) part).getAEStoreFluidStack() != null) {
|
||||
NBTTagCompound data = new NBTTagCompound();
|
||||
((FCPartMonitor) part).getAEStoreFluidStack().writeToNBT(data);
|
||||
tag.setTag(key, data);
|
||||
}
|
||||
return tag;
|
||||
}
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
package com.glodblock.github.crossmod.waila.part;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import com.glodblock.github.crossmod.waila.Tooltip;
|
||||
|
||||
import appeng.api.parts.IPart;
|
||||
import appeng.integration.modules.waila.part.BasePartWailaDataProvider;
|
||||
import appeng.parts.automation.PartSharedItemBus;
|
||||
import mcp.mobius.waila.api.IWailaConfigHandler;
|
||||
import mcp.mobius.waila.api.IWailaDataAccessor;
|
||||
|
||||
public class SpeedWailaDataProvider extends BasePartWailaDataProvider {
|
||||
|
||||
@Override
|
||||
public List<String> getWailaBody(final IPart part, final List<String> currentToolTip,
|
||||
final IWailaDataAccessor accessor, final IWailaConfigHandler config) {
|
||||
if (accessor.getNBTData().hasKey("BusSpeed")) {
|
||||
currentToolTip.add(Tooltip.partFluidBusFormat(accessor.getNBTData().getInteger("BusSpeed")));
|
||||
}
|
||||
return currentToolTip;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound getNBTData(final EntityPlayerMP player, final IPart part, final TileEntity te,
|
||||
final NBTTagCompound tag, final World world, final int x, final int y, final int z) {
|
||||
if (part instanceof PartSharedItemBus<?>bus) {
|
||||
tag.setInteger("BusSpeed", bus.calculateAmountToSend() / 5);
|
||||
}
|
||||
return tag;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user