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