Search in sources :

Example 21 with BlockPosition

use of powercrystals.core.position.BlockPosition in project MineFactoryReloaded by powercrystals.

the class TileEntityGenerator method producePower.

protected final int producePower(int mj) {
    BlockPosition ourbp = BlockPosition.fromFactoryTile(this);
    for (BlockPosition bp : ourbp.getAdjacent(true)) {
        TileEntity te = worldObj.getBlockTileEntity(bp.x, bp.y, bp.z);
        if (te == null || !(te instanceof IPowerReceptor)) {
            continue;
        }
        IPowerReceptor ipr = ((IPowerReceptor) te);
        IPowerProvider pp = ipr.getPowerProvider();
        if (pp != null && pp.preConditions(ipr) && pp.getMinEnergyReceived() <= mj) {
            int mjUsed = Math.min(Math.min(pp.getMaxEnergyReceived(), mj), pp.getMaxEnergyStored() - (int) Math.floor(pp.getEnergyStored()));
            pp.receiveEnergy(mjUsed, bp.orientation);
            mj -= mjUsed;
            if (mj <= 0) {
                return 0;
            }
        }
    }
    return mj;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) BlockPosition(powercrystals.core.position.BlockPosition) IPowerReceptor(buildcraft.api.power.IPowerReceptor) IPowerProvider(buildcraft.api.power.IPowerProvider)

Example 22 with BlockPosition

use of powercrystals.core.position.BlockPosition in project MineFactoryReloaded by powercrystals.

the class TileEntityBlockPlacer method activateMachine.

@Override
protected boolean activateMachine() {
    for (int i = 0; i < getSizeInventory(); i++) {
        if (_inventory[i] == null || !(_inventory[i].getItem() instanceof ItemBlock)) {
            continue;
        }
        BlockPosition bp = BlockPosition.fromFactoryTile(this);
        bp.moveForwards(1);
        if (worldObj.isAirBlock(bp.x, bp.y, bp.z)) {
            worldObj.setBlock(bp.x, bp.y, bp.z, _inventory[i].itemID, _inventory[i].getItemDamage(), 3);
            Block block = Block.blocksList[_inventory[i].itemID];
            worldObj.playSoundEffect(bp.x + 0.5, bp.y + 0.5, bp.z + 0.5, block.stepSound.getPlaceSound(), (block.stepSound.getVolume() + 1.0F) / 2.0F, block.stepSound.getPitch() * 0.8F);
            decrStackSize(i, 1);
            return true;
        }
    }
    setIdleTicks(getIdleTicksMax());
    return false;
}
Also used : BlockPosition(powercrystals.core.position.BlockPosition) Block(net.minecraft.block.Block) ItemBlock(net.minecraft.item.ItemBlock) ItemBlock(net.minecraft.item.ItemBlock)

Example 23 with BlockPosition

use of powercrystals.core.position.BlockPosition in project MineFactoryReloaded by powercrystals.

the class TileEntityFruitPicker method activateMachine.

@Override
protected boolean activateMachine() {
    int harvestedBlockId = 0;
    int harvestedBlockMetadata = 0;
    BlockPosition targetCoords = getNextTree();
    if (targetCoords == null) {
        setIdleTicks(getIdleTicksMax());
        return false;
    }
    harvestedBlockId = worldObj.getBlockId(targetCoords.x, targetCoords.y, targetCoords.z);
    harvestedBlockMetadata = worldObj.getBlockMetadata(targetCoords.x, targetCoords.y, targetCoords.z);
    IFactoryFruit harvestable = MFRRegistry.getFruits().get(new Integer(harvestedBlockId));
    List<ItemStack> drops = harvestable.getDrops(worldObj, _rand, targetCoords.x, targetCoords.y, targetCoords.z);
    ItemStack replacement = harvestable.getReplacementBlock(worldObj, targetCoords.x, targetCoords.y, targetCoords.z);
    harvestable.prePick(worldObj, targetCoords.x, targetCoords.y, targetCoords.z);
    doDrop(drops);
    if (replacement == null) {
        if (MFRConfig.playSounds.getBoolean(true)) {
            worldObj.playAuxSFXAtEntity(null, 2001, targetCoords.x, targetCoords.y, targetCoords.z, harvestedBlockId + (harvestedBlockMetadata << 12));
        }
        worldObj.setBlockToAir(targetCoords.x, targetCoords.y, targetCoords.z);
    } else {
        worldObj.setBlock(targetCoords.x, targetCoords.y, targetCoords.z, replacement.itemID, replacement.getItemDamage(), 3);
    }
    harvestable.postPick(worldObj, targetCoords.x, targetCoords.y, targetCoords.z);
    return true;
}
Also used : BlockPosition(powercrystals.core.position.BlockPosition) IFactoryFruit(powercrystals.minefactoryreloaded.api.IFactoryFruit) ItemStack(net.minecraft.item.ItemStack)

Example 24 with BlockPosition

use of powercrystals.core.position.BlockPosition in project MineFactoryReloaded by powercrystals.

the class TileEntityFruitPicker method getNextTree.

private BlockPosition getNextTree() {
    BlockPosition bp = _areaManager.getNextBlock();
    int searchId = worldObj.getBlockId(bp.x, bp.y, bp.z);
    if (!MFRRegistry.getFruitLogBlockIds().contains(searchId)) {
        _lastTree = null;
        return null;
    }
    BlockPosition temp = getNextTreeSegment(bp.x, bp.y, bp.z, false);
    if (temp != null) {
        _areaManager.rewindBlock();
    }
    return temp;
}
Also used : BlockPosition(powercrystals.core.position.BlockPosition)

Example 25 with BlockPosition

use of powercrystals.core.position.BlockPosition in project MineFactoryReloaded by powercrystals.

the class TileEntityHarvester method getNextTreeSegment.

private BlockPosition getNextTreeSegment(int x, int y, int z, boolean treeFlipped) {
    int blockId;
    if (_lastTree == null || _lastTree.x != x || _lastTree.y != y || _lastTree.z != z) {
        int yTreeAreaLowerBound = (treeFlipped ? y - MFRConfig.treeSearchMaxVertical.getInt() : y);
        int yTreeAreaUpperBound = (treeFlipped ? y : y + MFRConfig.treeSearchMaxVertical.getInt());
        Area a = new Area(x - MFRConfig.treeSearchMaxHorizontal.getInt(), x + MFRConfig.treeSearchMaxHorizontal.getInt(), yTreeAreaLowerBound, yTreeAreaUpperBound, z - MFRConfig.treeSearchMaxHorizontal.getInt(), z + MFRConfig.treeSearchMaxHorizontal.getInt());
        _treeManager = new TreeHarvestManager(a, treeFlipped ? TreeHarvestMode.HarvestInverted : TreeHarvestMode.Harvest);
        _lastTree = new BlockPosition(x, y, z);
    } else if (_treeManager.getIsDone()) {
        _treeManager.reset();
    }
    while (true) {
        if (_treeManager.getIsDone()) {
            return null;
        }
        BlockPosition bp = _treeManager.getNextBlock();
        blockId = worldObj.getBlockId(bp.x, bp.y, bp.z);
        if (MFRRegistry.getHarvestables().containsKey(new Integer(blockId)) && MFRRegistry.getHarvestables().get(new Integer(blockId)).canBeHarvested(worldObj, _settings, bp.x, bp.y, bp.z)) {
            if (_treeManager.getIsLeafPass() && MFRRegistry.getHarvestables().get(new Integer(blockId)).getHarvestType() == HarvestType.TreeLeaf) {
                return bp;
            } else if (!_treeManager.getIsLeafPass() && (MFRRegistry.getHarvestables().get(new Integer(blockId)).getHarvestType() == HarvestType.Tree || MFRRegistry.getHarvestables().get(new Integer(blockId)).getHarvestType() == HarvestType.TreeFlipped)) {
                return bp;
            } else if (!_treeManager.getIsLeafPass() && MFRRegistry.getHarvestables().get(new Integer(blockId)).getHarvestType() == HarvestType.TreeLeaf) {
                _treeManager.reset();
                continue;
            }
        }
        _treeManager.moveNext();
    }
}
Also used : Area(powercrystals.core.position.Area) BlockPosition(powercrystals.core.position.BlockPosition) TreeHarvestManager(powercrystals.minefactoryreloaded.core.TreeHarvestManager)

Aggregations

BlockPosition (powercrystals.core.position.BlockPosition)37 ItemStack (net.minecraft.item.ItemStack)8 TileEntity (net.minecraft.tileentity.TileEntity)8 Area (powercrystals.core.position.Area)6 Block (net.minecraft.block.Block)4 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)3 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 ForgeDirection (net.minecraftforge.common.ForgeDirection)2 IFactoryHarvestable (powercrystals.minefactoryreloaded.api.IFactoryHarvestable)2 IConnectableRedNet (powercrystals.minefactoryreloaded.api.rednet.IConnectableRedNet)2 TreeHarvestManager (powercrystals.minefactoryreloaded.core.TreeHarvestManager)2 IconOverlay (powercrystals.minefactoryreloaded.render.IconOverlay)2 TileEntityRedNetCable (powercrystals.minefactoryreloaded.tile.rednet.TileEntityRedNetCable)2 IPowerProvider (buildcraft.api.power.IPowerProvider)1 IPowerReceptor (buildcraft.api.power.IPowerReceptor)1 ArrayList (java.util.ArrayList)1 Entity (net.minecraft.entity.Entity)1 EntityAgeable (net.minecraft.entity.EntityAgeable)1 EntityLiving (net.minecraft.entity.EntityLiving)1 EntityMinecartContainer (net.minecraft.entity.item.EntityMinecartContainer)1