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.entity.player.EntityPlayer;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.util.EnumHand;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a player using a wireless grid.
|
* Represents a player using a wireless grid.
|
||||||
*/
|
*/
|
||||||
public interface IWirelessGridConsumer {
|
public interface IWirelessGridConsumer {
|
||||||
/**
|
|
||||||
* @return The hand this wireless grid is opened with
|
|
||||||
*/
|
|
||||||
EnumHand getHand();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The player using the wireless grid
|
* @return The player using the wireless grid
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -2,25 +2,17 @@ package refinedstorage.apiimpl.network;
|
|||||||
|
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.util.EnumHand;
|
|
||||||
import refinedstorage.api.network.IWirelessGridConsumer;
|
import refinedstorage.api.network.IWirelessGridConsumer;
|
||||||
|
|
||||||
public class WirelessGridConsumer implements IWirelessGridConsumer {
|
public class WirelessGridConsumer implements IWirelessGridConsumer {
|
||||||
private EntityPlayer player;
|
private EntityPlayer player;
|
||||||
private EnumHand hand;
|
|
||||||
private ItemStack stack;
|
private ItemStack stack;
|
||||||
|
|
||||||
public WirelessGridConsumer(EntityPlayer player, EnumHand hand, ItemStack stack) {
|
public WirelessGridConsumer(EntityPlayer player, ItemStack stack) {
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.hand = hand;
|
|
||||||
this.stack = stack;
|
this.stack = stack;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public EnumHand getHand() {
|
|
||||||
return hand;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EntityPlayer getPlayer() {
|
public EntityPlayer getPlayer() {
|
||||||
return player;
|
return player;
|
||||||
|
|||||||
@@ -2,13 +2,11 @@ package refinedstorage.apiimpl.network;
|
|||||||
|
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.entity.player.EntityPlayerMP;
|
import net.minecraft.entity.player.EntityPlayerMP;
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraft.util.EnumHand;
|
import net.minecraft.util.EnumHand;
|
||||||
import refinedstorage.RefinedStorage;
|
import refinedstorage.RefinedStorage;
|
||||||
import refinedstorage.RefinedStorageGui;
|
import refinedstorage.RefinedStorageGui;
|
||||||
import refinedstorage.RefinedStorageItems;
|
import refinedstorage.RefinedStorageItems;
|
||||||
import refinedstorage.api.network.*;
|
import refinedstorage.api.network.*;
|
||||||
import refinedstorage.api.storage.CompareUtils;
|
|
||||||
import refinedstorage.item.ItemWirelessGrid;
|
import refinedstorage.item.ItemWirelessGrid;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -33,19 +31,6 @@ public class WirelessGridHandler implements IWirelessGridHandler {
|
|||||||
public void update() {
|
public void update() {
|
||||||
consumers.removeAll(consumersToRemove);
|
consumers.removeAll(consumersToRemove);
|
||||||
consumersToRemove.clear();
|
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
|
@Override
|
||||||
@@ -70,7 +55,7 @@ public class WirelessGridHandler implements IWirelessGridHandler {
|
|||||||
return false;
|
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);
|
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) {
|
if (consumer != null) {
|
||||||
ItemWirelessGrid item = RefinedStorageItems.WIRELESS_GRID;
|
ItemWirelessGrid item = RefinedStorageItems.WIRELESS_GRID;
|
||||||
ItemStack held = consumer.getPlayer().getHeldItem(consumer.getHand());
|
|
||||||
|
|
||||||
if (held.getItemDamage() != ItemWirelessGrid.TYPE_CREATIVE) {
|
if (consumer.getStack().getItemDamage() != ItemWirelessGrid.TYPE_CREATIVE) {
|
||||||
item.extractEnergy(held, energy, false);
|
item.extractEnergy(consumer.getStack(), energy, false);
|
||||||
|
|
||||||
if (item.getEnergyStored(held) <= 0) {
|
if (item.getEnergyStored(consumer.getStack()) <= 0) {
|
||||||
onClose(player);
|
onClose(player);
|
||||||
|
|
||||||
consumer.getPlayer().closeScreen();
|
consumer.getPlayer().closeScreen();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import refinedstorage.api.storage.CompareUtils;
|
|||||||
import refinedstorage.container.slot.SlotDisabled;
|
import refinedstorage.container.slot.SlotDisabled;
|
||||||
import refinedstorage.container.slot.SlotSpecimen;
|
import refinedstorage.container.slot.SlotSpecimen;
|
||||||
import refinedstorage.container.slot.SlotSpecimenLegacy;
|
import refinedstorage.container.slot.SlotSpecimenLegacy;
|
||||||
|
import refinedstorage.tile.grid.WirelessGrid;
|
||||||
|
|
||||||
public abstract class ContainerBase extends Container {
|
public abstract class ContainerBase extends Container {
|
||||||
private EntityPlayer player;
|
private EntityPlayer player;
|
||||||
@@ -29,7 +30,7 @@ public abstract class ContainerBase extends Container {
|
|||||||
int x = xInventory + i * 18;
|
int x = xInventory + i * 18;
|
||||||
int y = yInventory + 4 + (3 * 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));
|
addSlotToContainer(new SlotDisabled(player.inventory, id, x, y));
|
||||||
} else {
|
} else {
|
||||||
addSlotToContainer(new Slot(player.inventory, id, x, y));
|
addSlotToContainer(new Slot(player.inventory, id, x, y));
|
||||||
|
|||||||
@@ -7,21 +7,18 @@ import refinedstorage.container.slot.SlotSpecimen;
|
|||||||
import refinedstorage.inventory.GridFilterItemHandler;
|
import refinedstorage.inventory.GridFilterItemHandler;
|
||||||
|
|
||||||
public class ContainerGridFilter extends ContainerBase {
|
public class ContainerGridFilter extends ContainerBase {
|
||||||
private GridFilterItemHandler itemHandler;
|
private GridFilterItemHandler filter;
|
||||||
|
|
||||||
protected int slot;
|
public ContainerGridFilter(EntityPlayer player, ItemStack stack) {
|
||||||
|
|
||||||
public ContainerGridFilter(EntityPlayer player, ItemStack gridFilter, int slot) {
|
|
||||||
super(player);
|
super(player);
|
||||||
|
|
||||||
this.slot = slot;
|
this.filter = new GridFilterItemHandler(stack);
|
||||||
this.itemHandler = new GridFilterItemHandler(gridFilter);
|
|
||||||
|
|
||||||
int x = 8;
|
int x = 8;
|
||||||
int y = 20;
|
int y = 20;
|
||||||
|
|
||||||
for (int i = 0; i < 9 * 3; ++i) {
|
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) {
|
if ((i + 1) % 9 == 0) {
|
||||||
y += 18;
|
y += 18;
|
||||||
|
|||||||
@@ -66,26 +66,6 @@ public class GuiHandler implements IGuiHandler {
|
|||||||
return getContainer(ID, player, world.getTileEntity(new BlockPos(x, y, z)));
|
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
|
@Override
|
||||||
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
|
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
|
||||||
TileEntity tile = world.getTileEntity(new BlockPos(x, y, z));
|
TileEntity tile = world.getTileEntity(new BlockPos(x, y, z));
|
||||||
@@ -131,4 +111,24 @@ public class GuiHandler implements IGuiHandler {
|
|||||||
return null;
|
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;
|
import refinedstorage.tile.TileBase;
|
||||||
|
|
||||||
public class GridFilterItemHandler extends ItemStackHandler {
|
public class GridFilterItemHandler extends ItemStackHandler {
|
||||||
private ItemStack filter;
|
private ItemStack stack;
|
||||||
|
|
||||||
public GridFilterItemHandler(ItemStack filter) {
|
public GridFilterItemHandler(ItemStack stack) {
|
||||||
super(9 * 3);
|
super(9 * 3);
|
||||||
|
|
||||||
this.filter = filter;
|
this.stack = stack;
|
||||||
|
|
||||||
if (filter.hasTagCompound()) {
|
if (stack.hasTagCompound()) {
|
||||||
TileBase.readItems(this, 0, filter.getTagCompound());
|
TileBase.readItems(this, 0, stack.getTagCompound());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -22,10 +22,10 @@ public class GridFilterItemHandler extends ItemStackHandler {
|
|||||||
protected void onContentsChanged(int slot) {
|
protected void onContentsChanged(int slot) {
|
||||||
super.onContentsChanged(slot);
|
super.onContentsChanged(slot);
|
||||||
|
|
||||||
if (!filter.hasTagCompound()) {
|
if (!stack.hasTagCompound()) {
|
||||||
filter.setTagCompound(new NBTTagCompound());
|
stack.setTagCompound(new NBTTagCompound());
|
||||||
}
|
}
|
||||||
|
|
||||||
TileBase.writeItems(this, 0, filter.getTagCompound());
|
TileBase.writeItems(this, 0, stack.getTagCompound());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user