diff --git a/common/mekanism/client/gui/GuiMItemStackFilter.java b/common/mekanism/client/gui/GuiMItemStackFilter.java index bb808f4bd..61c21528b 100644 --- a/common/mekanism/client/gui/GuiMItemStackFilter.java +++ b/common/mekanism/client/gui/GuiMItemStackFilter.java @@ -148,7 +148,7 @@ public class GuiMItemStackFilter extends GuiMekanism { super.drawGuiContainerBackgroundLayer(partialTick, mouseX, mouseY); - mc.renderEngine.bindTexture(MekanismUtils.getResource(ResourceType.GUI, "GuiItemStackFilter.png")); + mc.renderEngine.bindTexture(MekanismUtils.getResource(ResourceType.GUI, "GuiMItemStackFilter.png")); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); int guiWidth = (width - xSize) / 2; int guiHeight = (height - ySize) / 2; diff --git a/common/mekanism/client/gui/GuiMOreDictFilter.java b/common/mekanism/client/gui/GuiMOreDictFilter.java index 858f89630..10fb2d859 100644 --- a/common/mekanism/client/gui/GuiMOreDictFilter.java +++ b/common/mekanism/client/gui/GuiMOreDictFilter.java @@ -174,7 +174,7 @@ public class GuiMOreDictFilter extends GuiMekanism { super.drawGuiContainerBackgroundLayer(partialTick, mouseX, mouseY); - mc.renderEngine.bindTexture(MekanismUtils.getResource(ResourceType.GUI, "GuiOreDictFilter.png")); + mc.renderEngine.bindTexture(MekanismUtils.getResource(ResourceType.GUI, "GuiMOreDictFilter.png")); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); int guiWidth = (width - xSize) / 2; int guiHeight = (height - ySize) / 2; diff --git a/common/mekanism/client/gui/GuiTItemStackFilter.java b/common/mekanism/client/gui/GuiTItemStackFilter.java index 210ff60a7..80f485291 100644 --- a/common/mekanism/client/gui/GuiTItemStackFilter.java +++ b/common/mekanism/client/gui/GuiTItemStackFilter.java @@ -233,7 +233,7 @@ public class GuiTItemStackFilter extends GuiMekanism { super.drawGuiContainerBackgroundLayer(partialTick, mouseX, mouseY); - mc.renderEngine.bindTexture(MekanismUtils.getResource(ResourceType.GUI, "GuiItemStackFilter.png")); + mc.renderEngine.bindTexture(MekanismUtils.getResource(ResourceType.GUI, "GuiTItemStackFilter.png")); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); int guiWidth = (width - xSize) / 2; int guiHeight = (height - ySize) / 2; diff --git a/common/mekanism/client/gui/GuiTOreDictFilter.java b/common/mekanism/client/gui/GuiTOreDictFilter.java index 0e5246ec0..6735ff425 100644 --- a/common/mekanism/client/gui/GuiTOreDictFilter.java +++ b/common/mekanism/client/gui/GuiTOreDictFilter.java @@ -203,7 +203,7 @@ public class GuiTOreDictFilter extends GuiMekanism { super.drawGuiContainerBackgroundLayer(partialTick, mouseX, mouseY); - mc.renderEngine.bindTexture(MekanismUtils.getResource(ResourceType.GUI, "GuiOreDictFilter.png")); + mc.renderEngine.bindTexture(MekanismUtils.getResource(ResourceType.GUI, "GuiTOreDictFilter.png")); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); int guiWidth = (width - xSize) / 2; int guiHeight = (height - ySize) / 2; diff --git a/common/mekanism/common/miner/ThreadMinerSearch.java b/common/mekanism/common/miner/ThreadMinerSearch.java index c8113c113..531fd3700 100644 --- a/common/mekanism/common/miner/ThreadMinerSearch.java +++ b/common/mekanism/common/miner/ThreadMinerSearch.java @@ -27,8 +27,6 @@ public class ThreadMinerSearch extends Thread 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++) @@ -55,8 +53,6 @@ public class ThreadMinerSearch extends Thread } } } - - count++; } } } diff --git a/common/mekanism/common/tileentity/TileEntityDigitalMiner.java b/common/mekanism/common/tileentity/TileEntityDigitalMiner.java index 6ac2503a0..690356677 100644 --- a/common/mekanism/common/tileentity/TileEntityDigitalMiner.java +++ b/common/mekanism/common/tileentity/TileEntityDigitalMiner.java @@ -3,7 +3,9 @@ package mekanism.common.tileentity; import ic2.api.energy.tile.IEnergySink; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashSet; +import java.util.List; import java.util.Set; import mekanism.api.Object3D; @@ -25,6 +27,7 @@ import mekanism.common.miner.ThreadMinerSearch.State; import mekanism.common.network.PacketTileEntity; import mekanism.common.util.ChargeUtils; import mekanism.common.util.MekanismUtils; +import mekanism.common.util.MinerUtils; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -42,6 +45,8 @@ public class TileEntityDigitalMiner extends TileEntityElectricBlock implements I public ThreadMinerSearch searcher = new ThreadMinerSearch(this); + public final double ENERGY_USAGE = 50; + public int radius; public int minY = 0; @@ -50,6 +55,8 @@ public class TileEntityDigitalMiner extends TileEntityElectricBlock implements I public boolean doEject = false; public boolean doPull = false; + public int delay; + public int clientToMine; public ItemStack replaceStack; @@ -91,6 +98,57 @@ public class TileEntityDigitalMiner extends TileEntityElectricBlock implements I { ChargeUtils.discharge(27, this); + if(running && getEnergy() >= MekanismUtils.getEnergy(getSpeedMultiplier(), ENERGY_USAGE) && searcher.state == State.FINISHED && oresToMine.size() > 0) + { + if(delay > 0) + { + delay--; + } + + //setEnergy(getEnergy()-MekanismUtils.getEnergy(getSpeedMultiplier(), ENERGY_USAGE)); + + if(delay == 0) + { + Set toRemove = new HashSet(); + + for(Object3D obj : oresToMine) + { + int id = obj.getBlockId(worldObj); + int meta = obj.getMetadata(worldObj); + + if(id == 0) + { + toRemove.add(obj); + continue; + } + + boolean hasFilter = false; + + for(MinerFilter filter : filters) + { + if(filter.canFilter(new ItemStack(id, 1, meta))) + { + hasFilter = true; + break; + } + } + + if(!hasFilter) + { + toRemove.add(obj); + continue; + } + + List drops = MinerUtils.getStacksFromBlock(worldObj, obj); + + if(drops.isEmpty() || canInsert(drops)) + { + + } + } + } + } + if(playersUsing.size() > 0) { for(EntityPlayer player : playersUsing) @@ -101,6 +159,81 @@ public class TileEntityDigitalMiner extends TileEntityElectricBlock implements I } } + public int getDelay() + { + return 9-getSpeedMultiplier(); + } + + public void setReplace(Object3D obj) + { + if(replaceStack != null) + { + worldObj.setBlock(obj.xCoord, obj.yCoord, obj.zCoord, replaceStack.itemID, replaceStack.getItemDamage(), 3); + } + else { + worldObj.setBlockToAir(obj.xCoord, obj.yCoord, obj.zCoord); + } + } + + public boolean canInsert(List stacks) + { + ItemStack[] testInv = Arrays.copyOf(inventory, inventory.length); + + int added = 0; + + stacks: + for(ItemStack stack : stacks) + { + for(int i = 0; i < 27; i++) + { + if(testInv[i] == null) + { + testInv[i] = stack; + added++; + + continue stacks; + } + else if(testInv[i].isItemEqual(stack) && testInv[i].stackSize+stack.stackSize <= stack.getMaxStackSize()) + { + testInv[i].stackSize += stack.stackSize; + added++; + + continue stacks; + } + } + } + + if(added == stacks.size()) + { + return true; + } + + return false; + } + + public void add(List stacks) + { + stacks: + for(ItemStack stack : stacks) + { + for(int i = 0; i < 27; i++) + { + if(inventory[i] == null) + { + inventory[i] = stack; + + continue stacks; + } + else if(inventory[i].isItemEqual(stack) && inventory[i].stackSize+stack.stackSize <= stack.getMaxStackSize()) + { + inventory[i].stackSize += stack.stackSize; + + continue stacks; + } + } + } + } + public void start() { if(searcher.state == State.IDLE) @@ -151,6 +284,7 @@ public class TileEntityDigitalMiner extends TileEntityElectricBlock implements I doPull = nbtTags.getBoolean("doPull"); isActive = nbtTags.getBoolean("isActive"); running = nbtTags.getBoolean("running"); + delay = nbtTags.getInteger("delay"); searcher.state = State.values()[nbtTags.getInteger("state")]; controlType = RedstoneControl.values()[nbtTags.getInteger("controlType")]; @@ -197,6 +331,7 @@ public class TileEntityDigitalMiner extends TileEntityElectricBlock implements I nbtTags.setBoolean("doPull", doPull); nbtTags.setBoolean("isActive", isActive); nbtTags.setBoolean("running", running); + nbtTags.setInteger("delay", delay); nbtTags.setInteger("state", searcher.state.ordinal()); nbtTags.setInteger("controlType", controlType.ordinal()); diff --git a/common/mekanism/common/tileentity/TileEntityElectricBlock.java b/common/mekanism/common/tileentity/TileEntityElectricBlock.java index 36c4106b8..36108723d 100644 --- a/common/mekanism/common/tileentity/TileEntityElectricBlock.java +++ b/common/mekanism/common/tileentity/TileEntityElectricBlock.java @@ -292,7 +292,7 @@ public abstract class TileEntityElectricBlock extends TileEntityContainerBlock i setEnergy(getEnergy() + toAdd); } - return (int)(toAdd*Mekanism.TO_TE); + return (int)Math.round(toAdd*Mekanism.TO_TE); } return 0; @@ -310,7 +310,7 @@ public abstract class TileEntityElectricBlock extends TileEntityContainerBlock i setEnergy(getEnergy() - toSend); } - return (int)(toSend*Mekanism.TO_TE); + return (int)Math.round(toSend*Mekanism.TO_TE); } return 0; diff --git a/common/mekanism/common/util/MinerUtils.java b/common/mekanism/common/util/MinerUtils.java new file mode 100644 index 000000000..1f540f870 --- /dev/null +++ b/common/mekanism/common/util/MinerUtils.java @@ -0,0 +1,32 @@ +package mekanism.common.util; + +import java.util.ArrayList; +import java.util.List; + +import mekanism.api.Object3D; +import net.minecraft.block.Block; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; +import net.minecraftforge.event.ForgeEventFactory; + +public final class MinerUtils +{ + public static List getStacksFromBlock(World world, Object3D obj) + { + Block block = Block.blocksList[obj.getBlockId(world)]; + + if(block == null) + { + return new ArrayList(); + } + + if(block.isAirBlock(world, obj.xCoord, obj.yCoord, obj.zCoord)) + { + return new ArrayList(); + } + + int meta = obj.getMetadata(world); + + return block.getBlockDropped(world, obj.xCoord, obj.yCoord, obj.zCoord, meta, 0); + } +} diff --git a/resources/assets/mekanism/gui/GuiMItemStackFilter.png b/resources/assets/mekanism/gui/GuiMItemStackFilter.png new file mode 100644 index 000000000..e4d63e0e4 Binary files /dev/null and b/resources/assets/mekanism/gui/GuiMItemStackFilter.png differ diff --git a/resources/assets/mekanism/gui/GuiMOreDictFilter.png b/resources/assets/mekanism/gui/GuiMOreDictFilter.png new file mode 100644 index 000000000..e0c39c598 Binary files /dev/null and b/resources/assets/mekanism/gui/GuiMOreDictFilter.png differ diff --git a/resources/assets/mekanism/gui/GuiItemStackFilter.png b/resources/assets/mekanism/gui/GuiTItemStackFilter.png similarity index 100% rename from resources/assets/mekanism/gui/GuiItemStackFilter.png rename to resources/assets/mekanism/gui/GuiTItemStackFilter.png diff --git a/resources/assets/mekanism/gui/GuiOreDictFilter.png b/resources/assets/mekanism/gui/GuiTOreDictFilter.png similarity index 100% rename from resources/assets/mekanism/gui/GuiOreDictFilter.png rename to resources/assets/mekanism/gui/GuiTOreDictFilter.png