Search in sources :

Example 1 with TileEntityElevatorCaller

use of pneumaticCraft.common.tileentity.TileEntityElevatorCaller in project PneumaticCraft by MineMaarten.

the class BlockElevatorCaller method onNeighborBlockChange.

/**
     * Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are
     * their own) Args: x, y, z, neighbor blockID
     */
@Override
public void onNeighborBlockChange(World world, int x, int y, int z, Block block) {
    int oldMeta = world.getBlockMetadata(x, y, z);
    boolean wasPowered = oldMeta / 8 > 0;
    boolean isPowered = world.isBlockIndirectlyGettingPowered(x, y, z);
    if (!wasPowered && isPowered) {
        world.setBlockMetadataWithNotify(x, y, z, oldMeta + 8, 3);
        TileEntity te = world.getTileEntity(x, y, z);
        if (te instanceof TileEntityElevatorCaller) {
            setSurroundingElevators(world, x, y, z, ((TileEntityElevatorCaller) te).thisFloor);
        }
    } else if (wasPowered && !isPowered) {
        world.setBlockMetadataWithNotify(x, y, z, oldMeta - 8, 3);
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityElevatorCaller(pneumaticCraft.common.tileentity.TileEntityElevatorCaller)

Example 2 with TileEntityElevatorCaller

use of pneumaticCraft.common.tileentity.TileEntityElevatorCaller in project PneumaticCraft by MineMaarten.

the class BlockElevatorCaller method collisionRayTrace.

@Override
public MovingObjectPosition collisionRayTrace(World world, int x, int y, int z, Vec3 origin, Vec3 direction) {
    setBlockBounds(0, 0, 0, 1, 1, 1);
    MovingObjectPosition rayTrace = super.collisionRayTrace(world, x, y, z, origin, direction);
    ForgeDirection orientation = ForgeDirection.getOrientation(world.getBlockMetadata(x, y, z) & 7).getOpposite();
    if (rayTrace != null && rayTrace.sideHit == orientation.ordinal()) {
        TileEntity te = world.getTileEntity(x, y, z);
        if (te instanceof TileEntityElevatorCaller) {
            TileEntityElevatorCaller caller = (TileEntityElevatorCaller) te;
            for (TileEntityElevatorCaller.ElevatorButton button : caller.getFloors()) {
                float startX = 0, startZ = 0, endX = 0, endZ = 0;
                switch(orientation) {
                    case NORTH:
                        startZ = 0F;
                        endZ = 0.01F;
                        endX = 1 - (float) button.posX;
                        startX = 1 - ((float) button.posX + (float) button.width);
                        break;
                    case SOUTH:
                        startZ = 0.99F;
                        endZ = 1F;
                        startX = (float) button.posX;
                        endX = (float) button.posX + (float) button.width;
                        break;
                    case WEST:
                        startX = 0F;
                        endX = 0.01F;
                        startZ = (float) button.posX;
                        endZ = (float) button.posX + (float) button.width;
                        break;
                    case EAST:
                        startX = 0.99F;
                        endX = 1F;
                        endZ = 1 - (float) button.posX;
                        startZ = 1 - ((float) button.posX + (float) button.width);
                        break;
                }
                setBlockBounds(startX, 1 - (float) (button.posY + button.height), startZ, endX, 1 - (float) button.posY, endZ);
                MovingObjectPosition buttonTrace = super.collisionRayTrace(world, x, y, z, origin, direction);
                if (buttonTrace != null) {
                    if (startX > 0.01F && startX < 0.98F)
                        startX += 0.01F;
                    if (startZ > 0.01F && startZ < 0.98F)
                        startZ += 0.01F;
                    if (endX > 0.02F && endX < 0.99F)
                        endX -= 0.01F;
                    if (endZ > 0.02F && endZ < 0.99F)
                        endZ -= 0.01F;
                    setBlockBounds(startX, 1.01F - (float) (button.posY + button.height), startZ, endX, 0.99F - (float) button.posY, endZ);
                    buttonTrace.subHit = button.floorNumber;
                    return buttonTrace;
                }
            }
        }
    }
    setBlockBounds(0, 0, 0, 1, 1, 1);
    return rayTrace;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) MovingObjectPosition(net.minecraft.util.MovingObjectPosition) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) TileEntityElevatorCaller(pneumaticCraft.common.tileentity.TileEntityElevatorCaller)

Example 3 with TileEntityElevatorCaller

use of pneumaticCraft.common.tileentity.TileEntityElevatorCaller in project PneumaticCraft by MineMaarten.

the class RenderElevatorCaller method renderTileEntityAt.

@Override
public void renderTileEntityAt(TileEntity tileentity, double x, double y, double z, float f) {
    TileEntityElevatorCaller tile = (TileEntityElevatorCaller) tileentity;
    Tessellator tess = Tessellator.instance;
    GL11.glPushMatrix();
    GL11.glTranslated(x + 0.5, y + 1.5, z + 0.5);
    GL11.glScalef(1.0F, -1F, -1F);
    // GL11.glRotated(180, 0, 0, 1);
    PneumaticCraftUtils.rotateMatrixByMetadata(tileentity.getBlockMetadata());
    GL11.glTranslatef(-1, 0, -1);
    for (TileEntityElevatorCaller.ElevatorButton button : tile.getFloors()) {
        GL11.glDisable(GL11.GL_TEXTURE_2D);
        GL11.glDisable(GL11.GL_LIGHTING);
        tess.startDrawingQuads();
        tess.setColorRGBA_F(button.red, button.green, button.blue, 1F);
        tess.addVertex(button.posX + 0.5D, button.posY + 0.5D, 0.499D);
        tess.addVertex(button.posX + 0.5D, button.posY + button.height + 0.5D, 0.499D);
        tess.addVertex(button.posX + button.width + 0.5D, button.posY + button.height + 0.5D, 0.499D);
        tess.addVertex(button.posX + button.width + 0.5D, button.posY + 0.5D, 0.499D);
        tess.draw();
        GL11.glEnable(GL11.GL_TEXTURE_2D);
        GL11.glEnable(GL11.GL_LIGHTING);
        GL11.glPushMatrix();
        GL11.glTranslated(button.posX + 0.5D, button.posY + 0.5D, 0.498);
        GL11.glTranslated(button.width / 2, button.height / 2, 0);
        float textScale = Math.min((float) button.width / 10F, (float) button.height / 10F);
        GL11.glScalef(textScale, textScale, textScale);
        func_147498_b().drawString(button.buttonText, -func_147498_b().getStringWidth(button.buttonText) / 2, -func_147498_b().FONT_HEIGHT / 2, 0xFF000000);
        GL11.glPopMatrix();
    }
    GL11.glPopMatrix();
}
Also used : Tessellator(net.minecraft.client.renderer.Tessellator) TileEntityElevatorCaller(pneumaticCraft.common.tileentity.TileEntityElevatorCaller)

Aggregations

TileEntityElevatorCaller (pneumaticCraft.common.tileentity.TileEntityElevatorCaller)3 TileEntity (net.minecraft.tileentity.TileEntity)2 Tessellator (net.minecraft.client.renderer.Tessellator)1 MovingObjectPosition (net.minecraft.util.MovingObjectPosition)1 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)1