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;
}
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;
}
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;
}
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;
}
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]);
}
}
}
}
Aggregations