Added Eraser Debug Tool.

Meteorite Spawning Complete.
Removed a lot of test Logging.
This commit is contained in:
AlgorithmX2 2014-03-02 17:18:15 -06:00
parent 792249f8fd
commit 58992d0786
12 changed files with 253 additions and 46 deletions

View file

@ -79,9 +79,11 @@ import appeng.core.localization.PlayerMessages;
import appeng.debug.BlockChunkloader;
import appeng.debug.BlockItemGen;
import appeng.debug.ToolDebugCard;
import appeng.debug.ToolEraser;
import appeng.debug.ToolMeteoritePlacer;
import appeng.debug.ToolReplicatorCard;
import appeng.hooks.AETrading;
import appeng.hooks.MeteoriteWorldGen;
import appeng.hooks.QuartzWorldGen;
import appeng.hooks.TickHandler;
import appeng.items.materials.ItemMaterial;
@ -343,6 +345,7 @@ public class Registration
items.itemFacade = addFeature( ItemFacade.class );
items.itemCrystalSeed = addFeature( ItemCrystalSeed.class );
addFeature( ToolEraser.class );
addFeature( ToolMeteoritePlacer.class );
addFeature( ToolDebugCard.class );
addFeature( ToolReplicatorCard.class );
@ -556,6 +559,9 @@ public class Registration
if ( AEConfig.instance.isFeatureEnabled( AEFeature.CertusQuartzWorldGen ) )
GameRegistry.registerWorldGenerator( new QuartzWorldGen(), 0 );
if ( AEConfig.instance.isFeatureEnabled( AEFeature.MeteoriteWorldGen ) )
GameRegistry.registerWorldGenerator( new MeteoriteWorldGen(), 0 );
recipeHandler.registerHandlers();
}
}

View file

@ -6,7 +6,7 @@ public enum AEFeature
// is just flat out required by tons of
// important stuff.
CertusQuartzWorldGen("World"),
CertusQuartzWorldGen("World"), MeteoriteWorldGen("World"),
DecorativeLights("World"), DecorativeQuartzBlocks("World"),

View file

@ -8,7 +8,6 @@ import java.io.IOException;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import appeng.api.util.DimensionalCoord;
import appeng.core.AELog;
import appeng.core.WorldSettings;
import appeng.core.sync.AppEngPacket;
import appeng.core.sync.network.INetworkInfo;
@ -32,7 +31,7 @@ public class PacketCompassRequest extends AppEngPacket implements ICompassCallba
}
@Override
public void calculatedDirection(boolean hasResult, boolean spin, double radians)
public void calculatedDirection(boolean hasResult, boolean spin, double radians, double dist)
{
NetworkHandler.instance.sendTo( new PacketCompassResponse( this, hasResult, spin, radians ), (EntityPlayerMP) talkBackTo );
}
@ -40,11 +39,10 @@ public class PacketCompassRequest extends AppEngPacket implements ICompassCallba
@Override
public void serverPacketData(INetworkInfo manager, AppEngPacket packet, EntityPlayer player)
{
AELog.info( "PacketCompassRequest.serverPacketData" );
talkBackTo = player;
DimensionalCoord loc = new DimensionalCoord( player.worldObj, this.cx << 4, this.cdy << 5, this.cz << 4 );
WorldSettings.getInstance().getCompass().getCompassDirection( loc, this );
WorldSettings.getInstance().getCompass().getCompassDirection( loc, 128, this );
}
// api

View file

@ -6,7 +6,6 @@ import io.netty.buffer.Unpooled;
import java.io.IOException;
import net.minecraft.entity.player.EntityPlayer;
import appeng.core.AELog;
import appeng.core.sync.AppEngPacket;
import appeng.core.sync.network.INetworkInfo;
import appeng.hooks.CompassManager;
@ -33,7 +32,6 @@ public class PacketCompassResponse extends AppEngPacket
@Override
public void clientPacketData(INetworkInfo network, AppEngPacket packet, EntityPlayer player)
{
AELog.info( "PacketCompassResponse.clientPacketData" );
CompassManager.instance.postResult( attunement, cx << 4, cdy << 5, cz << 4, cr );
}

75
debug/ToolEraser.java Normal file
View file

@ -0,0 +1,75 @@
package appeng.debug;
import java.util.EnumSet;
import java.util.LinkedList;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import appeng.api.util.WorldCoord;
import appeng.core.AELog;
import appeng.core.features.AEFeature;
import appeng.items.AEBaseItem;
import appeng.util.Platform;
public class ToolEraser extends AEBaseItem
{
public ToolEraser() {
super( ToolEraser.class );
setfeature( EnumSet.of( AEFeature.Debug, AEFeature.Creative ) );
}
@Override
public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ)
{
if ( Platform.isClient() )
return false;
Block blk = world.getBlock( x, y, z );
int meta = world.getBlockMetadata( x, y, z );
int blocks = 0;
List<WorldCoord> next = new LinkedList();
next.add( new WorldCoord( x, y, z ) );
while (blocks < 90000 && !next.isEmpty())
{
List<WorldCoord> c = next;
next = new LinkedList();
for (WorldCoord wc : c)
{
Block c_blk = world.getBlock( wc.x, wc.y, wc.z );
int c_meta = world.getBlockMetadata( wc.x, wc.y, wc.z );
if ( c_blk == blk && c_meta == meta )
{
blocks++;
world.setBlock( wc.x, wc.y, wc.z, Platform.air );
check( world, wc.x + 1, wc.y, wc.z, next );
check( world, wc.x - 1, wc.y, wc.z, next );
check( world, wc.x, wc.y + 1, wc.z, next );
check( world, wc.x, wc.y - 1, wc.z, next );
check( world, wc.x, wc.y, wc.z + 1, next );
check( world, wc.x, wc.y, wc.z - 1, next );
}
}
}
AELog.info( "Delete " + blocks + " blocks" );
return true;
}
private void check(World world, int i, int y, int z, List<WorldCoord> next)
{
next.add( new WorldCoord( i, y, z ) );
}
}

View file

@ -43,7 +43,7 @@ public class MeteoritePlacer
else if ( a > 0.8 )
put( w, x, y, z, Blocks.stone );
else if ( a > 0.7 )
put( w, x, y, z, Blocks.dirt );
put( w, x, y, z, Blocks.grass );
else if ( a > 0.6 )
put( w, x, y, z, skystone );
else if ( a > 0.5 )
@ -105,7 +105,7 @@ public class MeteoritePlacer
public void getOther(World w, int x, int y, int z, double a)
{
if ( a > 0.8 )
if ( a > 0.66 )
put( w, x, y, z, Blocks.glass );
}
@ -118,6 +118,7 @@ public class MeteoritePlacer
Fallout type = new Fallout();
Block skystone = AEApi.instance().blocks().blockSkyStone.block();
Block skychest = AEApi.instance().blocks().blockSkyChest.block();
double real_sizeOfMetorite = (Math.random() * 6.0) + 2;
double real_crator = real_sizeOfMetorite * 2 + 5;
@ -126,7 +127,6 @@ public class MeteoritePlacer
double crator = real_crator * real_crator;
public MeteoritePlacer() {
Block skystone = AEApi.instance().blocks().blockSkyStone.block();
validSpawn.add( Blocks.stone );
validSpawn.add( Blocks.cobblestone );
@ -277,6 +277,8 @@ public class MeteoritePlacer
if ( dx * dx * 0.7 + dy * dy * (j > y ? 1.4 : 0.8) + dz * dz * 0.7 < sizeOfMetorite )
put( w, i, j, k, skystone );
}
put( w, x, y, z, skychest );
}
private void Decay(World w, int x, int y, int z)
@ -310,7 +312,8 @@ public class MeteoritePlacer
double dist = dx * dx + dy * dy + dz * dz;
Block xf = w.getBlock( i, j - 1, k );
if ( !xf.isReplaceable( w, i, j - 1, k ) )
{
double height = crator * 0.1 - Math.abs( dist - crator * 1.7 );
if ( xf != blk && height > 0 && Math.random() > 0.5 )
@ -319,6 +322,7 @@ public class MeteoritePlacer
}
}
}
}
else
{
// decay.

View file

@ -48,7 +48,6 @@ public class CompassManager
public void postResult(long attunement, int x, int y, int z, CompassResult res)
{
AELog.info( "CompassManager.postResult" );
CompassReq r = new CompassReq( attunement, x, y, z );
reqs.put( r, res );
}
@ -89,7 +88,6 @@ public class CompassManager
private void requestUpdate(CompassReq r)
{
AELog.info( "CompassManager.requestUpdate" );
try
{

View file

@ -0,0 +1,81 @@
package appeng.hooks;
import java.util.Random;
import net.minecraft.world.World;
import net.minecraft.world.chunk.IChunkProvider;
import appeng.api.util.DimensionalCoord;
import appeng.core.WorldSettings;
import appeng.helpers.MeteoritePlacer;
import appeng.services.helpers.ICompassCallback;
import cpw.mods.fml.common.IWorldGenerator;
final public class MeteoriteWorldGen implements IWorldGenerator
{
class myGen implements ICompassCallback
{
double distance = 0;
@Override
public void calculatedDirection(boolean hasResult, boolean spin, double radians, double dist)
{
if ( hasResult )
distance = dist;
else
distance = Double.MAX_VALUE;
synchronized (this)
{
notify();
}
}
};
@Override
public void generate(Random r, int chunkX, int chunkZ, World w, IChunkProvider chunkGenerator, IChunkProvider chunkProvider)
{
if ( r.nextFloat() > 0.9 )
{
int x = r.nextInt( 16 ) + (chunkX << 4);
int z = r.nextInt( 16 ) + (chunkZ << 4);
myGen obj = new myGen();
WorldSettings.getInstance().getCompass().getCompassDirection( new DimensionalCoord( w, x, 128, z ), 30, obj );
synchronized (obj)
{
try
{
obj.wait();
}
catch (InterruptedException e)
{
// meh
return;
}
}
if ( obj.distance > 1000 * 1000 )
{
int depth = 180 + r.nextInt( 20 );
for (int trys = 0; trys < 20; trys++)
{
MeteoritePlacer mp = new MeteoritePlacer();
if ( mp.spawnMeteorite( w, x, depth, z ) )
return;
depth -= 15;
if ( depth < 40 )
return;
}
}
}
}
}

View file

@ -8,7 +8,6 @@ import net.minecraft.block.Block;
import net.minecraft.world.World;
import appeng.api.AEApi;
import appeng.api.util.DimensionalCoord;
import appeng.core.AELog;
import appeng.services.helpers.CompassException;
import appeng.services.helpers.CompassReader;
import appeng.services.helpers.ICompassCallback;
@ -59,6 +58,7 @@ public class CompassService implements Runnable
{
public final DimensionalCoord coord;
public final int maxRange;
public final ICompassCallback callback;
@Override
@ -67,8 +67,9 @@ public class CompassService implements Runnable
return true;
}
public CMDirectionRequest(DimensionalCoord coord, ICompassCallback cc) {
public CMDirectionRequest(DimensionalCoord coord, int getMaxRange, ICompassCallback cc) {
this.coord = coord;
this.maxRange = getMaxRange;
callback = cc;
}
@ -111,9 +112,9 @@ public class CompassService implements Runnable
postJob( new CMUpdatePost( w, cx, cz, cdy, false ) );
}
public void getCompassDirection(DimensionalCoord coord, ICompassCallback cc)
public void getCompassDirection(DimensionalCoord coord, int maxRange, ICompassCallback cc)
{
postJob( new CMDirectionRequest( coord, cc ) );
postJob( new CMDirectionRequest( coord, maxRange, cc ) );
}
private void postJob(CompassMessage msg)
@ -137,6 +138,8 @@ public class CompassService implements Runnable
try
{
myMsg = jobList.poll();
overOberdened = jobList.isEmpty();
if ( myMsg == null )
jobList.wait();
}
@ -150,6 +153,7 @@ public class CompassService implements Runnable
return myMsg;
}
boolean overOberdened = false;
HashMap<World, CompassReader> worldSet = new HashMap();
final File rootFolder;
@ -173,8 +177,6 @@ public class CompassService implements Runnable
private void processRequest(CMDirectionRequest req)
{
AELog.info( "CompassService.processRequest" );
int cx = req.coord.x >> 4;
int cz = req.coord.z >> 4;
@ -183,8 +185,7 @@ public class CompassService implements Runnable
// Am I standing on it?
if ( cr.hasBeacon( cx, cz ) )
{
req.callback.calculatedDirection( true, true, -999 );
cr.close();
req.callback.calculatedDirection( true, true, -999, 0 );
return;
}
@ -196,20 +197,32 @@ public class CompassService implements Runnable
int maxx = cx + offset;
int maxz = cz + offset;
int closest = Integer.MAX_VALUE;
int chosen_x = cx;
int chosen_z = cz;
for (int z = minz; z <= maxz; z++)
{
if ( cr.hasBeacon( minx, z ) )
{
req.callback.calculatedDirection( true, false, rad( cx, cz, minx, z ) );
cr.close();
return;
int closness = dist( cx, cz, minx, z );
if ( closness < closest )
{
closest = closness;
chosen_x = minx;
chosen_z = z;
}
}
if ( cr.hasBeacon( maxx, z ) )
{
req.callback.calculatedDirection( true, false, rad( cx, cz, maxx, z ) );
cr.close();
return;
int closness = dist( cx, cz, maxx, z );
if ( closness < closest )
{
closest = closness;
chosen_x = maxx;
chosen_z = z;
}
}
}
@ -217,23 +230,48 @@ public class CompassService implements Runnable
{
if ( cr.hasBeacon( x, minz ) )
{
req.callback.calculatedDirection( true, false, rad( cx, cz, x, minz ) );
cr.close();
return;
int closness = dist( cx, cz, x, minz );
if ( closness < closest )
{
closest = closness;
chosen_x = x;
chosen_z = minz;
}
}
if ( cr.hasBeacon( x, maxz ) )
{
req.callback.calculatedDirection( true, false, rad( cx, cz, x, maxz ) );
cr.close();
return;
int closness = dist( cx, cz, x, maxz );
if ( closness < closest )
{
closest = closness;
chosen_x = x;
chosen_z = maxz;
}
}
}
// didn't find shit...
req.callback.calculatedDirection( false, true, -999 );
if ( closest < Integer.MAX_VALUE )
{
req.callback.calculatedDirection( true, false, rad( cx, cz, chosen_x, chosen_z ), dist( cx, cz, chosen_x, chosen_z ) );
if ( !overOberdened )
cr.close();
return;
}
}
// didn't find shit...
req.callback.calculatedDirection( false, true, -999, 999 );
if ( !overOberdened )
cr.close();
}
private int dist(int ax, int az, int bx, int bz)
{
int up = (bz - az) * 16;
int side = (bx - ax) * 16;
return up * up + side * side;
}
private double rad(int ax, int az, int bx, int bz)

View file

@ -16,6 +16,7 @@ public class CompassReader
{
for (CompassRegion r : regions.values())
r.close();
regions.clear();
}

View file

@ -1,8 +1,9 @@
package appeng.services.helpers;
import java.io.EOFException;
import java.io.File;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
public class CompassRegion
{
@ -18,6 +19,7 @@ public class CompassRegion
boolean hasFile = false;
final File rootFolder;
RandomAccessFile raf = null;
ByteBuffer buffer;
public void close()
{
@ -25,6 +27,7 @@ public class CompassRegion
{
if ( hasFile )
{
buffer = null;
raf.close();
raf = null;
hasFile = false;
@ -94,8 +97,9 @@ public class CompassRegion
{
try
{
raf.seek( cx + cz * 0x400 );
raf.writeByte( val );
buffer.put( cx + cz * 0x400, (byte) val );
// raf.seek( cx + cz * 0x400 );
// raf.writeByte( val );
}
catch (Throwable t)
{
@ -107,10 +111,11 @@ public class CompassRegion
{
try
{
raf.seek( cx + cz * 0x400 );
return raf.readByte();
return buffer.get( cx + cz * 0x400 );
// raf.seek( cx + cz * 0x400 );
// return raf.readByte();
}
catch (EOFException eof)
catch (IndexOutOfBoundsException outofBounds)
{
return 0;
}
@ -131,6 +136,8 @@ public class CompassRegion
try
{
raf = new RandomAccessFile( fName, "rw" );
FileChannel fc = raf.getChannel();
buffer = fc.map( FileChannel.MapMode.READ_WRITE, 0, 0x400 * 0x400 );// fc.size() );
hasFile = true;
}
catch (Throwable t)
@ -156,4 +163,5 @@ public class CompassRegion
return new File( folder + File.separatorChar + world + "_" + low_x + "_" + low_z + ".dat" );
}
}

View file

@ -10,6 +10,6 @@ public interface ICompassCallback
* @param spin
* @param radians
*/
public void calculatedDirection(boolean hasResult, boolean spin, double radians);
public void calculatedDirection(boolean hasResult, boolean spin, double radians, double dist);
}