Beginning foundations of Digital Miner.

This commit is contained in:
Aidan C. Brady 2013-11-19 12:13:37 -05:00
parent ba66b6fc9f
commit 86b6474f35
17 changed files with 441 additions and 50 deletions

View file

@ -0,0 +1,5 @@
package mekanism.client.gui;
public class GuiDigitalMiner {
}

View file

@ -0,0 +1,5 @@
package mekanism.client.gui;
public class GuiDigitalMinerConfig {
}

View file

@ -11,7 +11,7 @@ import mekanism.common.network.PacketLogisticalSorterGui;
import mekanism.common.network.PacketLogisticalSorterGui.SorterGuiPacket;
import mekanism.common.network.PacketNewFilter;
import mekanism.common.tileentity.TileEntityLogisticalSorter;
import mekanism.common.transporter.ItemStackFilter;
import mekanism.common.transporter.TItemStackFilter;
import mekanism.common.util.MekanismUtils;
import mekanism.common.util.MekanismUtils.ResourceType;
import mekanism.common.util.TransporterUtils;
@ -30,9 +30,9 @@ public class GuiItemStackFilter extends GuiMekanism
public boolean isNew = false;
public ItemStackFilter origFilter;
public TItemStackFilter origFilter;
public ItemStackFilter filter = new ItemStackFilter();
public TItemStackFilter filter = new TItemStackFilter();
public String status = EnumColor.DARK_GREEN + "All OK";
@ -46,8 +46,8 @@ public class GuiItemStackFilter extends GuiMekanism
super(new ContainerFilter(player.inventory));
tileEntity = tentity;
origFilter = (ItemStackFilter)tileEntity.filters.get(index);
filter = ((ItemStackFilter)tileEntity.filters.get(index)).clone();
origFilter = (TItemStackFilter)tileEntity.filters.get(index);
filter = ((TItemStackFilter)tileEntity.filters.get(index)).clone();
}
public GuiItemStackFilter(EntityPlayer player, TileEntityLogisticalSorter tentity)

View file

@ -16,8 +16,8 @@ import mekanism.common.network.PacketLogisticalSorterGui;
import mekanism.common.network.PacketLogisticalSorterGui.SorterGuiPacket;
import mekanism.common.network.PacketTileEntity;
import mekanism.common.tileentity.TileEntityLogisticalSorter;
import mekanism.common.transporter.ItemStackFilter;
import mekanism.common.transporter.OreDictFilter;
import mekanism.common.transporter.TItemStackFilter;
import mekanism.common.transporter.TOreDictFilter;
import mekanism.common.transporter.TransporterFilter;
import mekanism.common.util.MekanismUtils;
import mekanism.common.util.MekanismUtils.ResourceType;
@ -43,7 +43,7 @@ public class GuiLogisticalSorter extends GuiMekanism
public int stackSwitch = 0;
public Map<OreDictFilter, StackData> oreDictStacks = new HashMap<OreDictFilter, StackData>();
public Map<TOreDictFilter, StackData> oreDictStacks = new HashMap<TOreDictFilter, StackData>();
public float scroll;
@ -81,7 +81,7 @@ public class GuiLogisticalSorter extends GuiMekanism
if(stackSwitch == 0)
{
for(Map.Entry<OreDictFilter, StackData> entry : oreDictStacks.entrySet())
for(Map.Entry<TOreDictFilter, StackData> entry : oreDictStacks.entrySet())
{
if(entry.getValue().iterStacks != null && entry.getValue().iterStacks.size() > 0)
{
@ -101,7 +101,7 @@ public class GuiLogisticalSorter extends GuiMekanism
stackSwitch = 20;
}
else {
for(Map.Entry<OreDictFilter, StackData> entry : oreDictStacks.entrySet())
for(Map.Entry<TOreDictFilter, StackData> entry : oreDictStacks.entrySet())
{
if(entry.getValue().iterStacks != null && entry.getValue().iterStacks.size() == 0)
{
@ -110,19 +110,19 @@ public class GuiLogisticalSorter extends GuiMekanism
}
}
Set<OreDictFilter> filtersVisible = new HashSet<OreDictFilter>();
Set<TOreDictFilter> filtersVisible = new HashSet<TOreDictFilter>();
for(int i = 0; i < 4; i++)
{
if(tileEntity.filters.get(getFilterIndex()+i) instanceof OreDictFilter)
if(tileEntity.filters.get(getFilterIndex()+i) instanceof TOreDictFilter)
{
filtersVisible.add((OreDictFilter)tileEntity.filters.get(getFilterIndex()+i));
filtersVisible.add((TOreDictFilter)tileEntity.filters.get(getFilterIndex()+i));
}
}
for(TransporterFilter filter : tileEntity.filters)
{
if(filter instanceof OreDictFilter && !filtersVisible.contains(filter))
if(filter instanceof TOreDictFilter && !filtersVisible.contains(filter))
{
if(oreDictStacks.containsKey(filter))
{
@ -158,12 +158,12 @@ public class GuiLogisticalSorter extends GuiMekanism
{
TransporterFilter filter = tileEntity.filters.get(getFilterIndex()+i);
if(filter instanceof ItemStackFilter)
if(filter instanceof TItemStackFilter)
{
mc.sndManager.playSoundFX("random.click", 1.0F, 1.0F);
PacketHandler.sendPacket(Transmission.SERVER, new PacketLogisticalSorterGui().setParams(SorterGuiPacket.SERVER_INDEX, Object3D.get(tileEntity), 1, getFilterIndex()+i));
}
else if(filter instanceof OreDictFilter)
else if(filter instanceof TOreDictFilter)
{
mc.sndManager.playSoundFX("random.click", 1.0F, 1.0F);
PacketHandler.sendPacket(Transmission.SERVER, new PacketLogisticalSorterGui().setParams(SorterGuiPacket.SERVER_INDEX, Object3D.get(tileEntity), 2, getFilterIndex()+i));
@ -283,9 +283,9 @@ public class GuiLogisticalSorter extends GuiMekanism
TransporterFilter filter = tileEntity.filters.get(getFilterIndex()+i);
int yStart = i*29 + 18;
if(filter instanceof ItemStackFilter)
if(filter instanceof TItemStackFilter)
{
ItemStackFilter itemFilter = (ItemStackFilter)filter;
TItemStackFilter itemFilter = (TItemStackFilter)filter;
if(itemFilter.itemType != null)
{
@ -299,9 +299,9 @@ public class GuiLogisticalSorter extends GuiMekanism
fontRenderer.drawString("Item Filter", 78, yStart + 2, 0x404040);
fontRenderer.drawString(filter.color != null ? filter.color.getName() : "None", 78, yStart + 11, 0x404040);
}
else if(filter instanceof OreDictFilter)
else if(filter instanceof TOreDictFilter)
{
OreDictFilter oreFilter = (OreDictFilter)filter;
TOreDictFilter oreFilter = (TOreDictFilter)filter;
if(!oreDictStacks.containsKey(oreFilter))
{
@ -386,11 +386,11 @@ public class GuiLogisticalSorter extends GuiMekanism
boolean mouseOver = xAxis >= 56 && xAxis <= 152 && yAxis >= yStart && yAxis <= yStart+29;
if(filter instanceof ItemStackFilter)
if(filter instanceof TItemStackFilter)
{
drawTexturedModalRect(guiWidth + 56, guiHeight + yStart, mouseOver ? 0 : 96, 166, 96, 29);
}
else if(filter instanceof OreDictFilter)
else if(filter instanceof TOreDictFilter)
{
drawTexturedModalRect(guiWidth + 56, guiHeight + yStart, mouseOver ? 0 : 96, 195, 96, 29);
}
@ -420,7 +420,7 @@ public class GuiLogisticalSorter extends GuiMekanism
for(TransporterFilter filter : tileEntity.filters)
{
if(filter instanceof ItemStackFilter)
if(filter instanceof TItemStackFilter)
{
list.add(filter);
}
@ -435,7 +435,7 @@ public class GuiLogisticalSorter extends GuiMekanism
for(TransporterFilter filter : tileEntity.filters)
{
if(filter instanceof OreDictFilter)
if(filter instanceof TOreDictFilter)
{
list.add(filter);
}
@ -444,7 +444,7 @@ public class GuiLogisticalSorter extends GuiMekanism
return list;
}
private void updateStackList(OreDictFilter filter)
private void updateStackList(TOreDictFilter filter)
{
if(!oreDictStacks.containsKey(filter))
{

View file

@ -15,8 +15,8 @@ import mekanism.common.network.PacketLogisticalSorterGui;
import mekanism.common.network.PacketLogisticalSorterGui.SorterGuiPacket;
import mekanism.common.network.PacketNewFilter;
import mekanism.common.tileentity.TileEntityLogisticalSorter;
import mekanism.common.transporter.ItemStackFilter;
import mekanism.common.transporter.OreDictFilter;
import mekanism.common.transporter.TItemStackFilter;
import mekanism.common.transporter.TOreDictFilter;
import mekanism.common.util.MekanismUtils;
import mekanism.common.util.MekanismUtils.ResourceType;
import mekanism.common.util.TransporterUtils;
@ -36,9 +36,9 @@ public class GuiOreDictFilter extends GuiMekanism
public boolean isNew = false;
public OreDictFilter origFilter;
public TOreDictFilter origFilter;
public OreDictFilter filter = new OreDictFilter();
public TOreDictFilter filter = new TOreDictFilter();
private GuiTextField oreDictText;
@ -59,8 +59,8 @@ public class GuiOreDictFilter extends GuiMekanism
super(new ContainerFilter(player.inventory));
tileEntity = tentity;
origFilter = (OreDictFilter)tileEntity.filters.get(index);
filter = ((OreDictFilter)tentity.filters.get(index)).clone();
origFilter = (TOreDictFilter)tileEntity.filters.get(index);
filter = ((TOreDictFilter)tentity.filters.get(index)).clone();
updateStackList(filter.oreDictName);
}

View file

@ -0,0 +1,79 @@
package mekanism.common.miner;
import java.util.ArrayList;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import com.google.common.io.ByteArrayDataInput;
public class MItemStackFilter extends MinerFilter
{
public ItemStack itemType;
@Override
public boolean canFilter(ItemStack itemStack)
{
if(itemStack == null)
{
return false;
}
return itemType.isItemEqual(itemStack);
}
@Override
public void write(NBTTagCompound nbtTags)
{
nbtTags.setInteger("type", 0);
itemType.writeToNBT(nbtTags);
}
@Override
protected void read(NBTTagCompound nbtTags)
{
itemType = ItemStack.loadItemStackFromNBT(nbtTags);
}
@Override
public void write(ArrayList data)
{
data.add(0);
data.add(itemType.itemID);
data.add(itemType.stackSize);
data.add(itemType.getItemDamage());
}
@Override
protected void read(ByteArrayDataInput dataStream)
{
itemType = new ItemStack(dataStream.readInt(), dataStream.readInt(), dataStream.readInt());
}
@Override
public int hashCode()
{
int code = 1;
code = 31 * code + super.hashCode();
code = 31 * code + itemType.itemID;
code = 31 * code + itemType.stackSize;
code = 31 * code + itemType.getItemDamage();
return code;
}
@Override
public boolean equals(Object filter)
{
return super.equals(filter) && filter instanceof MItemStackFilter && ((MItemStackFilter)filter).itemType.isItemEqual(itemType);
}
@Override
public MItemStackFilter clone()
{
MItemStackFilter filter = new MItemStackFilter();
filter.itemType = itemType.copy();
return filter;
}
}

View file

@ -0,0 +1,103 @@
package mekanism.common.miner;
import java.util.ArrayList;
import mekanism.common.util.MekanismUtils;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import com.google.common.io.ByteArrayDataInput;
public class MOreDictFilter extends MinerFilter
{
public String oreDictName;
@Override
public boolean canFilter(ItemStack itemStack)
{
String oreKey = MekanismUtils.getOreDictName(itemStack);
if(oreKey == null)
{
return false;
}
if(oreDictName.equals(oreKey) || oreDictName.equals("*"))
{
return true;
}
else if(oreDictName.endsWith("*") && !oreDictName.startsWith("*"))
{
if(oreKey.startsWith(oreDictName.substring(0, oreDictName.length()-1)))
{
return true;
}
}
else if(oreDictName.startsWith("*") && !oreDictName.endsWith("*"))
{
if(oreKey.endsWith(oreDictName.substring(1)))
{
return true;
}
}
else if(oreDictName.startsWith("*") && oreDictName.endsWith("*"))
{
if(oreKey.contains(oreDictName.substring(1, oreDictName.length()-1)))
{
return true;
}
}
return false;
}
@Override
public void write(NBTTagCompound nbtTags)
{
nbtTags.setInteger("type", 1);
nbtTags.setString("oreDictName", oreDictName);
}
@Override
protected void read(NBTTagCompound nbtTags)
{
oreDictName = nbtTags.getString("oreDictName");
}
@Override
public void write(ArrayList data)
{
data.add(1);
data.add(oreDictName);
}
@Override
protected void read(ByteArrayDataInput dataStream)
{
oreDictName = dataStream.readUTF();
}
@Override
public int hashCode()
{
int code = 1;
code = 31 * code + super.hashCode();
code = 31 * code + oreDictName.hashCode();
return code;
}
@Override
public boolean equals(Object filter)
{
return super.equals(filter) && filter instanceof MOreDictFilter && ((MOreDictFilter)filter).oreDictName.equals(oreDictName);
}
@Override
public MOreDictFilter clone()
{
MOreDictFilter filter = new MOreDictFilter();
filter.oreDictName = oreDictName;
return filter;
}
}

View file

@ -0,0 +1,66 @@
package mekanism.common.miner;
import java.util.ArrayList;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import com.google.common.io.ByteArrayDataInput;
public abstract class MinerFilter
{
public abstract boolean canFilter(ItemStack itemStack);
public abstract void write(NBTTagCompound nbtTags);
protected abstract void read(NBTTagCompound nbtTags);
public abstract void write(ArrayList data);
protected abstract void read(ByteArrayDataInput dataStream);
public static MinerFilter readFromNBT(NBTTagCompound nbtTags)
{
int type = nbtTags.getInteger("type");
MinerFilter filter = null;
if(type == 0)
{
filter = new MItemStackFilter();
}
else {
filter = new MOreDictFilter();
}
filter.read(nbtTags);
return filter;
}
public static MinerFilter readFromPacket(ByteArrayDataInput dataStream)
{
int type = dataStream.readInt();
MinerFilter filter = null;
if(type == 0)
{
filter = new MItemStackFilter();
}
else if(type == 1)
{
filter = new MOreDictFilter();
}
filter.read(dataStream);
return filter;
}
@Override
public boolean equals(Object filter)
{
return filter instanceof MinerFilter;
}
}

View file

@ -0,0 +1,10 @@
package mekanism.common.miner;
public class ThreadMinerSearch extends Thread
{
@Override
public void run()
{
}
}

View file

@ -3,18 +3,27 @@ package mekanism.common.tileentity;
import ic2.api.energy.tile.IEnergySink;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
import mekanism.api.Object3D;
import mekanism.api.energy.IStrictEnergyAcceptor;
import mekanism.common.HashList;
import mekanism.common.IRedstoneControl;
import mekanism.common.IUpgradeTile;
import mekanism.common.Mekanism;
import mekanism.common.PacketHandler;
import mekanism.common.PacketHandler.Transmission;
import mekanism.common.TileComponentUpgrade;
import mekanism.common.block.BlockMachine.MachineType;
import mekanism.common.miner.MinerFilter;
import mekanism.common.miner.ThreadMinerSearch;
import mekanism.common.network.PacketTileEntity;
import mekanism.common.util.ChargeUtils;
import mekanism.common.util.MekanismUtils;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
@ -22,8 +31,22 @@ import com.google.common.io.ByteArrayDataInput;
public class TileEntityDigitalMiner extends TileEntityElectricBlock implements IEnergySink, IStrictEnergyAcceptor, IUpgradeTile, IRedstoneControl
{
public Set<Object3D> oresToMine = new HashSet<Object3D>();
public HashList<MinerFilter> filters = new HashList<MinerFilter>();
public int radius;
public int minY;
public int maxY;
public boolean doEject = false;
public boolean doPull = false;
public ThreadMinerSearch searcher;
public int clientToMine;
/** This machine's current RedstoneControl type. */
public RedstoneControl controlType = RedstoneControl.DISABLED;
@ -53,7 +76,21 @@ public class TileEntityDigitalMiner extends TileEntityElectricBlock implements I
super.readFromNBT(nbtTags);
radius = nbtTags.getInteger("radius");
minY = nbtTags.getInteger("minY");
maxY = nbtTags.getInteger("maxY");
doEject = nbtTags.getBoolean("doEject");
doPull = nbtTags.getBoolean("doPull");
controlType = RedstoneControl.values()[nbtTags.getInteger("controlType")];
if(nbtTags.hasKey("filters"))
{
NBTTagList tagList = nbtTags.getTagList("filters");
for(int i = 0; i < tagList.tagCount(); i++)
{
filters.add(MinerFilter.readFromNBT((NBTTagCompound)tagList.tagAt(i)));
}
}
}
@Override
@ -62,7 +99,37 @@ public class TileEntityDigitalMiner extends TileEntityElectricBlock implements I
super.writeToNBT(nbtTags);
nbtTags.setInteger("radius", radius);
nbtTags.setInteger("minY", minY);
nbtTags.setInteger("maxY", maxY);
nbtTags.setBoolean("doEject", doEject);
nbtTags.setBoolean("doPull", doPull);
nbtTags.setInteger("controlType", controlType.ordinal());
NBTTagList filterTags = new NBTTagList();
for(MinerFilter filter : filters)
{
NBTTagCompound tagCompound = new NBTTagCompound();
filter.write(new NBTTagCompound());
filterTags.appendTag(tagCompound);
}
if(filterTags.tagCount() != 0)
{
nbtTags.setTag("filters", filterTags);
}
NBTTagList miningOres = new NBTTagList();
for(Object3D obj : oresToMine)
{
miningOres.appendTag(obj.write(new NBTTagCompound()));
}
if(miningOres.tagCount() != 0)
{
nbtTags.setTag("oresToMine", miningOres);
}
}
@Override
@ -70,8 +137,29 @@ public class TileEntityDigitalMiner extends TileEntityElectricBlock implements I
{
super.handlePacketData(dataStream);
radius = dataStream.readInt();
controlType = RedstoneControl.values()[dataStream.readInt()];
int type = dataStream.readInt();
if(type == 0)
{
radius = dataStream.readInt();
minY = dataStream.readInt();
maxY = dataStream.readInt();
doEject = dataStream.readBoolean();
doPull = dataStream.readBoolean();
clientToMine = dataStream.readInt();
controlType = RedstoneControl.values()[dataStream.readInt()];
}
else if(type == 1)
{
filters.clear();
int amount = dataStream.readInt();
for(int i = 0; i < amount; i++)
{
filters.add(MinerFilter.readFromPacket(dataStream));
}
}
}
@Override
@ -79,11 +167,42 @@ public class TileEntityDigitalMiner extends TileEntityElectricBlock implements I
{
super.getNetworkedData(data);
data.add(0);
data.add(radius);
data.add(minY);
data.add(maxY);
data.add(doEject);
data.add(doPull);
data.add(oresToMine.size());
data.add(controlType.ordinal());
return data;
}
@Override
public void openChest()
{
if(!worldObj.isRemote)
{
PacketHandler.sendPacket(Transmission.CLIENTS_RANGE, new PacketTileEntity().setParams(Object3D.get(this), getFilterPacket(new ArrayList())), Object3D.get(this), 50D);
}
}
public ArrayList getFilterPacket(ArrayList data)
{
super.getNetworkedData(data);
data.add(1);
data.add(filters.size());
for(MinerFilter filter : filters)
{
filter.write(data);
}
return data;
}
@Override
public boolean acceptsEnergyFrom(TileEntity emitter, ForgeDirection direction)
@ -145,6 +264,12 @@ public class TileEntityDigitalMiner extends TileEntityElectricBlock implements I
return rejects;
}
@Override
public double getMaxEnergy()
{
return MekanismUtils.getEnergy(getEnergyMultiplier(), MAX_ELECTRICITY);
}
@Override
public boolean canReceiveEnergy(ForgeDirection side)
{

View file

@ -342,11 +342,9 @@ public class TileEntityElectricPump extends TileEntityElectricBlock implements I
NBTTagList cleaningList = new NBTTagList();
for(Object3D wrapper : cleaningNodes)
for(Object3D obj : cleaningNodes)
{
NBTTagCompound tagCompound = new NBTTagCompound();
wrapper.write(tagCompound);
cleaningList.appendTag(tagCompound);
cleaningList.appendTag(obj.write(new NBTTagCompound()));
}
if(cleaningList.tagCount() != 0)

View file

@ -10,7 +10,7 @@ import net.minecraftforge.common.ForgeDirection;
import com.google.common.io.ByteArrayDataInput;
public class ItemStackFilter extends TransporterFilter
public class TItemStackFilter extends TransporterFilter
{
public boolean sizeMode;
@ -116,14 +116,14 @@ public class ItemStackFilter extends TransporterFilter
@Override
public boolean equals(Object filter)
{
return super.equals(filter) && filter instanceof ItemStackFilter && ((ItemStackFilter)filter).itemType.isItemEqual(itemType)
&& ((ItemStackFilter)filter).sizeMode == sizeMode && ((ItemStackFilter)filter).min == min && ((ItemStackFilter)filter).max == max;
return super.equals(filter) && filter instanceof TItemStackFilter && ((TItemStackFilter)filter).itemType.isItemEqual(itemType)
&& ((TItemStackFilter)filter).sizeMode == sizeMode && ((TItemStackFilter)filter).min == min && ((TItemStackFilter)filter).max == max;
}
@Override
public ItemStackFilter clone()
public TItemStackFilter clone()
{
ItemStackFilter filter = new ItemStackFilter();
TItemStackFilter filter = new TItemStackFilter();
filter.color = color;
filter.itemType = itemType.copy();
filter.sizeMode = sizeMode;

View file

@ -11,7 +11,7 @@ import net.minecraftforge.common.ForgeDirection;
import com.google.common.io.ByteArrayDataInput;
public class OreDictFilter extends TransporterFilter
public class TOreDictFilter extends TransporterFilter
{
public String oreDictName;
@ -107,13 +107,13 @@ public class OreDictFilter extends TransporterFilter
@Override
public boolean equals(Object filter)
{
return super.equals(filter) && filter instanceof OreDictFilter && ((OreDictFilter)filter).oreDictName.equals(oreDictName);
return super.equals(filter) && filter instanceof TOreDictFilter && ((TOreDictFilter)filter).oreDictName.equals(oreDictName);
}
@Override
public OreDictFilter clone()
public TOreDictFilter clone()
{
OreDictFilter filter = new OreDictFilter();
TOreDictFilter filter = new TOreDictFilter();
filter.color = color;
filter.oreDictName = oreDictName;

View file

@ -67,10 +67,10 @@ public abstract class TransporterFilter
if(type == 0)
{
filter = new ItemStackFilter();
filter = new TItemStackFilter();
}
else {
filter = new OreDictFilter();
filter = new TOreDictFilter();
}
filter.read(nbtTags);
@ -86,11 +86,11 @@ public abstract class TransporterFilter
if(type == 0)
{
filter = new ItemStackFilter();
filter = new TItemStackFilter();
}
else if(type == 1)
{
filter = new OreDictFilter();
filter = new TOreDictFilter();
}
filter.read(dataStream);

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.4 KiB

After

Width:  |  Height:  |  Size: 5.3 KiB