Search in sources :

Example 26 with BlockPosition

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

the class TileEntityHarvester method getNextHarvest.

private BlockPosition getNextHarvest() {
    BlockPosition bp = _areaManager.getNextBlock();
    int searchId = worldObj.getBlockId(bp.x, bp.y, bp.z);
    if (!MFRRegistry.getHarvestables().containsKey(new Integer(searchId))) {
        _lastTree = null;
        return null;
    }
    IFactoryHarvestable harvestable = MFRRegistry.getHarvestables().get(new Integer(searchId));
    if (harvestable.canBeHarvested(worldObj, _settings, bp.x, bp.y, bp.z)) {
        if (harvestable.getHarvestType() == HarvestType.Normal) {
            _lastTree = null;
            return bp;
        } else if (harvestable.getHarvestType() == HarvestType.Column) {
            _lastTree = null;
            return getNextVertical(bp.x, bp.y, bp.z, 0);
        } else if (harvestable.getHarvestType() == HarvestType.LeaveBottom) {
            _lastTree = null;
            return getNextVertical(bp.x, bp.y, bp.z, 1);
        } else if (harvestable.getHarvestType() == HarvestType.Tree) {
            BlockPosition temp = getNextTreeSegment(bp.x, bp.y, bp.z, false);
            if (temp != null) {
                _areaManager.rewindBlock();
            }
            return temp;
        } else if (harvestable.getHarvestType() == HarvestType.TreeFlipped) {
            BlockPosition temp = getNextTreeSegment(bp.x, bp.y, bp.z, true);
            if (temp != null) {
                _areaManager.rewindBlock();
            }
            return temp;
        }
    }
    _lastTree = null;
    return null;
}
Also used : IFactoryHarvestable(powercrystals.minefactoryreloaded.api.IFactoryHarvestable) BlockPosition(powercrystals.core.position.BlockPosition)

Example 27 with BlockPosition

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

the class TileEntityHarvester method activateMachine.

@Override
public boolean activateMachine() {
    BlockPosition targetCoords = getNextHarvest();
    if (targetCoords == null) {
        setIdleTicks(getIdleTicksMax());
        return false;
    }
    int harvestedBlockId = worldObj.getBlockId(targetCoords.x, targetCoords.y, targetCoords.z);
    int harvestedBlockMetadata = worldObj.getBlockMetadata(targetCoords.x, targetCoords.y, targetCoords.z);
    IFactoryHarvestable harvestable = MFRRegistry.getHarvestables().get(new Integer(harvestedBlockId));
    List<ItemStack> drops = harvestable.getDrops(worldObj, _rand, ImmutableMap.copyOf(_settings), targetCoords.x, targetCoords.y, targetCoords.z);
    harvestable.preHarvest(worldObj, targetCoords.x, targetCoords.y, targetCoords.z);
    doDrop(drops);
    if (harvestable.breakBlock()) {
        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);
    }
    harvestable.postHarvest(worldObj, targetCoords.x, targetCoords.y, targetCoords.z);
    _tank.fill(LiquidDictionary.getLiquid("sludge", 10), true);
    return true;
}
Also used : IFactoryHarvestable(powercrystals.minefactoryreloaded.api.IFactoryHarvestable) BlockPosition(powercrystals.core.position.BlockPosition) ItemStack(net.minecraft.item.ItemStack)

Example 28 with BlockPosition

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

the class TileEntityLaserDrillPrecharger method getDrill.

private TileEntityLaserDrill getDrill() {
    BlockPosition bp = new BlockPosition(this);
    bp.orientation = getDirectionFacing();
    bp.moveForwards(1);
    if (!worldObj.isAirBlock(bp.x, bp.y, bp.z)) {
        return null;
    }
    bp.moveForwards(1);
    TileEntity te = worldObj.getBlockTileEntity(bp.x, bp.y, bp.z);
    if (te instanceof TileEntityLaserDrill) {
        return ((TileEntityLaserDrill) te);
    }
    return null;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) BlockPosition(powercrystals.core.position.BlockPosition)

Example 29 with BlockPosition

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

the class TileEntityPlanter method activateMachine.

@Override
public boolean activateMachine() {
    BlockPosition bp = _areaManager.getNextBlock();
    ItemStack match = _inventory[getPlanterSlotIdFromBp(bp)];
    for (int stackIndex = 10; stackIndex <= 25; stackIndex++) {
        ItemStack availableStack = getStackInSlot(stackIndex);
        //skip planting attempt if there's no stack in that slot, or if there's a template item that's not matched
        if (availableStack == null || (match != null && !stacksEqual(match, availableStack))) {
            continue;
        }
        if (!MFRRegistry.getPlantables().containsKey(new Integer(availableStack.itemID))) {
            continue;
        }
        IFactoryPlantable plantable = MFRRegistry.getPlantables().get(new Integer(availableStack.itemID));
        if (!plantable.canBePlantedHere(worldObj, bp.x, bp.y, bp.z, availableStack)) {
            continue;
        }
        plantable.prePlant(worldObj, bp.x, bp.y, bp.z, availableStack);
        worldObj.setBlock(bp.x, bp.y, bp.z, plantable.getPlantedBlockId(worldObj, bp.x, bp.y, bp.z, availableStack), plantable.getPlantedBlockMetadata(worldObj, bp.x, bp.y, bp.z, availableStack), 3);
        plantable.postPlant(worldObj, bp.x, bp.y, bp.z, availableStack);
        decrStackSize(stackIndex, 1);
        return true;
    }
    setIdleTicks(getIdleTicksMax());
    return false;
}
Also used : IFactoryPlantable(powercrystals.minefactoryreloaded.api.IFactoryPlantable) BlockPosition(powercrystals.core.position.BlockPosition) ItemStack(net.minecraft.item.ItemStack)

Example 30 with BlockPosition

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

the class TileEntityRedNetLogic method updateEntity.

@Override
public void updateEntity() {
    if (worldObj.isRemote) {
        return;
    }
    int[][] lastOuput = new int[6][];
    for (int i = 0; i < 6; i++) {
        lastOuput[i] = _buffers[i + 6];
        _buffers[i + 6] = new int[16];
    }
    for (int circuitNum = 0; circuitNum < _circuits.length; circuitNum++) {
        if (_circuits[circuitNum] instanceof Noop) {
            continue;
        }
        int[] input = new int[_circuits[circuitNum].getInputCount()];
        for (int pinNum = 0; pinNum < input.length; pinNum++) {
            input[pinNum] = _buffers[_pinMappingInputs[circuitNum][pinNum].buffer][_pinMappingInputs[circuitNum][pinNum].pin];
        }
        int[] output = _circuits[circuitNum].recalculateOutputValues(worldObj.getTotalWorldTime(), input);
        for (int pinNum = 0; pinNum < output.length; pinNum++) {
            _buffers[_pinMappingOutputs[circuitNum][pinNum].buffer][_pinMappingOutputs[circuitNum][pinNum].pin] = output[pinNum];
        }
    }
    for (int i = 0; i < 6; i++) {
        if (!Arrays.areEqual(lastOuput[i], _buffers[i + 6])) {
            BlockPosition bp = new BlockPosition(this);
            bp.orientation = ForgeDirection.VALID_DIRECTIONS[i];
            bp.moveForwards(1);
            Block b = Block.blocksList[worldObj.getBlockId(bp.x, bp.y, bp.z)];
            if (b instanceof IRedNetNetworkContainer) {
                ((IRedNetNetworkContainer) b).updateNetwork(worldObj, bp.x, bp.y, bp.z);
            } else if (b instanceof IConnectableRedNet) {
                ((IConnectableRedNet) b).onInputsChanged(worldObj, bp.x, bp.y, bp.z, bp.orientation.getOpposite(), _buffers[i + 6]);
            }
        }
    }
}
Also used : IRedNetNetworkContainer(powercrystals.minefactoryreloaded.api.rednet.IRedNetNetworkContainer) Noop(powercrystals.minefactoryreloaded.circuits.Noop) BlockPosition(powercrystals.core.position.BlockPosition) Block(net.minecraft.block.Block) IConnectableRedNet(powercrystals.minefactoryreloaded.api.rednet.IConnectableRedNet)

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