Search in sources :

Example 1 with LeverTileEntity

use of omtteam.openmodularturrets.tileentity.LeverTileEntity in project OpenModularTurrets by OpenModularTurretsTeam.

the class LeverBlock method clOnBlockActivated.

@Override
protected boolean clOnBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
    if (TurretHeadUtil.getTurretBaseFacing(worldIn, pos) == EnumFacing.DOWN || TurretHeadUtil.getTurretBaseFacing(worldIn, pos) == EnumFacing.UP) {
        return true;
    }
    TurretBase base = getTurretBase(worldIn, pos);
    LeverTileEntity lever = (LeverTileEntity) worldIn.getTileEntity(pos);
    OMEnergyStorage storage = (OMEnergyStorage) base.getCapability(CapabilityEnergy.ENERGY, EnumFacing.DOWN);
    if (storage == null) {
        return true;
    }
    if (lever != null && (worldIn.getBlockState(pos).getValue(ROTATION) * 90) == 0 && isBaseValid(worldIn.getTileEntity(new BlockPos(pos.getX(), pos.getY(), pos.getZ() + 1)))) {
        base = (TurretBase) worldIn.getTileEntity(new BlockPos(pos.getX(), pos.getY(), pos.getZ() + 1));
        if (base != null) {
            lever.isTurning = true;
            if (lever.rotation == 0F) {
                //worldIn.playSound(pos.getX(), pos.getY(), pos.getZ(), "omtteam.openmodularturrets:windup", 1.0F, 1.0F);
                storage.receiveEnergy(50, false);
            }
        }
    }
    if (lever != null && (worldIn.getBlockState(pos).getValue(ROTATION) * 90) == 90 && isBaseValid(worldIn.getTileEntity(new BlockPos(pos.getX() - 1, pos.getY(), pos.getZ())))) {
        base = (TurretBase) worldIn.getTileEntity(new BlockPos(pos.getX() - 1, pos.getY(), pos.getZ()));
        if (base != null) {
            lever.isTurning = true;
            if (lever.rotation == 0F) {
                //worldIn.playSoundEffect(pos.getX(), pos.getY(), pos.getZ(), "omtteam.openmodularturrets:windup", 1.0F, 1.0F);
                storage.receiveEnergy(50, false);
            }
        }
    }
    if (lever != null && (worldIn.getBlockState(pos).getValue(ROTATION) * 90) == 180 && isBaseValid(worldIn.getTileEntity(new BlockPos(pos.getX(), pos.getY(), pos.getZ() - 1)))) {
        base = (TurretBase) worldIn.getTileEntity(new BlockPos(pos.getX(), pos.getY(), pos.getZ() - 1));
        if (base != null) {
            lever.isTurning = true;
            if (lever.rotation == 0F) {
                //worldIn.playSoundEffect(pos.getX(), pos.getY(), pos.getZ(), "omtteam.openmodularturrets:windup", 1.0F, 1.0F);
                storage.receiveEnergy(50, false);
            }
        }
    }
    if (lever != null && (worldIn.getBlockState(pos).getValue(ROTATION) * 90) == 270 && isBaseValid(worldIn.getTileEntity(new BlockPos(pos.getX() + 1, pos.getY(), pos.getZ())))) {
        base = (TurretBase) worldIn.getTileEntity(new BlockPos(pos.getX() + 1, pos.getY(), pos.getZ()));
        if (base != null) {
            lever.isTurning = true;
            if (lever.rotation == 0F) {
                //worldIn.playSoundEffect(pos.getX(), pos.getY(), pos.getZ(), "omtteam.openmodularturrets:windup", 1.0F, 1.0F);
                storage.receiveEnergy(50, false);
            }
        }
    }
    return true;
}
Also used : LeverTileEntity(omtteam.openmodularturrets.tileentity.LeverTileEntity) TurretBase(omtteam.openmodularturrets.tileentity.TurretBase) TurretHeadUtil.getTurretBase(omtteam.openmodularturrets.util.TurretHeadUtil.getTurretBase) OMEnergyStorage(omtteam.omlib.power.OMEnergyStorage) BlockPos(net.minecraft.util.math.BlockPos)

Example 2 with LeverTileEntity

use of omtteam.openmodularturrets.tileentity.LeverTileEntity in project OpenModularTurrets by OpenModularTurretsTeam.

the class LeverRenderer method renderTileEntityAt.

@SuppressWarnings("ConstantConditions")
@Override
public void renderTileEntityAt(TileEntity te, double x, double y, double z, float scale, int destroyStage) {
    LeverTileEntity lever = (LeverTileEntity) te;
    int rotation;
    ResourceLocation textures = (new ResourceLocation(Reference.MOD_ID + ":textures/blocks/lever_block.png"));
    Minecraft.getMinecraft().renderEngine.bindTexture(textures);
    GL11.glPushMatrix();
    GL11.glTranslatef((float) x + 0.5F, (float) y + 1.5F, (float) z + 0.5F);
    if (te == null) {
        GL11.glScalef(0.7F, -0.7F, -0.7F);
        GL11.glTranslatef((float) x + 0.0F, (float) y + 0.4F, (float) z + 0.5F);
        GL11.glRotatef(45.0F, 2.5F, -4.5F, -1.0F);
        model.renderAll();
        GL11.glPopMatrix();
        return;
    }
    if (te.getWorld() != null) {
        rotation = te.getBlockMetadata();
        GL11.glRotatef(rotation * -90F, 0.0F, 1.0F, 0.0F);
        GL11.glScalef(1.0F, -1F, -1F);
        model.Shape1.rotateAngleZ = (lever.rotation / 55);
        model.Shape2.rotateAngleZ = (lever.rotation / 55);
        model.renderAll();
    }
    GL11.glPopMatrix();
}
Also used : LeverTileEntity(omtteam.openmodularturrets.tileentity.LeverTileEntity) ResourceLocation(net.minecraft.util.ResourceLocation)

Aggregations

LeverTileEntity (omtteam.openmodularturrets.tileentity.LeverTileEntity)2 ResourceLocation (net.minecraft.util.ResourceLocation)1 BlockPos (net.minecraft.util.math.BlockPos)1 OMEnergyStorage (omtteam.omlib.power.OMEnergyStorage)1 TurretBase (omtteam.openmodularturrets.tileentity.TurretBase)1 TurretHeadUtil.getTurretBase (omtteam.openmodularturrets.util.TurretHeadUtil.getTurretBase)1