Search in sources :

Example 1 with CapBankType

use of crazypants.enderio.powertools.machine.capbank.CapBankType in project EnderIO by SleepyTrousers.

the class CapBankClientNetwork method computeIODisplayInfo.

@Nonnull
private IOInfo computeIODisplayInfo(int xOrg, int yOrg, int zOrg, @Nonnull EnumFacing dir) {
    if (dir.getFrontOffsetY() != 0) {
        return IOInfo.SINGLE;
    }
    TileCapBank cb = getCapBankAt(xOrg, yOrg, zOrg);
    if (cb == null) {
        return IOInfo.SINGLE;
    }
    CapBankType type = cb.getType();
    EnumFacing left = dir.rotateYCCW();
    EnumFacing right = left.getOpposite();
    int hOff = 0;
    int vOff = 0;
    // step 1: find top left
    while (isIOType(xOrg + left.getFrontOffsetX(), yOrg, zOrg + left.getFrontOffsetZ(), dir, type)) {
        xOrg += left.getFrontOffsetX();
        zOrg += left.getFrontOffsetZ();
        hOff++;
    }
    while (isIOType(xOrg, yOrg + 1, zOrg, dir, type)) {
        yOrg++;
        vOff++;
    }
    if (isIOType(xOrg + left.getFrontOffsetX(), yOrg, zOrg + left.getFrontOffsetZ(), dir, type)) {
        // not a rectangle
        return IOInfo.SINGLE;
    }
    // step 2: find width
    int width = 1;
    int height = 1;
    int xTmp = xOrg;
    int yTmp = yOrg;
    int zTmp = zOrg;
    while (isIOType(xTmp + right.getFrontOffsetX(), yTmp, zTmp + right.getFrontOffsetZ(), dir, type)) {
        if (isIOType(xTmp + right.getFrontOffsetX(), yTmp + 1, zTmp + right.getFrontOffsetZ(), dir, type)) {
            // not a rectangle
            return IOInfo.SINGLE;
        }
        xTmp += right.getFrontOffsetX();
        zTmp += right.getFrontOffsetZ();
        width++;
    }
    // step 3: find height
    while (isIOType(xOrg, yTmp - 1, zOrg, dir, type)) {
        xTmp = xOrg;
        yTmp--;
        zTmp = zOrg;
        if (isIOType(xTmp + left.getFrontOffsetX(), yTmp, zTmp + left.getFrontOffsetZ(), dir, type)) {
            // not a rectangle
            return IOInfo.SINGLE;
        }
        for (int i = 1; i < width; i++) {
            xTmp += right.getFrontOffsetX();
            zTmp += right.getFrontOffsetZ();
            if (!isIOType(xTmp, yTmp, zTmp, dir, type)) {
                // not a rectangle
                return IOInfo.SINGLE;
            }
        }
        if (isIOType(xTmp + right.getFrontOffsetX(), yTmp, zTmp + right.getFrontOffsetZ(), dir, type)) {
            // not a rectangle
            return IOInfo.SINGLE;
        }
        height++;
    }
    xTmp = xOrg;
    yTmp--;
    zTmp = zOrg;
    for (int i = 0; i < width; i++) {
        if (isIOType(xTmp, yTmp, zTmp, dir, type)) {
            // not a rectangle
            return IOInfo.SINGLE;
        }
        xTmp += right.getFrontOffsetX();
        zTmp += right.getFrontOffsetZ();
    }
    if (width == 1 && height == 1) {
        return IOInfo.SINGLE;
    }
    if (hOff > 0 || vOff > 0) {
        return IOInfo.INSIDE;
    }
    return new IOInfo(width, height);
}
Also used : TileCapBank(crazypants.enderio.powertools.machine.capbank.TileCapBank) CapBankType(crazypants.enderio.powertools.machine.capbank.CapBankType) EnumFacing(net.minecraft.util.EnumFacing) Nonnull(javax.annotation.Nonnull)

Example 2 with CapBankType

use of crazypants.enderio.powertools.machine.capbank.CapBankType in project EnderIO by SleepyTrousers.

the class CapBankItemRenderMapper method mapItemRender.

@Override
@SideOnly(Side.CLIENT)
public List<Pair<IBlockState, ItemStack>> mapItemRender(@Nonnull Block block, @Nonnull ItemStack stack, @Nonnull ItemQuadCollector itemQuadCollector) {
    List<Pair<IBlockState, ItemStack>> states = new ArrayList<Pair<IBlockState, ItemStack>>();
    IBlockState defaultState = block.getDefaultState();
    states.add(Pair.of(defaultState.withProperty(RENDER, EnumMergingBlockRenderMode.sides).withProperty(CapBankType.KIND, CapBankType.NONE), (ItemStack) null));
    CapBankType bankType = CapBankType.getTypeFromMeta(stack.getItemDamage());
    defaultState = defaultState.withProperty(CapBankType.KIND, bankType);
    for (EnumFacing facing : EnumFacing.Plane.HORIZONTAL) {
        states.add(Pair.of(defaultState.withProperty(RENDER, EnumMergingBlockRenderMode.get(facing, EnumFacing.UP)), (ItemStack) null));
        states.add(Pair.of(defaultState.withProperty(RENDER, EnumMergingBlockRenderMode.get(facing, EnumFacing.DOWN)), (ItemStack) null));
        states.add(Pair.of(defaultState.withProperty(RENDER, EnumMergingBlockRenderMode.get(facing, facing.rotateYCCW())), (ItemStack) null));
        states.add(Pair.of(defaultState.withProperty(RENDER, EnumMergingBlockRenderMode.get(facing, facing.rotateYCCW(), EnumFacing.UP)), (ItemStack) null));
        states.add(Pair.of(defaultState.withProperty(RENDER, EnumMergingBlockRenderMode.get(facing, facing.rotateYCCW(), EnumFacing.DOWN)), (ItemStack) null));
    }
    return states;
}
Also used : CapBankType(crazypants.enderio.powertools.machine.capbank.CapBankType) IBlockState(net.minecraft.block.state.IBlockState) EnumFacing(net.minecraft.util.EnumFacing) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) Pair(org.apache.commons.lang3.tuple.Pair) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Aggregations

CapBankType (crazypants.enderio.powertools.machine.capbank.CapBankType)2 EnumFacing (net.minecraft.util.EnumFacing)2 TileCapBank (crazypants.enderio.powertools.machine.capbank.TileCapBank)1 ArrayList (java.util.ArrayList)1 Nonnull (javax.annotation.Nonnull)1 IBlockState (net.minecraft.block.state.IBlockState)1 ItemStack (net.minecraft.item.ItemStack)1 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)1 Pair (org.apache.commons.lang3.tuple.Pair)1