Search in sources :

Example 1 with TileEntityPressureTube

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

the class BlockPressureTube method canConnectRedstone.

/**
     * Determine if this block can make a redstone connection on the side provided,
     * Useful to control which sides are inputs and outputs for redstone wires.
     *
     * Side:
     *  -1: UP
     *   0: NORTH
     *   1: EAST
     *   2: SOUTH
     *   3: WEST
     *
     * @param world The current world
     * @param x X Position
     * @param y Y Position
     * @param z Z Position
     * @param side The side that is trying to make the connection
     * @return True to make the connection
     */
@Override
public boolean canConnectRedstone(IBlockAccess world, int x, int y, int z, int side) {
    if (side < 0 || side > 3)
        return false;
    TileEntityPressureTube tube = (TileEntityPressureTube) world.getTileEntity(x, y, z);
    ForgeDirection d = ForgeDirection.NORTH;
    for (int i = 0; i < side; i++) {
        d = d.getRotation(ForgeDirection.UP);
    }
    side = d.ordinal();
    for (int i = 0; i < 6; i++) {
        if (tube.modules[i] != null) {
            if ((side ^ 1) == i || i != side && tube.modules[i].isInline()) {
                //if we are on the same side, or when we have an 'in line' module that is not on the opposite side.
                if (tube.modules[i] instanceof TubeModuleRedstoneEmitting)
                    return true;
            }
        }
    }
    return false;
}
Also used : ForgeDirection(net.minecraftforge.common.util.ForgeDirection) TileEntityPressureTube(pneumaticCraft.common.tileentity.TileEntityPressureTube) TubeModuleRedstoneEmitting(pneumaticCraft.common.block.tubes.TubeModuleRedstoneEmitting)

Example 2 with TileEntityPressureTube

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

the class BlockPressureTube method randomDisplayTick.

@Override
@SideOnly(Side.CLIENT)
public /**
     * A randomly called display update to be able to add particles or other items for display
     */
void randomDisplayTick(World par1World, int par2, int par3, int par4, Random par5Random) {
    TileEntity te = par1World.getTileEntity(par2, par3, par4);
    if (te instanceof TileEntityPressureTube) {
        TileEntityPressureTube tePt = (TileEntityPressureTube) te;
        int l = 0;
        for (TubeModule module : tePt.modules) if (module != null)
            l = Math.max(l, module.getRedstoneLevel());
        if (l > 0) {
            // for(int i = 0; i < 4; i++){
            double d0 = par2 + 0.5D + (par5Random.nextFloat() - 0.5D) * 0.5D;
            double d1 = par3 + 0.5D + (par5Random.nextFloat() - 0.5D) * 0.5D;
            double d2 = par4 + 0.5D + (par5Random.nextFloat() - 0.5D) * 0.5D;
            float f = l / 15.0F;
            float f1 = f * 0.6F + 0.4F;
            float f2 = f * f * 0.7F - 0.5F;
            float f3 = f * f * 0.6F - 0.7F;
            if (f2 < 0.0F) {
                f2 = 0.0F;
            }
            if (f3 < 0.0F) {
                f3 = 0.0F;
            }
            // PacketDispatcher.sendPacketToAllPlayers(PacketHandlerPneumaticCraft.spawnParticle("reddust",
            // d0, d1, d2, (double)f1, (double)f2, (double)f3));
            par1World.spawnParticle("reddust", d0, d1, d2, f1, f2, f3);
        // }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TubeModule(pneumaticCraft.common.block.tubes.TubeModule) ItemTubeModule(pneumaticCraft.common.item.ItemTubeModule) TileEntityPressureTube(pneumaticCraft.common.tileentity.TileEntityPressureTube) SideOnly(cpw.mods.fml.relauncher.SideOnly)

Example 3 with TileEntityPressureTube

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

the class BlockPressureTube method onBlockAdded.

@Override
public void onBlockAdded(World world, int x, int y, int z) {
    super.onBlockAdded(world, x, y, z);
    TileEntity te = world.getTileEntity(x, y, z);
    if (te != null && te instanceof TileEntityPressureTube) {
        TileEntityPressureTube tePt = (TileEntityPressureTube) te;
        tePt.updateConnections(world, x, y, z);
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityPressureTube(pneumaticCraft.common.tileentity.TileEntityPressureTube)

Example 4 with TileEntityPressureTube

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

the class BlockPressureTube method rotateBlock.

@Override
public boolean rotateBlock(World world, EntityPlayer player, int x, int y, int z, ForgeDirection side) {
    TileEntityPressureTube tube = ModInteractionUtils.getInstance().getTube(world.getTileEntity(x, y, z));
    if (player.isSneaking()) {
        TubeModule module = getLookedModule(world, x, y, z, player);
        if (module != null) {
            if (!player.capabilities.isCreativeMode) {
                List<ItemStack> drops = module.getDrops();
                for (ItemStack drop : drops) {
                    EntityItem entity = new EntityItem(world, x + 0.5, y + 0.5, z + 0.5);
                    entity.setEntityItemStack(drop);
                    world.spawnEntityInWorld(entity);
                    entity.onCollideWithPlayer(player);
                }
            }
            tube.setModule(null, module.getDirection());
            onNeighborBlockChange(world, x, y, z, this);
            world.notifyBlocksOfNeighborChange(x, y, z, this, module.getDirection().getOpposite().ordinal());
            return true;
        }
        if (!player.capabilities.isCreativeMode) {
            EntityItem entity = new EntityItem(world, x + 0.5, y + 0.5, z + 0.5, new ItemStack(tube.maxPressure <= PneumaticValues.MAX_PRESSURE_PRESSURE_TUBE ? Blockss.pressureTube : Blockss.advancedPressureTube));
            world.spawnEntityInWorld(entity);
            entity.onCollideWithPlayer(player);
        }
        ModInteractionUtils.getInstance().removeTube(world.getTileEntity(x, y, z));
        return true;
    } else {
        return super.rotateBlock(world, player, x, y, z, side);
    }
}
Also used : TubeModule(pneumaticCraft.common.block.tubes.TubeModule) ItemTubeModule(pneumaticCraft.common.item.ItemTubeModule) TileEntityPressureTube(pneumaticCraft.common.tileentity.TileEntityPressureTube) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem)

Example 5 with TileEntityPressureTube

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

the class BlockPressureTube method isProvidingWeakPower.

/**
     * Returns true if the block is emitting indirect/weak redstone power on the
     * specified side. If isBlockNormalCube returns true, standard redstone
     * propagation rules will apply instead and this will not be called. Args:
     * World, X, Y, Z, side. Note that the side is reversed - eg it is 1 (up)
     * when checking the bottom of the block.
     */
@Override
public int isProvidingWeakPower(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int side) {
    TileEntity te = par1IBlockAccess.getTileEntity(par2, par3, par4);
    if (te instanceof TileEntityPressureTube) {
        TileEntityPressureTube tePt = (TileEntityPressureTube) te;
        int redstoneLevel = 0;
        for (int i = 0; i < 6; i++) {
            if (tePt.modules[i] != null) {
                if ((side ^ 1) == i || i != side && tePt.modules[i].isInline()) {
                    //if we are on the same side, or when we have an 'in line' module that is not on the opposite side.
                    redstoneLevel = Math.max(redstoneLevel, tePt.modules[i].getRedstoneLevel());
                }
            }
        }
        return redstoneLevel;
    }
    return 0;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityPressureTube(pneumaticCraft.common.tileentity.TileEntityPressureTube)

Aggregations

TileEntityPressureTube (pneumaticCraft.common.tileentity.TileEntityPressureTube)12 TubeModule (pneumaticCraft.common.block.tubes.TubeModule)5 TileEntity (net.minecraft.tileentity.TileEntity)4 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)4 ItemTubeModule (pneumaticCraft.common.item.ItemTubeModule)4 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 MovingObjectPosition (net.minecraft.util.MovingObjectPosition)2 SideOnly (cpw.mods.fml.relauncher.SideOnly)1 HashSet (java.util.HashSet)1 Stack (java.util.Stack)1 Block (net.minecraft.block.Block)1 EntityItem (net.minecraft.entity.item.EntityItem)1 ItemStack (net.minecraft.item.ItemStack)1 AxisAlignedBB (net.minecraft.util.AxisAlignedBB)1 Vec3 (net.minecraft.util.Vec3)1 TubeModuleRedstoneEmitting (pneumaticCraft.common.block.tubes.TubeModuleRedstoneEmitting)1 TileEntityPneumaticBase (pneumaticCraft.common.tileentity.TileEntityPneumaticBase)1 TileEntityCache (pneumaticCraft.common.util.TileEntityCache)1