Improves the message generated when generating the folder for the compass data.
Outsources the encoding of the compass data into the file name Written tests for the encoding Did some internal cleaning of the class Conflicts: src/main/java/appeng/block/solids/BlockSkyStone.java src/main/java/appeng/core/WorldSettings.java src/main/java/appeng/core/features/registries/PlayerRegistry.java src/main/java/appeng/core/sync/network/NetworkHandler.java src/main/java/appeng/core/worlddata/PlayerMapping.java src/main/java/appeng/core/worlddata/PlayerMappingsInitializer.java src/main/java/appeng/services/CompassService.java src/main/java/appeng/worldgen/MeteoritePlacer.java src/main/java/appeng/worldgen/MeteoriteWorldGen.java
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
* Copyright (c) 2013 - 2015, 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
|
||||
@@ -21,18 +21,25 @@ package appeng.services.compass;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
|
||||
public class CompassReader
|
||||
public final class CompassReader
|
||||
{
|
||||
private final HashMap<Long, CompassRegion> regions = new HashMap<Long, CompassRegion>();
|
||||
private final Map<Long, CompassRegion> regions = new HashMap<Long, CompassRegion>( 100 );
|
||||
private final int dimensionId;
|
||||
private final File rootFolder;
|
||||
private final File worldCompassFolder;
|
||||
|
||||
public CompassReader( int dimensionId, File rootFolder )
|
||||
public CompassReader( int dimensionId, @Nonnull final File worldCompassFolder )
|
||||
{
|
||||
Preconditions.checkNotNull( worldCompassFolder );
|
||||
Preconditions.checkArgument( worldCompassFolder.isDirectory() );
|
||||
|
||||
this.dimensionId = dimensionId;
|
||||
this.rootFolder = rootFolder;
|
||||
this.worldCompassFolder = worldCompassFolder;
|
||||
}
|
||||
|
||||
public void close()
|
||||
@@ -60,7 +67,7 @@ public class CompassReader
|
||||
CompassRegion cr = this.regions.get( pos );
|
||||
if( cr == null )
|
||||
{
|
||||
cr = new CompassRegion( cx, cz, this.dimensionId, this.rootFolder );
|
||||
cr = new CompassRegion( cx, cz, this.dimensionId, this.worldCompassFolder );
|
||||
this.regions.put( pos, cr );
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
* Copyright (c) 2013 - 2015, 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
|
||||
@@ -23,55 +23,56 @@ import java.io.File;
|
||||
import java.io.RandomAccessFile;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.FileChannel;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import appeng.core.AELog;
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
import appeng.core.worlddata.MeteorDataNameEncoder;
|
||||
|
||||
|
||||
public class CompassRegion
|
||||
public final class CompassRegion
|
||||
{
|
||||
final int low_x;
|
||||
final int low_z;
|
||||
private final int lowX;
|
||||
private final int lowZ;
|
||||
private final int world;
|
||||
private final File worldCompassFolder;
|
||||
private final MeteorDataNameEncoder encoder;
|
||||
|
||||
final int hi_x;
|
||||
final int hi_z;
|
||||
private boolean hasFile = false;
|
||||
private RandomAccessFile raf = null;
|
||||
private ByteBuffer buffer;
|
||||
|
||||
final int world;
|
||||
final File rootFolder;
|
||||
boolean hasFile = false;
|
||||
RandomAccessFile raf = null;
|
||||
ByteBuffer buffer;
|
||||
|
||||
public CompassRegion( int cx, int cz, int worldID, File rootFolder )
|
||||
public CompassRegion( int cx, int cz, int worldID, @Nonnull final File worldCompassFolder )
|
||||
{
|
||||
Preconditions.checkNotNull( worldCompassFolder );
|
||||
Preconditions.checkArgument( worldCompassFolder.isDirectory() );
|
||||
|
||||
this.world = worldID;
|
||||
this.rootFolder = rootFolder;
|
||||
this.worldCompassFolder = worldCompassFolder;
|
||||
this.encoder = new MeteorDataNameEncoder( 0 );
|
||||
|
||||
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.lowX = region_x << 10;
|
||||
this.lowZ = region_z << 10;
|
||||
|
||||
this.openFile( false );
|
||||
}
|
||||
|
||||
private void openFile( boolean create )
|
||||
{
|
||||
File fName = this.getFileName();
|
||||
if( this.hasFile )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if( create || this.fileExists( fName ) )
|
||||
final File file = this.getFile();
|
||||
if( create || this.isFileExistent( file ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
this.raf = new RandomAccessFile( fName, "rw" );
|
||||
this.raf = new RandomAccessFile( file, "rw" );
|
||||
FileChannel fc = this.raf.getChannel();
|
||||
this.buffer = fc.map( FileChannel.MapMode.READ_WRITE, 0, 0x400 * 0x400 );// fc.size() );
|
||||
this.hasFile = true;
|
||||
@@ -83,25 +84,16 @@ public class CompassRegion
|
||||
}
|
||||
}
|
||||
|
||||
private File getFileName()
|
||||
private File getFile()
|
||||
{
|
||||
String folder = this.rootFolder.getPath() + File.separatorChar + "compass";
|
||||
File folderFile = new File( folder );
|
||||
final String fileName = this.encoder.encode( this.world, this.lowX, this.lowZ);
|
||||
|
||||
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" );
|
||||
return new File( this.worldCompassFolder, fileName );
|
||||
}
|
||||
|
||||
private boolean fileExists( File name )
|
||||
private boolean isFileExistent( File file )
|
||||
{
|
||||
return name.exists() && name.isFile();
|
||||
return file.exists() && file.isFile();
|
||||
}
|
||||
|
||||
public void close()
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2015, 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.util.concurrent.ThreadFactory;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
|
||||
/**
|
||||
* @author thatsIch
|
||||
* @version rv3 - 31.05.2015
|
||||
* @since rv3 31.05.2015
|
||||
*/
|
||||
public final class CompassThreadFactory implements ThreadFactory
|
||||
{
|
||||
@Override
|
||||
public Thread newThread( @Nonnull final Runnable job )
|
||||
{
|
||||
Preconditions.checkNotNull( job );
|
||||
|
||||
return new Thread( job, "AE Compass Service" );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user