More work!
This commit is contained in:
parent
86b6474f35
commit
3939000190
7 changed files with 241 additions and 15 deletions
|
@ -1,5 +1,6 @@
|
|||
package mekanism.client.gui;
|
||||
|
||||
public class GuiDigitalMinerConfig {
|
||||
public class GuiDigitalMinerConfig
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,145 @@
|
|||
package mekanism.common.inventory.container;
|
||||
|
||||
import mekanism.common.inventory.slot.SlotElectricChest;
|
||||
import mekanism.common.inventory.slot.SlotEnergy.SlotDischarge;
|
||||
import mekanism.common.tileentity.TileEntityDigitalMiner;
|
||||
import mekanism.common.util.ChargeUtils;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class ContainerDigitalMiner extends Container
|
||||
{
|
||||
private TileEntityDigitalMiner tileEntity;
|
||||
|
||||
public ContainerDigitalMiner(InventoryPlayer inventory, TileEntityDigitalMiner tentity, IInventory inv, boolean b)
|
||||
{
|
||||
tileEntity = tentity;
|
||||
|
||||
for(int slotY = 0; slotY < 6; slotY++)
|
||||
{
|
||||
for(int slotX = 0; slotX < 9; slotX++)
|
||||
{
|
||||
addSlotToContainer(new SlotElectricChest(getInv(), slotX + slotY * 9, 8 + slotX * 18, 26 + slotY * 18));
|
||||
}
|
||||
}
|
||||
|
||||
addSlotToContainer(new SlotDischarge(getInv(), 54, 180, 11));
|
||||
|
||||
int slotX;
|
||||
|
||||
for(slotX = 0; slotX < 3; ++slotX)
|
||||
{
|
||||
for(int slotY = 0; slotY < 9; ++slotY)
|
||||
{
|
||||
addSlotToContainer(new SlotElectricChest(inventory, slotY + slotX * 9 + 9, 8 + slotY * 18, 148 + slotX * 18));
|
||||
}
|
||||
}
|
||||
|
||||
for(slotX = 0; slotX < 9; ++slotX)
|
||||
{
|
||||
addSlotToContainer(new SlotElectricChest(inventory, slotX, 8 + slotX * 18, 206));
|
||||
}
|
||||
}
|
||||
|
||||
public IInventory getInv()
|
||||
{
|
||||
if(isBlock)
|
||||
{
|
||||
return tileEntity;
|
||||
}
|
||||
else {
|
||||
return itemInventory;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onContainerClosed(EntityPlayer entityplayer)
|
||||
{
|
||||
super.onContainerClosed(entityplayer);
|
||||
|
||||
if(isBlock)
|
||||
{
|
||||
tileEntity.closeChest();
|
||||
tileEntity.playersUsing.remove(entityplayer);
|
||||
}
|
||||
else {
|
||||
itemInventory.closeChest();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInteractWith(EntityPlayer entityplayer)
|
||||
{
|
||||
if(isBlock)
|
||||
{
|
||||
return tileEntity.isUseableByPlayer(entityplayer);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack transferStackInSlot(EntityPlayer player, int slotID)
|
||||
{
|
||||
ItemStack stack = null;
|
||||
Slot currentSlot = (Slot)inventorySlots.get(slotID);
|
||||
|
||||
if(currentSlot != null && currentSlot.getHasStack())
|
||||
{
|
||||
ItemStack slotStack = currentSlot.getStack();
|
||||
stack = slotStack.copy();
|
||||
|
||||
if(ChargeUtils.canBeDischarged(slotStack))
|
||||
{
|
||||
if(slotID != 54)
|
||||
{
|
||||
if(!mergeItemStack(slotStack, 54, 55, false))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else if(slotID == 54)
|
||||
{
|
||||
if(!mergeItemStack(slotStack, 55, inventorySlots.size(), true))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(slotID < 54)
|
||||
{
|
||||
if(!mergeItemStack(slotStack, 55, inventorySlots.size(), true))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else if(!mergeItemStack(slotStack, 0, 54, false))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
if(slotStack.stackSize == 0)
|
||||
{
|
||||
currentSlot.putStack((ItemStack)null);
|
||||
}
|
||||
else {
|
||||
currentSlot.onSlotChanged();
|
||||
}
|
||||
|
||||
if(slotStack.stackSize == stack.stackSize)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
currentSlot.onPickupFromSlot(player, slotStack);
|
||||
}
|
||||
|
||||
return stack;
|
||||
}
|
||||
}
|
|
@ -23,10 +23,12 @@ public class MItemStackFilter extends MinerFilter
|
|||
}
|
||||
|
||||
@Override
|
||||
public void write(NBTTagCompound nbtTags)
|
||||
public NBTTagCompound write(NBTTagCompound nbtTags)
|
||||
{
|
||||
nbtTags.setInteger("type", 0);
|
||||
itemType.writeToNBT(nbtTags);
|
||||
|
||||
return nbtTags;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -52,10 +52,12 @@ public class MOreDictFilter extends MinerFilter
|
|||
}
|
||||
|
||||
@Override
|
||||
public void write(NBTTagCompound nbtTags)
|
||||
public NBTTagCompound write(NBTTagCompound nbtTags)
|
||||
{
|
||||
nbtTags.setInteger("type", 1);
|
||||
nbtTags.setString("oreDictName", oreDictName);
|
||||
|
||||
return nbtTags;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -11,7 +11,7 @@ public abstract class MinerFilter
|
|||
{
|
||||
public abstract boolean canFilter(ItemStack itemStack);
|
||||
|
||||
public abstract void write(NBTTagCompound nbtTags);
|
||||
public abstract NBTTagCompound write(NBTTagCompound nbtTags);
|
||||
|
||||
protected abstract void read(NBTTagCompound nbtTags);
|
||||
|
||||
|
|
|
@ -1,10 +1,29 @@
|
|||
package mekanism.common.miner;
|
||||
|
||||
import mekanism.common.tileentity.TileEntityDigitalMiner;
|
||||
|
||||
public class ThreadMinerSearch extends Thread
|
||||
{
|
||||
public TileEntityDigitalMiner tileEntity;
|
||||
|
||||
public boolean finished = false;
|
||||
|
||||
public ThreadMinerSearch(TileEntityDigitalMiner tile)
|
||||
{
|
||||
tileEntity = tile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
|
||||
if(tileEntity.isInvalid())
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public void reset()
|
||||
{
|
||||
finished = false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ import mekanism.common.miner.ThreadMinerSearch;
|
|||
import mekanism.common.network.PacketTileEntity;
|
||||
import mekanism.common.util.ChargeUtils;
|
||||
import mekanism.common.util.MekanismUtils;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
|
@ -35,6 +36,8 @@ public class TileEntityDigitalMiner extends TileEntityElectricBlock implements I
|
|||
|
||||
public HashList<MinerFilter> filters = new HashList<MinerFilter>();
|
||||
|
||||
public ThreadMinerSearch searcher = new ThreadMinerSearch(this);
|
||||
|
||||
public int radius;
|
||||
|
||||
public int minY;
|
||||
|
@ -42,8 +45,6 @@ public class TileEntityDigitalMiner extends TileEntityElectricBlock implements I
|
|||
|
||||
public boolean doEject = false;
|
||||
public boolean doPull = false;
|
||||
|
||||
public ThreadMinerSearch searcher;
|
||||
|
||||
public int clientToMine;
|
||||
|
||||
|
@ -67,6 +68,14 @@ public class TileEntityDigitalMiner extends TileEntityElectricBlock implements I
|
|||
if(!worldObj.isRemote)
|
||||
{
|
||||
ChargeUtils.discharge(27, this);
|
||||
|
||||
if(playersUsing.size() > 0)
|
||||
{
|
||||
for(EntityPlayer player : playersUsing)
|
||||
{
|
||||
PacketHandler.sendPacket(Transmission.SINGLE_CLIENT, new PacketTileEntity().setParams(Object3D.get(this), getGenericPacket(new ArrayList())), player);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -91,6 +100,16 @@ public class TileEntityDigitalMiner extends TileEntityElectricBlock implements I
|
|||
filters.add(MinerFilter.readFromNBT((NBTTagCompound)tagList.tagAt(i)));
|
||||
}
|
||||
}
|
||||
|
||||
if(nbtTags.hasKey("oresToMine"))
|
||||
{
|
||||
NBTTagList tagList = nbtTags.getTagList("oresToMine");
|
||||
|
||||
for(int i = 0; i < tagList.tagCount(); i++)
|
||||
{
|
||||
oresToMine.add(Object3D.read((NBTTagCompound)tagList.tagAt(i)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -109,9 +128,7 @@ public class TileEntityDigitalMiner extends TileEntityElectricBlock implements I
|
|||
|
||||
for(MinerFilter filter : filters)
|
||||
{
|
||||
NBTTagCompound tagCompound = new NBTTagCompound();
|
||||
filter.write(new NBTTagCompound());
|
||||
filterTags.appendTag(tagCompound);
|
||||
filterTags.appendTag(filter.write(new NBTTagCompound()));
|
||||
}
|
||||
|
||||
if(filterTags.tagCount() != 0)
|
||||
|
@ -119,16 +136,16 @@ public class TileEntityDigitalMiner extends TileEntityElectricBlock implements I
|
|||
nbtTags.setTag("filters", filterTags);
|
||||
}
|
||||
|
||||
NBTTagList miningOres = new NBTTagList();
|
||||
NBTTagList miningOreTags = new NBTTagList();
|
||||
|
||||
for(Object3D obj : oresToMine)
|
||||
{
|
||||
miningOres.appendTag(obj.write(new NBTTagCompound()));
|
||||
miningOreTags.appendTag(obj.write(new NBTTagCompound()));
|
||||
}
|
||||
|
||||
if(miningOres.tagCount() != 0)
|
||||
if(miningOreTags.tagCount() != 0)
|
||||
{
|
||||
nbtTags.setTag("oresToMine", miningOres);
|
||||
nbtTags.setTag("oresToMine", miningOreTags);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -148,8 +165,27 @@ public class TileEntityDigitalMiner extends TileEntityElectricBlock implements I
|
|||
doPull = dataStream.readBoolean();
|
||||
clientToMine = dataStream.readInt();
|
||||
controlType = RedstoneControl.values()[dataStream.readInt()];
|
||||
|
||||
filters.clear();
|
||||
|
||||
int amount = dataStream.readInt();
|
||||
|
||||
for(int i = 0; i < amount; i++)
|
||||
{
|
||||
filters.add(MinerFilter.readFromPacket(dataStream));
|
||||
}
|
||||
}
|
||||
else if(type == 1)
|
||||
{
|
||||
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 == 2)
|
||||
{
|
||||
filters.clear();
|
||||
|
||||
|
@ -188,11 +224,32 @@ public class TileEntityDigitalMiner extends TileEntityElectricBlock implements I
|
|||
}
|
||||
}
|
||||
|
||||
public ArrayList getFilterPacket(ArrayList data)
|
||||
public ArrayList getGenericPacket(ArrayList data)
|
||||
{
|
||||
super.getNetworkedData(data);
|
||||
|
||||
data.add(1);
|
||||
data.add(radius);
|
||||
data.add(minY);
|
||||
data.add(maxY);
|
||||
data.add(doEject);
|
||||
data.add(doPull);
|
||||
data.add(oresToMine.size());
|
||||
data.add(controlType.ordinal());
|
||||
|
||||
for(MinerFilter filter : filters)
|
||||
{
|
||||
filter.write(data);
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
public ArrayList getFilterPacket(ArrayList data)
|
||||
{
|
||||
super.getNetworkedData(data);
|
||||
|
||||
data.add(2);
|
||||
|
||||
data.add(filters.size());
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue