Basic reformat, hit once, hope never again
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
|
||||
package appeng.services.compass;
|
||||
|
||||
|
||||
public class CompassException extends RuntimeException
|
||||
{
|
||||
|
||||
@@ -25,8 +26,8 @@ public class CompassException extends RuntimeException
|
||||
|
||||
public final Throwable inner;
|
||||
|
||||
public CompassException(Throwable t) {
|
||||
public CompassException( Throwable t )
|
||||
{
|
||||
this.inner = t;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
package appeng.services.compass;
|
||||
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
|
||||
@@ -28,9 +29,15 @@ public class CompassReader
|
||||
private final int dimensionId;
|
||||
private final File rootFolder;
|
||||
|
||||
public CompassReader( int dimensionId, File rootFolder )
|
||||
{
|
||||
this.dimensionId = dimensionId;
|
||||
this.rootFolder = rootFolder;
|
||||
}
|
||||
|
||||
public void close()
|
||||
{
|
||||
for (CompassRegion r : this.regions.values())
|
||||
for( CompassRegion r : this.regions.values() )
|
||||
{
|
||||
r.close();
|
||||
}
|
||||
@@ -38,39 +45,31 @@ public class CompassReader
|
||||
this.regions.clear();
|
||||
}
|
||||
|
||||
public CompassReader(int dimensionId, File rootFolder)
|
||||
{
|
||||
this.dimensionId = dimensionId;
|
||||
this.rootFolder = rootFolder;
|
||||
}
|
||||
|
||||
public void setHasBeacon(int cx, int cz, int cdy, boolean hasBeacon)
|
||||
public void setHasBeacon( int cx, int cz, int cdy, boolean hasBeacon )
|
||||
{
|
||||
CompassRegion r = this.getRegion( cx, cz );
|
||||
r.setHasBeacon( cx, cz, cdy, hasBeacon );
|
||||
}
|
||||
|
||||
public boolean hasBeacon(int cx, int cz)
|
||||
{
|
||||
CompassRegion r = this.getRegion( cx, cz );
|
||||
return r.hasBeacon( cx, cz );
|
||||
}
|
||||
|
||||
private CompassRegion getRegion(int cx, int cz)
|
||||
private CompassRegion getRegion( int cx, int cz )
|
||||
{
|
||||
long pos = cx >> 10;
|
||||
pos <<= 32;
|
||||
pos |= ( cz >> 10 );
|
||||
|
||||
CompassRegion cr = this.regions.get( pos );
|
||||
if ( cr == null )
|
||||
if( cr == null )
|
||||
{
|
||||
cr = new CompassRegion( cx, cz, this.dimensionId, this.rootFolder );
|
||||
this.regions.put( pos, cr );
|
||||
}
|
||||
|
||||
return cr;
|
||||
|
||||
}
|
||||
|
||||
public boolean hasBeacon( int cx, int cz )
|
||||
{
|
||||
CompassRegion r = this.getRegion( cx, cz );
|
||||
return r.hasBeacon( cx, cz );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,11 +59,52 @@ public class CompassRegion
|
||||
this.openFile( false );
|
||||
}
|
||||
|
||||
private void openFile( boolean create )
|
||||
{
|
||||
File fName = this.getFileName();
|
||||
if( this.hasFile )
|
||||
return;
|
||||
|
||||
if( create || this.fileExists( fName ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
this.raf = new RandomAccessFile( fName, "rw" );
|
||||
FileChannel fc = this.raf.getChannel();
|
||||
this.buffer = fc.map( FileChannel.MapMode.READ_WRITE, 0, 0x400 * 0x400 );// fc.size() );
|
||||
this.hasFile = true;
|
||||
}
|
||||
catch( Throwable t )
|
||||
{
|
||||
throw new CompassException( t );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private File getFileName()
|
||||
{
|
||||
String folder = this.rootFolder.getPath() + File.separatorChar + "compass";
|
||||
File folderFile = new File( folder );
|
||||
|
||||
if( !folderFile.exists() || !folderFile.isDirectory() )
|
||||
{
|
||||
if( !folderFile.mkdir() )
|
||||
AELog.info( "Failed to create AE2/compass/" );
|
||||
}
|
||||
|
||||
return new File( folder, this.world + '_' + this.low_x + '_' + this.low_z + ".dat" );
|
||||
}
|
||||
|
||||
private boolean fileExists( File name )
|
||||
{
|
||||
return name.exists() && name.isFile();
|
||||
}
|
||||
|
||||
public void close()
|
||||
{
|
||||
try
|
||||
{
|
||||
if ( this.hasFile )
|
||||
if( this.hasFile )
|
||||
{
|
||||
this.buffer = null;
|
||||
this.raf.close();
|
||||
@@ -71,7 +112,7 @@ public class CompassRegion
|
||||
this.hasFile = false;
|
||||
}
|
||||
}
|
||||
catch ( Throwable t )
|
||||
catch( Throwable t )
|
||||
{
|
||||
throw new CompassException( t );
|
||||
}
|
||||
@@ -79,55 +120,19 @@ public class CompassRegion
|
||||
|
||||
public boolean hasBeacon( int cx, int cz )
|
||||
{
|
||||
if ( this.hasFile )
|
||||
if( this.hasFile )
|
||||
{
|
||||
cx &= 0x3FF;
|
||||
cz &= 0x3FF;
|
||||
|
||||
int val = this.read( cx, cz );
|
||||
if ( val != 0 )
|
||||
if( val != 0 )
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setHasBeacon( int cx, int cz, int cdy, boolean hasBeacon )
|
||||
{
|
||||
cx &= 0x3FF;
|
||||
cz &= 0x3FF;
|
||||
|
||||
this.openFile( hasBeacon );
|
||||
|
||||
if ( this.hasFile )
|
||||
{
|
||||
int val = this.read( cx, cz );
|
||||
int originalVal = val;
|
||||
|
||||
if ( hasBeacon )
|
||||
val |= 1 << cdy;
|
||||
else
|
||||
val &= ~( 1 << cdy );
|
||||
|
||||
if ( originalVal != val )
|
||||
this.write( cx, cz, val );
|
||||
}
|
||||
}
|
||||
|
||||
private void write( int cx, int cz, int val )
|
||||
{
|
||||
try
|
||||
{
|
||||
this.buffer.put( cx + cz * 0x400, ( byte ) val );
|
||||
// raf.seek( cx + cz * 0x400 );
|
||||
// raf.writeByte( val );
|
||||
}
|
||||
catch ( Throwable t )
|
||||
{
|
||||
throw new CompassException( t );
|
||||
}
|
||||
}
|
||||
|
||||
private int read( int cx, int cz )
|
||||
{
|
||||
try
|
||||
@@ -136,55 +141,49 @@ public class CompassRegion
|
||||
// raf.seek( cx + cz * 0x400 );
|
||||
// return raf.readByte();
|
||||
}
|
||||
catch ( IndexOutOfBoundsException outOfBounds )
|
||||
catch( IndexOutOfBoundsException outOfBounds )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
catch ( Throwable t )
|
||||
catch( Throwable t )
|
||||
{
|
||||
throw new CompassException( t );
|
||||
}
|
||||
}
|
||||
|
||||
private void openFile( boolean create )
|
||||
public void setHasBeacon( int cx, int cz, int cdy, boolean hasBeacon )
|
||||
{
|
||||
File fName = this.getFileName();
|
||||
if ( this.hasFile )
|
||||
return;
|
||||
cx &= 0x3FF;
|
||||
cz &= 0x3FF;
|
||||
|
||||
if ( create || this.fileExists( fName ) )
|
||||
this.openFile( hasBeacon );
|
||||
|
||||
if( this.hasFile )
|
||||
{
|
||||
try
|
||||
{
|
||||
this.raf = new RandomAccessFile( fName, "rw" );
|
||||
FileChannel fc = this.raf.getChannel();
|
||||
this.buffer = fc.map( FileChannel.MapMode.READ_WRITE, 0, 0x400 * 0x400 );// fc.size() );
|
||||
this.hasFile = true;
|
||||
}
|
||||
catch ( Throwable t )
|
||||
{
|
||||
throw new CompassException( t );
|
||||
}
|
||||
}
|
||||
int val = this.read( cx, cz );
|
||||
int originalVal = val;
|
||||
|
||||
if( hasBeacon )
|
||||
val |= 1 << cdy;
|
||||
else
|
||||
val &= ~( 1 << cdy );
|
||||
|
||||
if( originalVal != val )
|
||||
this.write( cx, cz, val );
|
||||
}
|
||||
}
|
||||
|
||||
private boolean fileExists( File name )
|
||||
private void write( int cx, int cz, int val )
|
||||
{
|
||||
return name.exists() && name.isFile();
|
||||
}
|
||||
|
||||
private File getFileName()
|
||||
{
|
||||
String folder = this.rootFolder.getPath() + File.separatorChar + "compass";
|
||||
File folderFile = new File( folder );
|
||||
|
||||
if ( !folderFile.exists() || !folderFile.isDirectory() )
|
||||
try
|
||||
{
|
||||
if ( !folderFile.mkdir() )
|
||||
AELog.info( "Failed to create AE2/compass/" );
|
||||
this.buffer.put( cx + cz * 0x400, (byte) val );
|
||||
// raf.seek( cx + cz * 0x400 );
|
||||
// raf.writeByte( val );
|
||||
}
|
||||
catch( Throwable t )
|
||||
{
|
||||
throw new CompassException( t );
|
||||
}
|
||||
|
||||
return new File( folder, this.world + '_' + this.low_x + '_' + this.low_z + ".dat" );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
package appeng.services.compass;
|
||||
|
||||
|
||||
public interface ICompassCallback
|
||||
{
|
||||
|
||||
@@ -25,10 +26,9 @@ public interface ICompassCallback
|
||||
* Called from another thread.
|
||||
*
|
||||
* @param hasResult true if found a target
|
||||
* @param spin true if should spin
|
||||
* @param radians radians
|
||||
* @param dist distance
|
||||
* @param spin true if should spin
|
||||
* @param radians radians
|
||||
* @param dist distance
|
||||
*/
|
||||
void calculatedDirection( boolean hasResult, boolean spin, double radians, double dist );
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user