use of powercrystals.core.position.BlockPosition in project MineFactoryReloaded by powercrystals.
the class RedstoneNetwork method mergeNetwork.
public void mergeNetwork(RedstoneNetwork network) {
if (_invalid) {
return;
}
RedstoneNetwork.log("Network with ID %d merging with network %d", _id, network._id);
network.setInvalid();
for (int subnet = 0; subnet < 16; subnet++) {
_singleNodes.get(subnet).addAll(network._singleNodes.get(subnet));
}
_omniNodes.addAll(network._omniNodes);
_weakNodes.addAll(network._weakNodes);
_mustUpdate = _mustUpdate || network._mustUpdate;
for (BlockPosition cable : network._cables) {
_cables.add(cable);
TileEntity te = cable.getTileEntity(_world);
if (te instanceof TileEntityRedNetCable) {
((TileEntityRedNetCable) te).setNetwork(this);
}
}
updatePowerLevels();
}
use of powercrystals.core.position.BlockPosition in project MineFactoryReloaded by powercrystals.
the class TileEntityFertilizer method activateMachine.
@Override
public boolean activateMachine() {
BlockPosition bp = _areaManager.getNextBlock();
int targetId = worldObj.getBlockId(bp.x, bp.y, bp.z);
if (!MFRRegistry.getFertilizables().containsKey(new Integer(targetId))) {
setIdleTicks(getIdleTicksMax());
return false;
}
for (int stackIndex = 0; stackIndex < getSizeInventory(); stackIndex++) {
ItemStack fertStack = getStackInSlot(stackIndex);
if (fertStack == null || !MFRRegistry.getFertilizers().containsKey(new Integer(fertStack.itemID))) {
continue;
}
IFactoryFertilizer fertilizer = MFRRegistry.getFertilizers().get(new Integer(fertStack.itemID));
IFactoryFertilizable fertilizable = MFRRegistry.getFertilizables().get(new Integer(targetId));
if (fertilizer.getFertilizerMeta() != fertStack.getItemDamage()) {
continue;
}
if (!fertilizable.canFertilizeBlock(worldObj, bp.x, bp.y, bp.z, fertilizer.getFertilizerType())) {
continue;
}
if (fertilizable.fertilize(worldObj, _rand, bp.x, bp.y, bp.z, fertilizer.getFertilizerType())) {
fertilizer.consume(fertStack);
if (fertStack.stackSize <= 0) {
setInventorySlotContents(stackIndex, null);
}
return true;
}
}
setIdleTicks(getIdleTicksMax());
return false;
}
use of powercrystals.core.position.BlockPosition in project MineFactoryReloaded by powercrystals.
the class TileEntityFisher method activateMachine.
@Override
public boolean activateMachine() {
if (_isJammed || worldObj.getWorldTime() % 137 == 0) {
Area fishingHole = _ham.getHarvestArea();
for (BlockPosition bp : fishingHole.getPositionsBottomFirst()) {
if (worldObj.getBlockId(bp.x, bp.y, bp.z) != Block.waterStill.blockID) {
_isJammed = true;
setIdleTicks(getIdleTicksMax());
return false;
}
}
}
_isJammed = false;
setWorkDone(getWorkDone() + 1);
if (getWorkDone() > getWorkMax()) {
doDrop(new ItemStack(Item.fishRaw));
setWorkDone(0);
}
return true;
}
use of powercrystals.core.position.BlockPosition in project MineFactoryReloaded by powercrystals.
the class TileEntityFruitPicker 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.fruitTreeSearchMaxVertical.getInt() : y);
int yTreeAreaUpperBound = (treeFlipped ? y : y + MFRConfig.fruitTreeSearchMaxVertical.getInt());
Area a = new Area(x - MFRConfig.fruitTreeSearchMaxHorizontal.getInt(), x + MFRConfig.fruitTreeSearchMaxHorizontal.getInt(), yTreeAreaLowerBound, yTreeAreaUpperBound, z - MFRConfig.fruitTreeSearchMaxHorizontal.getInt(), z + MFRConfig.fruitTreeSearchMaxHorizontal.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.getFruits().containsKey(new Integer(blockId)) && MFRRegistry.getFruits().get(new Integer(blockId)).canBePicked(worldObj, bp.x, bp.y, bp.z)) {
return bp;
}
_treeManager.moveNext();
}
}
use of powercrystals.core.position.BlockPosition in project MineFactoryReloaded by powercrystals.
the class BlockRedNetCable method isProvidingStrongPower.
@Override
public int isProvidingStrongPower(IBlockAccess world, int x, int y, int z, int side) {
int power = 0;
TileEntity te = world.getBlockTileEntity(x, y, z);
if (te instanceof TileEntityRedNetCable) {
TileEntityRedNetCable cable = ((TileEntityRedNetCable) te);
if (cable.getNetwork() == null || cable.getConnectionState(ForgeDirection.VALID_DIRECTIONS[side].getOpposite()) == RedNetConnectionType.None) {
return 0;
}
BlockPosition nodebp = new BlockPosition(x, y, z, ForgeDirection.getOrientation(side).getOpposite());
nodebp.moveForwards(1);
int subnet = cable.getSideColor(nodebp.orientation);
if (cable.getNetwork().isWeakNode(nodebp)) {
power = 0;
RedstoneNetwork.log("Asked for strong power at " + x + "," + y + "," + z + " - weak node, power 0");
} else {
power = Math.min(Math.max(cable.getNetwork().getPowerLevelOutput(subnet), 0), 15);
RedstoneNetwork.log("Asked for strong power at " + x + "," + y + "," + z + " - got " + power + " from network " + ((TileEntityRedNetCable) te).getNetwork().getId() + ":" + subnet);
}
}
return power;
}
Aggregations