Just disable wireless grid slot instead of closing GUI's
This commit is contained in:
@@ -2,17 +2,11 @@ package refinedstorage.api.network;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumHand;
|
||||
|
||||
/**
|
||||
* Represents a player using a wireless grid.
|
||||
*/
|
||||
public interface IWirelessGridConsumer {
|
||||
/**
|
||||
* @return The hand this wireless grid is opened with
|
||||
*/
|
||||
EnumHand getHand();
|
||||
|
||||
/**
|
||||
* @return The player using the wireless grid
|
||||
*/
|
||||
|
||||
@@ -2,25 +2,17 @@ package refinedstorage.apiimpl.network;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import refinedstorage.api.network.IWirelessGridConsumer;
|
||||
|
||||
public class WirelessGridConsumer implements IWirelessGridConsumer {
|
||||
private EntityPlayer player;
|
||||
private EnumHand hand;
|
||||
private ItemStack stack;
|
||||
|
||||
public WirelessGridConsumer(EntityPlayer player, EnumHand hand, ItemStack stack) {
|
||||
public WirelessGridConsumer(EntityPlayer player, ItemStack stack) {
|
||||
this.player = player;
|
||||
this.hand = hand;
|
||||
this.stack = stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumHand getHand() {
|
||||
return hand;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityPlayer getPlayer() {
|
||||
return player;
|
||||
|
||||
@@ -2,13 +2,11 @@ package refinedstorage.apiimpl.network;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import refinedstorage.RefinedStorage;
|
||||
import refinedstorage.RefinedStorageGui;
|
||||
import refinedstorage.RefinedStorageItems;
|
||||
import refinedstorage.api.network.*;
|
||||
import refinedstorage.api.storage.CompareUtils;
|
||||
import refinedstorage.item.ItemWirelessGrid;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -33,19 +31,6 @@ public class WirelessGridHandler implements IWirelessGridHandler {
|
||||
public void update() {
|
||||
consumers.removeAll(consumersToRemove);
|
||||
consumersToRemove.clear();
|
||||
|
||||
Iterator<IWirelessGridConsumer> it = consumers.iterator();
|
||||
|
||||
while (it.hasNext()) {
|
||||
IWirelessGridConsumer consumer = it.next();
|
||||
|
||||
if (!CompareUtils.compareStack(consumer.getStack(), consumer.getPlayer().getHeldItem(consumer.getHand()))) {
|
||||
/**
|
||||
* This will call {@link net.minecraft.inventory.Container#onContainerClosed(EntityPlayer)} so the consumer is removed from the list.
|
||||
*/
|
||||
consumer.getPlayer().closeScreen();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -70,7 +55,7 @@ public class WirelessGridHandler implements IWirelessGridHandler {
|
||||
return false;
|
||||
}
|
||||
|
||||
consumers.add(new WirelessGridConsumer(player, hand, player.getHeldItem(hand)));
|
||||
consumers.add(new WirelessGridConsumer(player, player.getHeldItem(hand)));
|
||||
|
||||
player.openGui(RefinedStorage.INSTANCE, RefinedStorageGui.WIRELESS_GRID, player.worldObj, hand.ordinal(), 0, 0);
|
||||
|
||||
@@ -96,13 +81,13 @@ public class WirelessGridHandler implements IWirelessGridHandler {
|
||||
|
||||
if (consumer != null) {
|
||||
ItemWirelessGrid item = RefinedStorageItems.WIRELESS_GRID;
|
||||
ItemStack held = consumer.getPlayer().getHeldItem(consumer.getHand());
|
||||
|
||||
if (held.getItemDamage() != ItemWirelessGrid.TYPE_CREATIVE) {
|
||||
item.extractEnergy(held, energy, false);
|
||||
if (consumer.getStack().getItemDamage() != ItemWirelessGrid.TYPE_CREATIVE) {
|
||||
item.extractEnergy(consumer.getStack(), energy, false);
|
||||
|
||||
if (item.getEnergyStored(held) <= 0) {
|
||||
if (item.getEnergyStored(consumer.getStack()) <= 0) {
|
||||
onClose(player);
|
||||
|
||||
consumer.getPlayer().closeScreen();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import refinedstorage.api.storage.CompareUtils;
|
||||
import refinedstorage.container.slot.SlotDisabled;
|
||||
import refinedstorage.container.slot.SlotSpecimen;
|
||||
import refinedstorage.container.slot.SlotSpecimenLegacy;
|
||||
import refinedstorage.tile.grid.WirelessGrid;
|
||||
|
||||
public abstract class ContainerBase extends Container {
|
||||
private EntityPlayer player;
|
||||
@@ -29,7 +30,7 @@ public abstract class ContainerBase extends Container {
|
||||
int x = xInventory + i * 18;
|
||||
int y = yInventory + 4 + (3 * 18);
|
||||
|
||||
if (ContainerBase.this instanceof ContainerGridFilter && i == ((ContainerGridFilter) ContainerBase.this).slot) {
|
||||
if (i == player.inventory.currentItem && (ContainerBase.this instanceof ContainerGridFilter || (ContainerBase.this instanceof ContainerGrid && ((ContainerGrid) ContainerBase.this).getGrid() instanceof WirelessGrid))) {
|
||||
addSlotToContainer(new SlotDisabled(player.inventory, id, x, y));
|
||||
} else {
|
||||
addSlotToContainer(new Slot(player.inventory, id, x, y));
|
||||
|
||||
@@ -7,21 +7,18 @@ import refinedstorage.container.slot.SlotSpecimen;
|
||||
import refinedstorage.inventory.GridFilterItemHandler;
|
||||
|
||||
public class ContainerGridFilter extends ContainerBase {
|
||||
private GridFilterItemHandler itemHandler;
|
||||
private GridFilterItemHandler filter;
|
||||
|
||||
protected int slot;
|
||||
|
||||
public ContainerGridFilter(EntityPlayer player, ItemStack gridFilter, int slot) {
|
||||
public ContainerGridFilter(EntityPlayer player, ItemStack stack) {
|
||||
super(player);
|
||||
|
||||
this.slot = slot;
|
||||
this.itemHandler = new GridFilterItemHandler(gridFilter);
|
||||
this.filter = new GridFilterItemHandler(stack);
|
||||
|
||||
int x = 8;
|
||||
int y = 20;
|
||||
|
||||
for (int i = 0; i < 9 * 3; ++i) {
|
||||
addSlotToContainer(new SlotSpecimen(itemHandler, i, x, y));
|
||||
addSlotToContainer(new SlotSpecimen(filter, i, x, y));
|
||||
|
||||
if ((i + 1) % 9 == 0) {
|
||||
y += 18;
|
||||
|
||||
@@ -66,26 +66,6 @@ public class GuiHandler implements IGuiHandler {
|
||||
return getContainer(ID, player, world.getTileEntity(new BlockPos(x, y, z)));
|
||||
}
|
||||
|
||||
private ContainerGridFilter getGridFilterContainer(EntityPlayer player, int hand) {
|
||||
return new ContainerGridFilter(player, player.getHeldItem(EnumHand.values()[hand]), player.inventory.currentItem);
|
||||
}
|
||||
|
||||
private WirelessGrid getWirelessGrid(EntityPlayer player, int hand) {
|
||||
return new WirelessGrid(player.worldObj, player.getHeldItem(EnumHand.values()[hand]), EnumHand.values()[hand]);
|
||||
}
|
||||
|
||||
private ContainerGrid getWirelessGridContainer(EntityPlayer player, int hand) {
|
||||
WirelessGrid wirelessGrid = getWirelessGrid(player, hand);
|
||||
|
||||
return new ContainerGrid(player, wirelessGrid);
|
||||
}
|
||||
|
||||
private GuiGrid getWirelessGridGui(EntityPlayer player, int hand) {
|
||||
WirelessGrid wirelessGrid = getWirelessGrid(player, hand);
|
||||
|
||||
return new GuiGrid(new ContainerGrid(player, wirelessGrid), wirelessGrid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
|
||||
TileEntity tile = world.getTileEntity(new BlockPos(x, y, z));
|
||||
@@ -131,4 +111,24 @@ public class GuiHandler implements IGuiHandler {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private ContainerGridFilter getGridFilterContainer(EntityPlayer player, int hand) {
|
||||
return new ContainerGridFilter(player, player.getHeldItem(EnumHand.values()[hand]));
|
||||
}
|
||||
|
||||
private WirelessGrid getWirelessGrid(EntityPlayer player, int hand) {
|
||||
return new WirelessGrid(player.worldObj, player.getHeldItem(EnumHand.values()[hand]), EnumHand.values()[hand]);
|
||||
}
|
||||
|
||||
private ContainerGrid getWirelessGridContainer(EntityPlayer player, int hand) {
|
||||
WirelessGrid wirelessGrid = getWirelessGrid(player, hand);
|
||||
|
||||
return new ContainerGrid(player, wirelessGrid);
|
||||
}
|
||||
|
||||
private GuiGrid getWirelessGridGui(EntityPlayer player, int hand) {
|
||||
WirelessGrid wirelessGrid = getWirelessGrid(player, hand);
|
||||
|
||||
return new GuiGrid(new ContainerGrid(player, wirelessGrid), wirelessGrid);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,15 +6,15 @@ import net.minecraftforge.items.ItemStackHandler;
|
||||
import refinedstorage.tile.TileBase;
|
||||
|
||||
public class GridFilterItemHandler extends ItemStackHandler {
|
||||
private ItemStack filter;
|
||||
private ItemStack stack;
|
||||
|
||||
public GridFilterItemHandler(ItemStack filter) {
|
||||
public GridFilterItemHandler(ItemStack stack) {
|
||||
super(9 * 3);
|
||||
|
||||
this.filter = filter;
|
||||
this.stack = stack;
|
||||
|
||||
if (filter.hasTagCompound()) {
|
||||
TileBase.readItems(this, 0, filter.getTagCompound());
|
||||
if (stack.hasTagCompound()) {
|
||||
TileBase.readItems(this, 0, stack.getTagCompound());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,10 +22,10 @@ public class GridFilterItemHandler extends ItemStackHandler {
|
||||
protected void onContentsChanged(int slot) {
|
||||
super.onContentsChanged(slot);
|
||||
|
||||
if (!filter.hasTagCompound()) {
|
||||
filter.setTagCompound(new NBTTagCompound());
|
||||
if (!stack.hasTagCompound()) {
|
||||
stack.setTagCompound(new NBTTagCompound());
|
||||
}
|
||||
|
||||
TileBase.writeItems(this, 0, filter.getTagCompound());
|
||||
TileBase.writeItems(this, 0, stack.getTagCompound());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user