IEssentiaTransport

基本信息

项目 值
来源 thaumcraft.api.aspects.IEssentiaTransport
包 thaumcraft.api.aspects
类型 接口

概述

IEssentiaTransport 接口用于具有元素(Vis/Essentia)传输功能的方块。实现了此接口的方块才能连接到元素导管或其他神秘学设备。

此接口由 TileEntity 类实现,用于管理元素的输入、输出和抽取逻辑。

连接性方法

isConnectable

boolean isConnectable(ForgeDirection face)

判断方块是否能在指定方向连接到其他元素用户/源。

参数:face - 要检查的方向 返回:是否可以连接

canInputFrom

boolean canInputFrom(ForgeDirection face)

判断指定方向是否用于输入元素。

参数:face - 要检查的方向 返回:是否可以输入

canOutputTo

boolean canOutputTo(ForgeDirection face)

判断指定方向是否用于输出元素。

参数:face - 要检查的方向 返回:是否可以输出

吸力/抽取方法

setSuction

void setSuction(Aspect aspect, int amount)

设置方块施加的吸力类型和强度。

参数:

  • aspect - 吸力类型(元素种类)
  • amount - 吸力强度

getSuctionType

Aspect getSuctionType(ForgeDirection face)

返回方块在指定方向施加的吸力类型。

参数:face - 要检查的方向 返回:元素类型

getSuctionAmount

int getSuctionAmount(ForgeDirection face)

返回方块在指定方向施加的吸力强度。

参数:face - 要检查的方向 返回:吸力强度数值

getMinimumSuction

int getMinimumSuction()

返回最小吸力阈值。吸力必须超过此值才会从容器中抽取元素。

返回:最小吸力值

元素传输方法

takeEssentia

int takeEssentia(Aspect aspect, int amount, ForgeDirection face)

从传输方块中抽取指定数量的元素。

参数:

  • aspect - 元素类型
  • amount - 要抽取的数量
  • face - 抽取方向

返回:实际抽取的数量

addEssentia

int addEssentia(Aspect aspect, int amount, ForgeDirection face)

向传输方块添加指定数量的元素。

参数:

  • aspect - 元素类型
  • amount - 要添加的数量
  • face - 添加方向

返回:实际添加的数量

元素信息方法

getEssentiaType

Aspect getEssentiaType(ForgeDirection face)

返回该方块包含的元素类型。

参数:face - 要检查的方向 返回:元素类型,如果没有则返回 null

getEssentiaAmount

int getEssentiaAmount(ForgeDirection face)

返回该方块包含的元素数量。

参数:face - 要检查的方向 返回:元素数量

渲染方法

renderExtendedTube

boolean renderExtendedTube()

返回 true 如果希望导管稍微延伸进入方块内部。用于 Jar 和 Alembic 等具有小于正常碰撞箱的方块。

返回:是否渲染扩展管

实现示例

public class MyVisConduit extends TileEntity implements IEssentiaTransport {
    
    private Aspect currentAspect = null;
    private int currentAmount = 0;
    private int suctionAmount = 0;
    
    @Override
    public boolean isConnectable(ForgeDirection face) {
        return true;  // 所有方向都可连接
    }
    
    @Override
    public boolean canInputFrom(ForgeDirection face) {
        return true;
    }
    
    @Override
    public boolean canOutputTo(ForgeDirection face) {
        return true;
    }
    
    @Override
    public void setSuction(Aspect aspect, int amount) {
        this.currentAspect = aspect;
        this.suctionAmount = amount;
    }
    
    @Override
    public Aspect getSuctionType(ForgeDirection face) {
        return currentAspect;
    }
    
    @Override
    public int getSuctionAmount(ForgeDirection face) {
        return suctionAmount;
    }
    
    @Override
    public int takeEssentia(Aspect aspect, int amount, ForgeDirection face) {
        int taken = Math.min(amount, currentAmount);
        currentAmount -= taken;
        return taken;
    }
    
    @Override
    public int addEssentia(Aspect aspect, int amount, ForgeDirection face) {
        if (currentAspect == null) {
            currentAspect = aspect;
            currentAmount = amount;
            return amount;
        }
        if (currentAspect == aspect) {
            currentAmount += amount;
            return amount;
        }
        return 0;  // 类型不匹配
    }
    
    @Override
    public Aspect getEssentiaType(ForgeDirection face) {
        return currentAspect;
    }
    
    @Override
    public int getEssentiaAmount(ForgeDirection face) {
        return currentAmount;
    }
    
    @Override
    public int getMinimumSuction() {
        return 0;
    }
    
    @Override
    public boolean renderExtendedTube() {
        return false;
    }
}