Search in sources :

Example 1 with TileFruitPod

use of forestry.arboriculture.gadgets.TileFruitPod in project ForestryMC by ForestryMC.

the class TreeHelper method setFruitBlock.

@Override
public boolean setFruitBlock(World world, IAlleleFruit allele, float sappiness, short[] indices, int x, int y, int z) {
    int direction = BlockUtil.getDirectionalMetadata(world, x, y, z);
    if (direction < 0) {
        return false;
    }
    boolean placed = ForestryBlock.pods.setBlock(world, x, y, z, direction, Defaults.FLAG_BLOCK_SYNCH);
    if (!placed) {
        return false;
    }
    if (!ForestryBlock.pods.isBlockEqual(world, x, y, z)) {
        return false;
    }
    TileFruitPod pod = BlockFruitPod.getPodTile(world, x, y, z);
    if (pod == null) {
        world.setBlockToAir(x, y, z);
        return false;
    }
    pod.setFruit(allele, sappiness, indices);
    world.markBlockForUpdate(x, y, z);
    return true;
}
Also used : TileFruitPod(forestry.arboriculture.gadgets.TileFruitPod)

Example 2 with TileFruitPod

use of forestry.arboriculture.gadgets.TileFruitPod in project ForestryMC by ForestryMC.

the class EventHandlerArboriculture method handleBonemeal.

@SubscribeEvent
public void handleBonemeal(BonemealEvent event) {
    if (!Proxies.common.isSimulating(event.world)) {
        return;
    }
    TileEntity tile = event.world.getTileEntity(event.x, event.y, event.z);
    if (tile instanceof TileSapling) {
        int result = ((TileSapling) tile).tryGrow(true);
        if (result == 1 || result == 2) {
            event.setResult(Result.ALLOW);
        }
    } else if (tile instanceof TileFruitPod) {
        if (((TileFruitPod) tile).canMature()) {
            ((TileFruitPod) tile).mature();
            event.setResult(Result.ALLOW);
        }
    } else if (tile instanceof IFruitBearer) {
        IFruitBearer bearer = (IFruitBearer) tile;
        if (bearer.getRipeness() < 1.0f) {
            bearer.addRipeness(1.0f);
            event.setResult(Result.ALLOW);
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IFruitBearer(forestry.api.genetics.IFruitBearer) TileSapling(forestry.arboriculture.gadgets.TileSapling) TileFruitPod(forestry.arboriculture.gadgets.TileFruitPod) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Example 3 with TileFruitPod

use of forestry.arboriculture.gadgets.TileFruitPod in project ForestryMC by ForestryMC.

the class FruitPodRenderingHandler method renderWorldBlock.

@Override
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) {
    int maturity = 0;
    BlockFruitPod blockPod = (BlockFruitPod) block;
    TileFruitPod pod = BlockFruitPod.getPodTile(world, x, y, z);
    if (pod != null) {
        maturity = pod.getMaturity();
    }
    Tessellator tessellator = Tessellator.instance;
    tessellator.setBrightness(blockPod.getMixedBrightnessForBlock(world, x, y, z));
    tessellator.setColorOpaque_F(1.0f, 1.0f, 1.0f);
    int metadata = world.getBlockMetadata(x, y, z);
    IIcon podIcon = blockPod.getIcon(world, x, y, z, metadata);
    int notchDirection = BlockDirectional.getDirection(metadata);
    int k1 = 4 + maturity * 2;
    int l1 = 5 + maturity * 2;
    double d0 = 15.0D - k1;
    double d1 = 15.0D;
    double d2 = 4.0D;
    double d3 = 4.0D + l1;
    double d4 = (double) podIcon.getInterpolatedU(d0);
    double d5 = (double) podIcon.getInterpolatedU(d1);
    double d6 = (double) podIcon.getInterpolatedV(d2);
    double d7 = (double) podIcon.getInterpolatedV(d3);
    double d8 = 0.0D;
    double d9 = 0.0D;
    switch(notchDirection) {
        case 0:
            d8 = 8.0D - k1 / 2;
            d9 = 15.0D - k1;
            break;
        case 1:
            d8 = 1.0D;
            d9 = 8.0D - k1 / 2;
            break;
        case 2:
            d8 = 8.0D - k1 / 2;
            d9 = 1.0D;
            break;
        case 3:
            d8 = 15.0D - k1;
            d9 = 8.0D - k1 / 2;
    }
    double d10 = x + d8 / 16.0D;
    double d11 = x + (d8 + k1) / 16.0D;
    double d12 = y + (12.0D - l1) / 16.0D;
    double d13 = y + 0.75D;
    double d14 = z + d9 / 16.0D;
    double d15 = z + (d9 + k1) / 16.0D;
    tessellator.addVertexWithUV(d10, d12, d14, d4, d7);
    tessellator.addVertexWithUV(d10, d12, d15, d5, d7);
    tessellator.addVertexWithUV(d10, d13, d15, d5, d6);
    tessellator.addVertexWithUV(d10, d13, d14, d4, d6);
    tessellator.addVertexWithUV(d11, d12, d15, d4, d7);
    tessellator.addVertexWithUV(d11, d12, d14, d5, d7);
    tessellator.addVertexWithUV(d11, d13, d14, d5, d6);
    tessellator.addVertexWithUV(d11, d13, d15, d4, d6);
    tessellator.addVertexWithUV(d11, d12, d14, d4, d7);
    tessellator.addVertexWithUV(d10, d12, d14, d5, d7);
    tessellator.addVertexWithUV(d10, d13, d14, d5, d6);
    tessellator.addVertexWithUV(d11, d13, d14, d4, d6);
    tessellator.addVertexWithUV(d10, d12, d15, d4, d7);
    tessellator.addVertexWithUV(d11, d12, d15, d5, d7);
    tessellator.addVertexWithUV(d11, d13, d15, d5, d6);
    tessellator.addVertexWithUV(d10, d13, d15, d4, d6);
    int i2 = k1;
    if (maturity >= 2) {
        i2 = k1 - 1;
    }
    d4 = (double) podIcon.getMinU();
    d5 = (double) podIcon.getInterpolatedU((double) i2);
    d6 = (double) podIcon.getMinV();
    d7 = (double) podIcon.getInterpolatedV((double) i2);
    tessellator.addVertexWithUV(d10, d13, d15, d4, d7);
    tessellator.addVertexWithUV(d11, d13, d15, d5, d7);
    tessellator.addVertexWithUV(d11, d13, d14, d5, d6);
    tessellator.addVertexWithUV(d10, d13, d14, d4, d6);
    tessellator.addVertexWithUV(d10, d12, d14, d4, d6);
    tessellator.addVertexWithUV(d11, d12, d14, d5, d6);
    tessellator.addVertexWithUV(d11, d12, d15, d5, d7);
    tessellator.addVertexWithUV(d10, d12, d15, d4, d7);
    d4 = (double) podIcon.getInterpolatedU(12.0D);
    d5 = (double) podIcon.getMaxU();
    d6 = (double) podIcon.getMinV();
    d7 = (double) podIcon.getInterpolatedV(4.0D);
    d8 = 8.0D;
    d9 = 0.0D;
    double d16;
    switch(notchDirection) {
        case 0:
            d8 = 8.0D;
            d9 = 12.0D;
            d16 = d4;
            d4 = d5;
            d5 = d16;
            break;
        case 1:
            d8 = 0.0D;
            d9 = 8.0D;
            break;
        case 2:
            d8 = 8.0D;
            d9 = 0.0D;
            break;
        case 3:
            d8 = 12.0D;
            d9 = 8.0D;
            d16 = d4;
            d4 = d5;
            d5 = d16;
    }
    d10 = x + d8 / 16.0D;
    d11 = x + (d8 + 4.0D) / 16.0D;
    d12 = y + 0.75D;
    d13 = y + 1.0D;
    d14 = z + d9 / 16.0D;
    d15 = z + (d9 + 4.0D) / 16.0D;
    if (notchDirection != 2 && notchDirection != 0) {
        if (notchDirection == 1 || notchDirection == 3) {
            tessellator.addVertexWithUV(d11, d12, d14, d4, d7);
            tessellator.addVertexWithUV(d10, d12, d14, d5, d7);
            tessellator.addVertexWithUV(d10, d13, d14, d5, d6);
            tessellator.addVertexWithUV(d11, d13, d14, d4, d6);
            tessellator.addVertexWithUV(d10, d12, d14, d5, d7);
            tessellator.addVertexWithUV(d11, d12, d14, d4, d7);
            tessellator.addVertexWithUV(d11, d13, d14, d4, d6);
            tessellator.addVertexWithUV(d10, d13, d14, d5, d6);
        }
    } else {
        tessellator.addVertexWithUV(d10, d12, d14, d5, d7);
        tessellator.addVertexWithUV(d10, d12, d15, d4, d7);
        tessellator.addVertexWithUV(d10, d13, d15, d4, d6);
        tessellator.addVertexWithUV(d10, d13, d14, d5, d6);
        tessellator.addVertexWithUV(d10, d12, d15, d4, d7);
        tessellator.addVertexWithUV(d10, d12, d14, d5, d7);
        tessellator.addVertexWithUV(d10, d13, d14, d5, d6);
        tessellator.addVertexWithUV(d10, d13, d15, d4, d6);
    }
    return true;
}
Also used : Tessellator(net.minecraft.client.renderer.Tessellator) IIcon(net.minecraft.util.IIcon) BlockFruitPod(forestry.arboriculture.gadgets.BlockFruitPod) TileFruitPod(forestry.arboriculture.gadgets.TileFruitPod)

Aggregations

TileFruitPod (forestry.arboriculture.gadgets.TileFruitPod)3 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)1 IFruitBearer (forestry.api.genetics.IFruitBearer)1 BlockFruitPod (forestry.arboriculture.gadgets.BlockFruitPod)1 TileSapling (forestry.arboriculture.gadgets.TileSapling)1 Tessellator (net.minecraft.client.renderer.Tessellator)1 TileEntity (net.minecraft.tileentity.TileEntity)1 IIcon (net.minecraft.util.IIcon)1