Search in sources :

Example 6 with TileEntityPressureTube

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

the class BlockPressureTube method tryPlaceModule.

public boolean tryPlaceModule(EntityPlayer player, World world, int x, int y, int z, int par6, boolean simulate) {
    if (player.getCurrentEquippedItem() != null) {
        if (player.getCurrentEquippedItem().getItem() instanceof ItemTubeModule) {
            TileEntityPressureTube pressureTube = ModInteractionUtils.getInstance().getTube(world.getTileEntity(x, y, z));
            if (pressureTube.modules[par6] == null && ModInteractionUtils.getInstance().occlusionTest(boundingBoxes[par6], world.getTileEntity(x, y, z))) {
                TubeModule module = ModuleRegistrator.getModule(((ItemTubeModule) player.getCurrentEquippedItem().getItem()).moduleName);
                if (simulate)
                    module.markFake();
                pressureTube.setModule(module, ForgeDirection.getOrientation(par6));
                if (!simulate) {
                    onNeighborBlockChange(world, x, y, z, this);
                    world.notifyBlocksOfNeighborChange(x, y, z, this, ForgeDirection.getOrientation(par6).getOpposite().ordinal());
                    if (!player.capabilities.isCreativeMode)
                        player.getCurrentEquippedItem().stackSize--;
                    world.playSoundEffect(x + 0.5, y + 0.5, z + 0.5, Block.soundTypeGlass.getStepResourcePath(), Block.soundTypeGlass.getVolume() * 5.0F, Block.soundTypeGlass.getPitch() * .9F);
                }
                return true;
            }
        } else if (player.getCurrentEquippedItem().getItem() == Itemss.advancedPCB && !simulate) {
            TubeModule module = BlockPressureTube.getLookedModule(world, x, y, z, player);
            if (module != null && !module.isUpgraded() && module.canUpgrade()) {
                if (!world.isRemote) {
                    module.upgrade();
                    if (!player.capabilities.isCreativeMode)
                        player.getCurrentEquippedItem().stackSize--;
                }
                return true;
            }
        }
    }
    return false;
}
Also used : TubeModule(pneumaticCraft.common.block.tubes.TubeModule) ItemTubeModule(pneumaticCraft.common.item.ItemTubeModule) TileEntityPressureTube(pneumaticCraft.common.tileentity.TileEntityPressureTube) ItemTubeModule(pneumaticCraft.common.item.ItemTubeModule)

Example 7 with TileEntityPressureTube

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

the class BlockPressureTube method collisionRayTrace.

@Override
public MovingObjectPosition collisionRayTrace(World world, int x, int y, int z, Vec3 origin, Vec3 direction) {
    MovingObjectPosition bestMOP = null;
    AxisAlignedBB bestAABB = null;
    setBlockBounds(BBConstants.PRESSURE_PIPE_MIN_POS, BBConstants.PRESSURE_PIPE_MIN_POS, BBConstants.PRESSURE_PIPE_MIN_POS, BBConstants.PRESSURE_PIPE_MAX_POS, BBConstants.PRESSURE_PIPE_MAX_POS, BBConstants.PRESSURE_PIPE_MAX_POS);
    MovingObjectPosition mop = super.collisionRayTrace(world, x, y, z, origin, direction);
    if (isCloserMOP(origin, bestMOP, mop)) {
        bestMOP = mop;
        bestAABB = AxisAlignedBB.getBoundingBox(minX, minY, minZ, maxX, maxY, maxZ);
    }
    TileEntityPressureTube tube = ModInteractionUtils.getInstance().getTube(world.getTileEntity(x, y, z));
    for (int i = 0; i < 6; i++) {
        if (tube.sidesConnected[i]) {
            setBlockBounds(boundingBoxes[i]);
            mop = super.collisionRayTrace(world, x, y, z, origin, direction);
            if (isCloserMOP(origin, bestMOP, mop)) {
                bestMOP = mop;
                bestAABB = AxisAlignedBB.getBoundingBox(minX, minY, minZ, maxX, maxY, maxZ);
            }
        }
    }
    //unknown indicates we hit the tube.
    if (bestMOP != null)
        bestMOP.hitInfo = ForgeDirection.UNKNOWN;
    TubeModule[] modules = tube.modules;
    for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
        if (modules[dir.ordinal()] != null) {
            setBlockBounds(modules[dir.ordinal()].boundingBoxes[dir.ordinal()]);
            mop = super.collisionRayTrace(world, x, y, z, origin, direction);
            if (isCloserMOP(origin, bestMOP, mop)) {
                mop.hitInfo = dir;
                bestMOP = mop;
                bestAABB = AxisAlignedBB.getBoundingBox(minX, minY, minZ, maxX, maxY, maxZ);
            }
        }
    }
    if (bestAABB != null)
        setBlockBounds(bestAABB);
    return bestMOP;
}
Also used : AxisAlignedBB(net.minecraft.util.AxisAlignedBB) MovingObjectPosition(net.minecraft.util.MovingObjectPosition) TubeModule(pneumaticCraft.common.block.tubes.TubeModule) ItemTubeModule(pneumaticCraft.common.item.ItemTubeModule) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) TileEntityPressureTube(pneumaticCraft.common.tileentity.TileEntityPressureTube)

Example 8 with TileEntityPressureTube

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

the class BlockPressureTube method addCollisionBoxesToList.

@Override
public void addCollisionBoxesToList(World world, int x, int y, int z, AxisAlignedBB axisalignedbb, List arraylist, Entity par7Entity) {
    setBlockBounds(BBConstants.PRESSURE_PIPE_MIN_POS, BBConstants.PRESSURE_PIPE_MIN_POS, BBConstants.PRESSURE_PIPE_MIN_POS, BBConstants.PRESSURE_PIPE_MAX_POS, BBConstants.PRESSURE_PIPE_MAX_POS, BBConstants.PRESSURE_PIPE_MAX_POS);
    super.addCollisionBoxesToList(world, x, y, z, axisalignedbb, arraylist, par7Entity);
    TileEntity te = world.getTileEntity(x, y, z);
    TileEntityPressureTube tePt = (TileEntityPressureTube) te;
    for (int i = 0; i < 6; i++) {
        if (tePt.sidesConnected[i]) {
            setBlockBounds(boundingBoxes[i]);
            super.addCollisionBoxesToList(world, x, y, z, axisalignedbb, arraylist, par7Entity);
        } else if (tePt.modules[i] != null) {
            setBlockBounds(tePt.modules[i].boundingBoxes[i]);
            super.addCollisionBoxesToList(world, x, y, z, axisalignedbb, arraylist, par7Entity);
        }
    }
    setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityPressureTube(pneumaticCraft.common.tileentity.TileEntityPressureTube)

Example 9 with TileEntityPressureTube

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

the class BlockPressureTube method getLookedModule.

public static TubeModule getLookedModule(World world, int x, int y, int z, EntityPlayer player) {
    Pair<Vec3, Vec3> vecs = PneumaticCraftUtils.getStartAndEndLookVec(player);
    MovingObjectPosition mop = Blockss.pressureTube.collisionRayTrace(world, x, y, z, vecs.getLeft(), vecs.getRight());
    if (mop != null && mop.hitInfo instanceof ForgeDirection && (ForgeDirection) mop.hitInfo != ForgeDirection.UNKNOWN) {
        TileEntityPressureTube tube = ModInteractionUtils.getInstance().getTube(world.getTileEntity(x, y, z));
        return tube.modules[((ForgeDirection) mop.hitInfo).ordinal()];
    }
    return null;
}
Also used : MovingObjectPosition(net.minecraft.util.MovingObjectPosition) Vec3(net.minecraft.util.Vec3) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) TileEntityPressureTube(pneumaticCraft.common.tileentity.TileEntityPressureTube)

Example 10 with TileEntityPressureTube

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

the class ModuleNetworkManager method getConnectedModules.

public Set<TubeModule> getConnectedModules(TubeModule module) {
    Set<TubeModule> modules = new HashSet<TubeModule>();
    Set<TileEntityPressureTube> traversedTubes = new HashSet<TileEntityPressureTube>();
    Stack<TileEntityPressureTube> pendingTubes = new Stack<TileEntityPressureTube>();
    pendingTubes.push((TileEntityPressureTube) module.getTube());
    while (!pendingTubes.isEmpty()) {
        TileEntityPressureTube tube = pendingTubes.pop();
        for (TubeModule m : tube.modules) {
            if (m != null)
                modules.add(m);
        }
        TileEntityCache[] cache = ((TileEntityPneumaticBase) ((IPneumaticMachine) tube).getAirHandler()).getTileCache();
        for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
            if (tube.sidesConnected[d.ordinal()]) {
                TileEntityPressureTube newTube = ModInteractionUtils.getInstance().getTube(cache[d.ordinal()].getTileEntity());
                if (newTube != null && !traversedTubes.contains(newTube)) {
                    pendingTubes.add(newTube);
                    traversedTubes.add(newTube);
                }
            }
        }
    }
    return modules;
}
Also used : ForgeDirection(net.minecraftforge.common.util.ForgeDirection) TileEntityPressureTube(pneumaticCraft.common.tileentity.TileEntityPressureTube) TileEntityCache(pneumaticCraft.common.util.TileEntityCache) HashSet(java.util.HashSet) Stack(java.util.Stack) TileEntityPneumaticBase(pneumaticCraft.common.tileentity.TileEntityPneumaticBase)

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