Fixes #976 Now uses GitHub to retrieve most current version
Reworked whole Version Checker with an extensible interface to add any other service later on easier. The version checker now has its own config file, to collect the different options and extract them from the main config file. In that you can specify how fine the versions should be checked.
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.services.compass;
|
||||
|
||||
public class CompassException extends RuntimeException
|
||||
{
|
||||
|
||||
private static final long serialVersionUID = 8825268683203860877L;
|
||||
|
||||
public final Throwable inner;
|
||||
|
||||
public CompassException(Throwable t) {
|
||||
this.inner = t;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.services.compass;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
|
||||
|
||||
public class CompassReader
|
||||
{
|
||||
private final HashMap<Long, CompassRegion> regions = new HashMap<Long, CompassRegion>();
|
||||
private final int dimensionId;
|
||||
private final File rootFolder;
|
||||
|
||||
public void close()
|
||||
{
|
||||
for (CompassRegion r : this.regions.values())
|
||||
{
|
||||
r.close();
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
long pos = cx >> 10;
|
||||
pos = pos << 32;
|
||||
pos = pos | (cz >> 10);
|
||||
|
||||
CompassRegion cr = this.regions.get( pos );
|
||||
if ( cr == null )
|
||||
{
|
||||
cr = new CompassRegion( cx, cz, this.dimensionId, this.rootFolder );
|
||||
this.regions.put( pos, cr );
|
||||
}
|
||||
|
||||
return cr;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,190 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.services.compass;
|
||||
|
||||
|
||||
import java.io.File;
|
||||
import java.io.RandomAccessFile;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.FileChannel;
|
||||
|
||||
import appeng.core.AELog;
|
||||
|
||||
|
||||
public class CompassRegion
|
||||
{
|
||||
final int low_x;
|
||||
final int low_z;
|
||||
|
||||
final int hi_x;
|
||||
final int hi_z;
|
||||
|
||||
final int world;
|
||||
final File rootFolder;
|
||||
boolean hasFile = false;
|
||||
RandomAccessFile raf = null;
|
||||
ByteBuffer buffer;
|
||||
|
||||
public CompassRegion( int cx, int cz, int worldID, File rootFolder )
|
||||
{
|
||||
|
||||
this.world = worldID;
|
||||
this.rootFolder = rootFolder;
|
||||
|
||||
int region_x = cx >> 10;
|
||||
int region_z = cz >> 10;
|
||||
|
||||
this.low_x = region_x << 10;
|
||||
this.low_z = region_z << 10;
|
||||
|
||||
this.hi_x = this.low_x + 1024;
|
||||
this.hi_z = this.low_z + 1024;
|
||||
|
||||
this.openFile( false );
|
||||
}
|
||||
|
||||
public void close()
|
||||
{
|
||||
try
|
||||
{
|
||||
if ( this.hasFile )
|
||||
{
|
||||
this.buffer = null;
|
||||
this.raf.close();
|
||||
this.raf = null;
|
||||
this.hasFile = false;
|
||||
}
|
||||
}
|
||||
catch ( Throwable t )
|
||||
{
|
||||
throw new CompassException( t );
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasBeacon( int cx, int cz )
|
||||
{
|
||||
if ( this.hasFile )
|
||||
{
|
||||
cx = cx & 0x3FF;
|
||||
cz = cz & 0x3FF;
|
||||
|
||||
int val = this.read( cx, cz );
|
||||
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
|
||||
{
|
||||
return this.buffer.get( cx + cz * 0x400 );
|
||||
// raf.seek( cx + cz * 0x400 );
|
||||
// return raf.readByte();
|
||||
}
|
||||
catch ( IndexOutOfBoundsException outOfBounds )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
catch ( Throwable t )
|
||||
{
|
||||
throw new CompassException( t );
|
||||
}
|
||||
}
|
||||
|
||||
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 boolean fileExists( File name )
|
||||
{
|
||||
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() )
|
||||
{
|
||||
if ( !folderFile.mkdir() )
|
||||
AELog.info( "Failed to create AE2/compass/" );
|
||||
}
|
||||
|
||||
return new File( folder + File.separatorChar + this.world + '_' + this.low_x + '_' + this.low_z + ".dat" );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.services.compass;
|
||||
|
||||
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
|
||||
*/
|
||||
public void calculatedDirection(boolean hasResult, boolean spin, double radians, double dist);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user