Basic reformat, hit once, hope never again

This commit is contained in:
thatsIch
2015-04-03 08:54:31 +02:00
parent 4ff1631f89
commit d34c988c88
886 changed files with 31400 additions and 30990 deletions
@@ -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" );
}
}