Some work on algorithm

This commit is contained in:
Aidan C. Brady 2013-11-20 16:12:54 -05:00
parent 7b3edc142e
commit 789c5dbf45
3 changed files with 63 additions and 5 deletions

View file

@ -292,9 +292,9 @@ public class GuiDigitalMinerConfig extends GuiMekanism
fontRenderer.drawString("Radi: " + tileEntity.radius, 11, 58, 0x00CD00);
fontRenderer.drawString("MinY: " + tileEntity.minY, 11, 83, 0x00CD00);
fontRenderer.drawString("Min: " + tileEntity.minY, 11, 83, 0x00CD00);
fontRenderer.drawString("MaxY: " + tileEntity.maxY, 11, 108, 0x00CD00);
fontRenderer.drawString("Max: " + tileEntity.maxY, 11, 108, 0x00CD00);
for(int i = 0; i < 4; i++)
{
@ -453,7 +453,7 @@ public class GuiDigitalMinerConfig extends GuiMekanism
{
if(!radiusField.getText().isEmpty())
{
int toUse = Math.max(0, Math.min(Integer.parseInt(radiusField.getText()), 99));
int toUse = Math.max(0, Math.min(Integer.parseInt(radiusField.getText()), 32));
ArrayList data = new ArrayList();
data.add(6);

View file

@ -1,6 +1,9 @@
package mekanism.common.miner;
import mekanism.api.Object3D;
import mekanism.common.tileentity.TileEntityDigitalMiner;
import mekanism.common.util.MekanismUtils;
import net.minecraft.item.ItemStack;
public class ThreadMinerSearch extends Thread
{
@ -18,12 +21,48 @@ public class ThreadMinerSearch extends Thread
{
state = State.SEARCHING;
if(tileEntity.isInvalid())
if(tileEntity.filters.isEmpty())
{
state = State.FINISHED;
return;
}
int count = 0;
for(int y = tileEntity.maxY; y >= tileEntity.minY; y--)
{
for(int x = tileEntity.xCoord-tileEntity.radius; x <= tileEntity.xCoord+tileEntity.radius; x++)
{
for(int z = tileEntity.zCoord-tileEntity.radius; z <= tileEntity.zCoord+tileEntity.radius; z++)
{
if(tileEntity.isInvalid())
{
return;
}
int blockID = tileEntity.worldObj.getBlockId(x, y, z);
int meta = tileEntity.worldObj.getBlockMetadata(x, y, z);
if(blockID != 0)
{
ItemStack stack = new ItemStack(blockID, 1, meta);
for(MinerFilter filter : tileEntity.filters)
{
if(filter.canFilter(stack))
{
tileEntity.oresToMine.add(new Object3D(x, y, z));
}
}
}
count++;
}
}
}
state = State.FINISHED;
MekanismUtils.saveChunk(tileEntity);
}
public void reset()
@ -35,6 +74,7 @@ public class ThreadMinerSearch extends Thread
{
IDLE("Not ready"),
SEARCHING("Searching"),
PAUSED("Paused"),
FINISHED("Ready");
public String desc;

View file

@ -109,14 +109,25 @@ public class TileEntityDigitalMiner extends TileEntityElectricBlock implements I
}
running = true;
MekanismUtils.saveChunk(this);
}
public void stop()
{
if(searcher.state == State.FINISHED)
if(searcher.state == State.SEARCHING)
{
searcher.interrupt();
reset();
return;
}
else if(searcher.state == State.FINISHED)
{
running = false;
}
MekanismUtils.saveChunk(this);
}
public void reset()
@ -124,6 +135,8 @@ public class TileEntityDigitalMiner extends TileEntityElectricBlock implements I
searcher = new ThreadMinerSearch(this);
running = false;
oresToMine.clear();
MekanismUtils.saveChunk(this);
}
@Override
@ -172,6 +185,11 @@ public class TileEntityDigitalMiner extends TileEntityElectricBlock implements I
{
super.writeToNBT(nbtTags);
if(searcher.state == State.SEARCHING)
{
reset();
}
nbtTags.setInteger("radius", radius);
nbtTags.setInteger("minY", minY);
nbtTags.setInteger("maxY", maxY);