Java Code Examples for erogenousbeef.core.common.CoordTriplet#compareTo()

The following examples show how to use erogenousbeef.core.common.CoordTriplet#compareTo() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MultiblockControllerBase.java    From BeefCore with MIT License 5 votes vote down vote up
private int _shouldConsume(MultiblockControllerBase otherController) {
	CoordTriplet myCoord = getReferenceCoord();
	CoordTriplet theirCoord = otherController.getReferenceCoord();
	
	// Always consume other controllers if their reference coordinate is null - this means they're empty and can be assimilated on the cheap
	if(theirCoord == null) { return -1; }
	else { return myCoord.compareTo(theirCoord); }
}
 
Example 2
Source File: MultiblockControllerBase.java    From BeefCore with MIT License 4 votes vote down vote up
/**
 * Attach a new part to this machine.
 * @param part The part to add.
 */
public void attachBlock(IMultiblockPart part) {
	IMultiblockPart candidate;
	CoordTriplet coord = part.getWorldLocation();

	if(!connectedParts.add(part)) {
		BeefCoreLog.warning("[%s] Controller %s is double-adding part %d @ %s. This is unusual. If you encounter odd behavior, please tear down the machine and rebuild it.", (worldObj.isRemote?"CLIENT":"SERVER"), hashCode(), part.hashCode(), coord);
	}
	
	part.onAttached(this);
	this.onBlockAdded(part);

	if(part.hasMultiblockSaveData()) {
		NBTTagCompound savedData = part.getMultiblockSaveData();
		onAttachedPartWithMultiblockData(part, savedData);
		part.onMultiblockDataAssimilated();
	}
	
	if(this.referenceCoord == null) {
		referenceCoord = coord;
		part.becomeMultiblockSaveDelegate();
	}
	else if(coord.compareTo(referenceCoord) < 0) {
		TileEntity te = this.worldObj.getTileEntity(referenceCoord.x, referenceCoord.y, referenceCoord.z);
		((IMultiblockPart)te).forfeitMultiblockSaveDelegate();
		
		referenceCoord = coord;
		part.becomeMultiblockSaveDelegate();
	}
	else {
		part.forfeitMultiblockSaveDelegate();
	}
	
	if(minimumCoord != null) {
		if(part.xCoord < minimumCoord.x) { minimumCoord.x = part.xCoord; }
		if(part.yCoord < minimumCoord.y) { minimumCoord.y = part.yCoord; }
		if(part.zCoord < minimumCoord.z) { minimumCoord.z = part.zCoord; }
	}
	
	if(maximumCoord != null) {
		if(part.xCoord > maximumCoord.x) { maximumCoord.x = part.xCoord; }
		if(part.yCoord > maximumCoord.y) { maximumCoord.y = part.yCoord; }
		if(part.zCoord > maximumCoord.z) { maximumCoord.z = part.zCoord; }
	}
	
	MultiblockRegistry.addDirtyController(worldObj, this);
}