Wireless Grid changes
The wireless grid used to be a hack, just opening the block's GUI it was bound to. Now it is bound to a controller, which means a grid is no longer needed on the network to actually use a wireless grid. Thanks to this I can also easily implement the wireless grid as an RF item (I now have the ability to throw the player out of the GUI when needed, for example: power is up)
This commit is contained in:
@@ -13,4 +13,5 @@ public final class RefinedStorageGui {
|
||||
public static final int STORAGE = 11;
|
||||
public static final int RELAY = 12;
|
||||
public static final int INTERFACE = 13;
|
||||
public static final int WIRELESS_GRID = 14;
|
||||
}
|
||||
|
@@ -15,7 +15,7 @@ import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import refinedstorage.RefinedStorage;
|
||||
import refinedstorage.RefinedStorageGui;
|
||||
import refinedstorage.tile.TileGrid;
|
||||
import refinedstorage.tile.grid.TileGrid;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@@ -4,7 +4,8 @@ import net.minecraft.util.IStringSerializable;
|
||||
|
||||
public enum EnumGridType implements IStringSerializable {
|
||||
NORMAL(0, "normal"),
|
||||
CRAFTING(1, "crafting");
|
||||
CRAFTING(1, "crafting"),
|
||||
WIRELESS(2, "wireless");
|
||||
|
||||
private int id;
|
||||
private String name;
|
||||
@@ -27,5 +28,4 @@ public enum EnumGridType implements IStringSerializable {
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -6,7 +6,8 @@ import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import refinedstorage.block.EnumGridType;
|
||||
import refinedstorage.container.slot.SlotGridCraftingResult;
|
||||
import refinedstorage.tile.TileGrid;
|
||||
import refinedstorage.tile.grid.IGrid;
|
||||
import refinedstorage.tile.grid.TileGrid;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -14,9 +15,9 @@ import java.util.List;
|
||||
public class ContainerGrid extends ContainerBase {
|
||||
private List<Slot> craftingSlots = new ArrayList<Slot>();
|
||||
|
||||
private TileGrid grid;
|
||||
private IGrid grid;
|
||||
|
||||
public ContainerGrid(EntityPlayer player, TileGrid grid) {
|
||||
public ContainerGrid(EntityPlayer player, IGrid grid) {
|
||||
super(player);
|
||||
|
||||
this.grid = grid;
|
||||
@@ -28,7 +29,7 @@ public class ContainerGrid extends ContainerBase {
|
||||
int y = 106;
|
||||
|
||||
for (int i = 0; i < 9; ++i) {
|
||||
Slot slot = new Slot(grid.getCraftingInventory(), i, x, y);
|
||||
Slot slot = new Slot(((TileGrid) grid).getCraftingInventory(), i, x, y);
|
||||
|
||||
craftingSlots.add(slot);
|
||||
|
||||
@@ -42,12 +43,12 @@ public class ContainerGrid extends ContainerBase {
|
||||
}
|
||||
}
|
||||
|
||||
addSlotToContainer(new SlotGridCraftingResult(this, player, grid.getCraftingInventory(), grid.getCraftingResultInventory(), grid, 0, 133 + 4, 120 + 4));
|
||||
addSlotToContainer(new SlotGridCraftingResult(this, player, ((TileGrid) grid).getCraftingInventory(), ((TileGrid) grid).getCraftingResultInventory(), (TileGrid) grid, 0, 133 + 4, 120 + 4));
|
||||
}
|
||||
}
|
||||
|
||||
public TileGrid getGrid() {
|
||||
return grid;
|
||||
return (TileGrid) grid;
|
||||
}
|
||||
|
||||
public List<Slot> getCraftingSlots() {
|
||||
@@ -73,4 +74,13 @@ public class ContainerGrid extends ContainerBase {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onContainerClosed(EntityPlayer player) {
|
||||
super.onContainerClosed(player);
|
||||
|
||||
if (grid.getType() == EnumGridType.WIRELESS && grid.isConnected()) {
|
||||
grid.getController().onCloseWirelessGrid(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -7,7 +7,7 @@ import net.minecraft.inventory.SlotCrafting;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||
import refinedstorage.container.ContainerGrid;
|
||||
import refinedstorage.tile.TileGrid;
|
||||
import refinedstorage.tile.grid.TileGrid;
|
||||
|
||||
public class SlotGridCraftingResult extends SlotCrafting {
|
||||
private ContainerGrid container;
|
||||
|
@@ -21,14 +21,15 @@ import refinedstorage.network.MessageStoragePull;
|
||||
import refinedstorage.network.MessageStoragePush;
|
||||
import refinedstorage.storage.StorageItem;
|
||||
import refinedstorage.tile.TileController;
|
||||
import refinedstorage.tile.TileGrid;
|
||||
import refinedstorage.tile.grid.IGrid;
|
||||
import refinedstorage.tile.grid.TileGrid;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
public class GuiGrid extends GuiBase {
|
||||
private ContainerGrid container;
|
||||
private TileGrid grid;
|
||||
private IGrid grid;
|
||||
|
||||
private List<StorageItem> items = new ArrayList<StorageItem>();
|
||||
|
||||
@@ -39,7 +40,7 @@ public class GuiGrid extends GuiBase {
|
||||
|
||||
private Scrollbar scrollbar;
|
||||
|
||||
public GuiGrid(ContainerGrid container, TileGrid grid) {
|
||||
public GuiGrid(ContainerGrid container, IGrid grid) {
|
||||
super(container, 193, grid.getType() == EnumGridType.CRAFTING ? 256 : 208);
|
||||
|
||||
this.container = container;
|
||||
@@ -49,7 +50,9 @@ public class GuiGrid extends GuiBase {
|
||||
|
||||
@Override
|
||||
public void init(int x, int y) {
|
||||
addSideButton(new SideButtonRedstoneMode(grid));
|
||||
if (grid.getRedstoneModeSetting() != null) {
|
||||
addSideButton(new SideButtonRedstoneMode(grid.getRedstoneModeSetting()));
|
||||
}
|
||||
|
||||
addSideButton(new SideButtonGridSortingDirection(grid));
|
||||
addSideButton(new SideButtonGridSortingType(grid));
|
||||
@@ -162,7 +165,7 @@ public class GuiGrid extends GuiBase {
|
||||
public void drawForeground(int mouseX, int mouseY) {
|
||||
scrollbar.update(this, mouseX, mouseY);
|
||||
|
||||
drawString(7, 7, t("gui.refinedstorage:grid"));
|
||||
drawString(7, 7, t(grid.getType() == EnumGridType.WIRELESS ? "gui.refinedstorage:wireless_grid" : "gui.refinedstorage:grid"));
|
||||
|
||||
if (grid.getType() == EnumGridType.CRAFTING) {
|
||||
drawString(7, 94, t("container.crafting"));
|
||||
@@ -271,7 +274,7 @@ public class GuiGrid extends GuiBase {
|
||||
|
||||
RefinedStorage.NETWORK.sendToServer(new MessageStoragePull(controller.getPos().getX(), controller.getPos().getY(), controller.getPos().getZ(), hoveringItemId, flags));
|
||||
} else if (clickedClear) {
|
||||
RefinedStorage.NETWORK.sendToServer(new MessageGridCraftingClear(grid));
|
||||
RefinedStorage.NETWORK.sendToServer(new MessageGridCraftingClear((TileGrid) grid));
|
||||
} else {
|
||||
for (Slot slot : container.getPlayerInventorySlots()) {
|
||||
if (inBounds(slot.xDisplayPosition, slot.yDisplayPosition, 16, 16, mouseX - guiLeft, mouseY - guiTop)) {
|
||||
@@ -285,7 +288,7 @@ public class GuiGrid extends GuiBase {
|
||||
for (Slot slot : container.getCraftingSlots()) {
|
||||
if (inBounds(slot.xDisplayPosition, slot.yDisplayPosition, 16, 16, mouseX - guiLeft, mouseY - guiTop)) {
|
||||
if (GuiScreen.isShiftKeyDown()) {
|
||||
RefinedStorage.NETWORK.sendToServer(new MessageGridCraftingPush(grid, slot.getSlotIndex()));
|
||||
RefinedStorage.NETWORK.sendToServer(new MessageGridCraftingPush((TileGrid) grid, slot.getSlotIndex()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -3,6 +3,7 @@ package refinedstorage.gui;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.common.network.IGuiHandler;
|
||||
@@ -10,6 +11,8 @@ import refinedstorage.RefinedStorageGui;
|
||||
import refinedstorage.container.*;
|
||||
import refinedstorage.storage.IStorageGui;
|
||||
import refinedstorage.tile.*;
|
||||
import refinedstorage.tile.grid.TileGrid;
|
||||
import refinedstorage.tile.grid.WirelessGrid;
|
||||
|
||||
public class GuiHandler implements IGuiHandler {
|
||||
private Container getContainer(int ID, EntityPlayer player, TileEntity tile) {
|
||||
@@ -45,9 +48,31 @@ public class GuiHandler implements IGuiHandler {
|
||||
|
||||
@Override
|
||||
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
|
||||
if (ID == RefinedStorageGui.WIRELESS_GRID) {
|
||||
return getWirelessGridContainer(world, player, x);
|
||||
}
|
||||
|
||||
return getContainer(ID, player, world.getTileEntity(new BlockPos(x, y, z)));
|
||||
}
|
||||
|
||||
private WirelessGrid getWirelessGrid(World world, EntityPlayer player, int hand) {
|
||||
EnumHand realHand = hand == 0 ? EnumHand.MAIN_HAND : EnumHand.OFF_HAND;
|
||||
|
||||
return new WirelessGrid(player.getHeldItem(realHand), realHand, world);
|
||||
}
|
||||
|
||||
private ContainerGrid getWirelessGridContainer(World world, EntityPlayer player, int hand) {
|
||||
WirelessGrid wirelessGrid = getWirelessGrid(world, player, hand);
|
||||
|
||||
return new ContainerGrid(player, wirelessGrid);
|
||||
}
|
||||
|
||||
private GuiGrid getWirelessGridGui(World world, EntityPlayer player, int hand) {
|
||||
WirelessGrid wirelessGrid = getWirelessGrid(world, 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));
|
||||
@@ -57,6 +82,8 @@ public class GuiHandler implements IGuiHandler {
|
||||
return new GuiController((ContainerController) getContainer(ID, player, tile), (TileController) tile);
|
||||
case RefinedStorageGui.GRID:
|
||||
return new GuiGrid((ContainerGrid) getContainer(ID, player, tile), (TileGrid) tile);
|
||||
case RefinedStorageGui.WIRELESS_GRID:
|
||||
return getWirelessGridGui(world, player, x);
|
||||
case RefinedStorageGui.DISK_DRIVE:
|
||||
return new GuiStorage((ContainerStorage) getContainer(ID, player, tile), (IStorageGui) tile, "gui/disk_drive.png");
|
||||
case RefinedStorageGui.IMPORTER:
|
||||
|
@@ -1,15 +1,14 @@
|
||||
package refinedstorage.gui.sidebutton;
|
||||
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import refinedstorage.RefinedStorage;
|
||||
import refinedstorage.gui.GuiBase;
|
||||
import refinedstorage.network.MessageGridSettingsUpdate;
|
||||
import refinedstorage.tile.TileGrid;
|
||||
import refinedstorage.tile.grid.IGrid;
|
||||
import refinedstorage.tile.grid.TileGrid;
|
||||
|
||||
public class SideButtonGridSearchBoxMode extends SideButton {
|
||||
private TileGrid grid;
|
||||
private IGrid grid;
|
||||
|
||||
public SideButtonGridSearchBoxMode(TileGrid grid) {
|
||||
public SideButtonGridSearchBoxMode(IGrid grid) {
|
||||
this.grid = grid;
|
||||
}
|
||||
|
||||
@@ -39,6 +38,6 @@ public class SideButtonGridSearchBoxMode extends SideButton {
|
||||
mode = TileGrid.SEARCH_BOX_MODE_NORMAL;
|
||||
}
|
||||
|
||||
RefinedStorage.NETWORK.sendToServer(new MessageGridSettingsUpdate(grid, grid.getSortingDirection(), grid.getSortingType(), mode));
|
||||
grid.onSearchBoxModeChanged(mode);
|
||||
}
|
||||
}
|
||||
|
@@ -1,15 +1,14 @@
|
||||
package refinedstorage.gui.sidebutton;
|
||||
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import refinedstorage.RefinedStorage;
|
||||
import refinedstorage.gui.GuiBase;
|
||||
import refinedstorage.network.MessageGridSettingsUpdate;
|
||||
import refinedstorage.tile.TileGrid;
|
||||
import refinedstorage.tile.grid.IGrid;
|
||||
import refinedstorage.tile.grid.TileGrid;
|
||||
|
||||
public class SideButtonGridSortingDirection extends SideButton {
|
||||
private TileGrid grid;
|
||||
private IGrid grid;
|
||||
|
||||
public SideButtonGridSortingDirection(TileGrid grid) {
|
||||
public SideButtonGridSortingDirection(IGrid grid) {
|
||||
this.grid = grid;
|
||||
}
|
||||
|
||||
@@ -39,6 +38,6 @@ public class SideButtonGridSortingDirection extends SideButton {
|
||||
dir = TileGrid.SORTING_DIRECTION_ASCENDING;
|
||||
}
|
||||
|
||||
RefinedStorage.NETWORK.sendToServer(new MessageGridSettingsUpdate(grid, dir, grid.getSortingType(), grid.getSearchBoxMode()));
|
||||
grid.onSortingDirectionChanged(dir);
|
||||
}
|
||||
}
|
||||
|
@@ -1,15 +1,14 @@
|
||||
package refinedstorage.gui.sidebutton;
|
||||
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import refinedstorage.RefinedStorage;
|
||||
import refinedstorage.gui.GuiBase;
|
||||
import refinedstorage.network.MessageGridSettingsUpdate;
|
||||
import refinedstorage.tile.TileGrid;
|
||||
import refinedstorage.tile.grid.IGrid;
|
||||
import refinedstorage.tile.grid.TileGrid;
|
||||
|
||||
public class SideButtonGridSortingType extends SideButton {
|
||||
private TileGrid grid;
|
||||
private IGrid grid;
|
||||
|
||||
public SideButtonGridSortingType(TileGrid grid) {
|
||||
public SideButtonGridSortingType(IGrid grid) {
|
||||
this.grid = grid;
|
||||
}
|
||||
|
||||
@@ -39,6 +38,6 @@ public class SideButtonGridSortingType extends SideButton {
|
||||
type = TileGrid.SORTING_TYPE_QUANTITY;
|
||||
}
|
||||
|
||||
RefinedStorage.NETWORK.sendToServer(new MessageGridSettingsUpdate(grid, grid.getSortingDirection(), type, grid.getSearchBoxMode()));
|
||||
grid.onSortingTypeChanged(type);
|
||||
}
|
||||
}
|
||||
|
@@ -13,17 +13,19 @@ import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.TextComponentString;
|
||||
import net.minecraft.util.text.translation.I18n;
|
||||
import net.minecraft.world.World;
|
||||
import refinedstorage.RefinedStorage;
|
||||
import refinedstorage.RefinedStorageBlocks;
|
||||
import refinedstorage.RefinedStorageGui;
|
||||
import refinedstorage.tile.TileGrid;
|
||||
import refinedstorage.tile.TileController;
|
||||
import refinedstorage.tile.grid.TileGrid;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ItemWirelessGrid extends ItemBase {
|
||||
public static final String NBT_GRID_X = "GridX";
|
||||
public static final String NBT_GRID_Y = "GridY";
|
||||
public static final String NBT_GRID_Z = "GridZ";
|
||||
public static final String NBT_CONTROLLER_X = "ControllerX";
|
||||
public static final String NBT_CONTROLLER_Y = "ControllerY";
|
||||
public static final String NBT_CONTROLLER_Z = "ControllerZ";
|
||||
public static final String NBT_SORTING_TYPE = "SortingType";
|
||||
public static final String NBT_SORTING_DIRECTION = "SortingDirection";
|
||||
public static final String NBT_SEARCH_BOX_MODE = "SearchBoxMode";
|
||||
|
||||
public ItemWirelessGrid() {
|
||||
super("wireless_grid");
|
||||
@@ -44,12 +46,15 @@ public class ItemWirelessGrid extends ItemBase {
|
||||
public EnumActionResult onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
|
||||
Block block = worldIn.getBlockState(pos).getBlock();
|
||||
|
||||
if (block == RefinedStorageBlocks.GRID) {
|
||||
if (block == RefinedStorageBlocks.CONTROLLER) {
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
|
||||
tag.setInteger(NBT_GRID_X, pos.getX());
|
||||
tag.setInteger(NBT_GRID_Y, pos.getY());
|
||||
tag.setInteger(NBT_GRID_Z, pos.getZ());
|
||||
tag.setInteger(NBT_CONTROLLER_X, pos.getX());
|
||||
tag.setInteger(NBT_CONTROLLER_Y, pos.getY());
|
||||
tag.setInteger(NBT_CONTROLLER_Z, pos.getZ());
|
||||
tag.setInteger(NBT_SORTING_DIRECTION, TileGrid.SORTING_DIRECTION_DESCENDING);
|
||||
tag.setInteger(NBT_SORTING_TYPE, TileGrid.SORTING_TYPE_NAME);
|
||||
tag.setInteger(NBT_SEARCH_BOX_MODE, TileGrid.SEARCH_BOX_MODE_NORMAL);
|
||||
|
||||
stack.setTagCompound(tag);
|
||||
|
||||
@@ -66,8 +71,8 @@ public class ItemWirelessGrid extends ItemBase {
|
||||
if (isInRange(stack, player)) {
|
||||
TileEntity tile = world.getTileEntity(new BlockPos(getX(stack), getY(stack), getZ(stack)));
|
||||
|
||||
if (tile instanceof TileGrid) {
|
||||
player.openGui(RefinedStorage.INSTANCE, RefinedStorageGui.GRID, world, tile.getPos().getX(), tile.getPos().getY(), tile.getPos().getZ());
|
||||
if (tile instanceof TileController) {
|
||||
((TileController) tile).onOpenWirelessGrid(player, hand);
|
||||
|
||||
return new ActionResult(EnumActionResult.PASS, stack);
|
||||
} else {
|
||||
@@ -87,15 +92,27 @@ public class ItemWirelessGrid extends ItemBase {
|
||||
}
|
||||
|
||||
public static int getX(ItemStack stack) {
|
||||
return stack.getTagCompound().getInteger(NBT_GRID_X);
|
||||
return stack.getTagCompound().getInteger(NBT_CONTROLLER_X);
|
||||
}
|
||||
|
||||
public static int getY(ItemStack stack) {
|
||||
return stack.getTagCompound().getInteger(NBT_GRID_Y);
|
||||
return stack.getTagCompound().getInteger(NBT_CONTROLLER_Y);
|
||||
}
|
||||
|
||||
public static int getZ(ItemStack stack) {
|
||||
return stack.getTagCompound().getInteger(NBT_GRID_Z);
|
||||
return stack.getTagCompound().getInteger(NBT_CONTROLLER_Z);
|
||||
}
|
||||
|
||||
public static int getSortingType(ItemStack stack) {
|
||||
return stack.getTagCompound().getInteger(NBT_SORTING_TYPE);
|
||||
}
|
||||
|
||||
public static int getSortingDirection(ItemStack stack) {
|
||||
return stack.getTagCompound().getInteger(NBT_SORTING_DIRECTION);
|
||||
}
|
||||
|
||||
public static int getSearchBoxMode(ItemStack stack) {
|
||||
return stack.getTagCompound().getInteger(NBT_SEARCH_BOX_MODE);
|
||||
}
|
||||
|
||||
public static boolean isInRange(ItemStack stack, EntityPlayer player) {
|
||||
@@ -103,6 +120,6 @@ public class ItemWirelessGrid extends ItemBase {
|
||||
}
|
||||
|
||||
public static boolean isValid(ItemStack stack) {
|
||||
return stack.hasTagCompound() && stack.getTagCompound().hasKey(NBT_GRID_X) && stack.getTagCompound().hasKey(NBT_GRID_Y) && stack.getTagCompound().hasKey(NBT_GRID_Z);
|
||||
return stack.hasTagCompound() && stack.getTagCompound().hasKey(NBT_CONTROLLER_X) && stack.getTagCompound().hasKey(NBT_CONTROLLER_Y) && stack.getTagCompound().hasKey(NBT_CONTROLLER_Z);
|
||||
}
|
||||
}
|
||||
|
@@ -7,7 +7,7 @@ import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
import refinedstorage.block.EnumGridType;
|
||||
import refinedstorage.tile.TileGrid;
|
||||
import refinedstorage.tile.grid.TileGrid;
|
||||
|
||||
public class MessageGridCraftingClear extends MessageHandlerPlayerToServer<MessageGridCraftingClear> implements IMessage {
|
||||
private int x;
|
||||
|
@@ -7,7 +7,7 @@ import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
import refinedstorage.block.EnumGridType;
|
||||
import refinedstorage.tile.TileGrid;
|
||||
import refinedstorage.tile.grid.TileGrid;
|
||||
|
||||
public class MessageGridCraftingPush extends MessageHandlerPlayerToServer<MessageGridCraftingPush> implements IMessage {
|
||||
private int x;
|
||||
|
@@ -10,7 +10,7 @@ import net.minecraftforge.fml.common.network.ByteBufUtils;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
import refinedstorage.block.EnumGridType;
|
||||
import refinedstorage.container.ContainerGrid;
|
||||
import refinedstorage.tile.TileGrid;
|
||||
import refinedstorage.tile.grid.TileGrid;
|
||||
|
||||
public class MessageGridCraftingTransfer extends MessageHandlerPlayerToServer<MessageGridCraftingTransfer> implements IMessage {
|
||||
private NBTTagCompound recipe;
|
||||
|
@@ -5,7 +5,7 @@ import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
import refinedstorage.tile.TileGrid;
|
||||
import refinedstorage.tile.grid.TileGrid;
|
||||
|
||||
public class MessageGridSettingsUpdate extends MessageHandlerPlayerToServer<MessageGridSettingsUpdate> implements IMessage {
|
||||
private int x;
|
||||
|
62
src/main/java/refinedstorage/network/MessageWirelessGridSettingsUpdate.java
Executable file
62
src/main/java/refinedstorage/network/MessageWirelessGridSettingsUpdate.java
Executable file
@@ -0,0 +1,62 @@
|
||||
package refinedstorage.network;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
import refinedstorage.RefinedStorageItems;
|
||||
import refinedstorage.item.ItemWirelessGrid;
|
||||
import refinedstorage.tile.grid.TileGrid;
|
||||
|
||||
public class MessageWirelessGridSettingsUpdate extends MessageHandlerPlayerToServer<MessageWirelessGridSettingsUpdate> implements IMessage {
|
||||
private int hand;
|
||||
private int sortingDirection;
|
||||
private int sortingType;
|
||||
private int searchBoxMode;
|
||||
|
||||
public MessageWirelessGridSettingsUpdate() {
|
||||
}
|
||||
|
||||
public MessageWirelessGridSettingsUpdate(int hand, int sortingDirection, int sortingType, int searchBoxMode) {
|
||||
this.hand = hand;
|
||||
this.sortingDirection = sortingDirection;
|
||||
this.sortingType = sortingType;
|
||||
this.searchBoxMode = searchBoxMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
hand = buf.readInt();
|
||||
sortingDirection = buf.readInt();
|
||||
sortingType = buf.readInt();
|
||||
searchBoxMode = buf.readInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
buf.writeInt(hand);
|
||||
buf.writeInt(sortingDirection);
|
||||
buf.writeInt(sortingType);
|
||||
buf.writeInt(searchBoxMode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(MessageWirelessGridSettingsUpdate message, EntityPlayerMP player) {
|
||||
ItemStack held = player.getHeldItem(hand == 1 ? EnumHand.OFF_HAND : EnumHand.MAIN_HAND);
|
||||
|
||||
if (held != null && held.getItem() == RefinedStorageItems.WIRELESS_GRID && held.getTagCompound() != null) {
|
||||
if (message.sortingDirection == TileGrid.SORTING_DIRECTION_ASCENDING || message.sortingDirection == TileGrid.SORTING_DIRECTION_DESCENDING) {
|
||||
held.getTagCompound().setInteger(ItemWirelessGrid.NBT_SORTING_DIRECTION, message.sortingDirection);
|
||||
}
|
||||
|
||||
if (message.sortingType == TileGrid.SORTING_TYPE_QUANTITY || message.sortingType == TileGrid.SORTING_TYPE_NAME) {
|
||||
held.getTagCompound().setInteger(ItemWirelessGrid.NBT_SORTING_TYPE, message.sortingType);
|
||||
}
|
||||
|
||||
if (message.searchBoxMode == TileGrid.SEARCH_BOX_MODE_NORMAL || message.searchBoxMode == TileGrid.SEARCH_BOX_MODE_JEI_SYNCHRONIZED) {
|
||||
held.getTagCompound().setInteger(ItemWirelessGrid.NBT_SEARCH_BOX_MODE, message.searchBoxMode);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -20,6 +20,7 @@ import refinedstorage.item.*;
|
||||
import refinedstorage.network.*;
|
||||
import refinedstorage.storage.NBTStorage;
|
||||
import refinedstorage.tile.*;
|
||||
import refinedstorage.tile.grid.TileGrid;
|
||||
import refinedstorage.tile.solderer.*;
|
||||
|
||||
import static refinedstorage.RefinedStorage.ID;
|
||||
@@ -39,6 +40,7 @@ public class CommonProxy {
|
||||
RefinedStorage.NETWORK.registerMessage(MessageGridSettingsUpdate.class, MessageGridSettingsUpdate.class, 11, Side.SERVER);
|
||||
RefinedStorage.NETWORK.registerMessage(MessageGridCraftingPush.class, MessageGridCraftingPush.class, 12, Side.SERVER);
|
||||
RefinedStorage.NETWORK.registerMessage(MessageGridCraftingTransfer.class, MessageGridCraftingTransfer.class, 13, Side.SERVER);
|
||||
RefinedStorage.NETWORK.registerMessage(MessageWirelessGridSettingsUpdate.class, MessageWirelessGridSettingsUpdate.class, 14, Side.SERVER);
|
||||
|
||||
NetworkRegistry.INSTANCE.registerGuiHandler(RefinedStorage.INSTANCE, new GuiHandler());
|
||||
|
||||
|
@@ -3,12 +3,16 @@ package refinedstorage.tile;
|
||||
import cofh.api.energy.EnergyStorage;
|
||||
import cofh.api.energy.IEnergyReceiver;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import refinedstorage.RefinedStorage;
|
||||
import refinedstorage.RefinedStorageBlocks;
|
||||
import refinedstorage.RefinedStorageGui;
|
||||
import refinedstorage.block.BlockController;
|
||||
import refinedstorage.block.EnumControllerType;
|
||||
import refinedstorage.storage.IStorage;
|
||||
@@ -18,14 +22,19 @@ import refinedstorage.tile.settings.IRedstoneModeSetting;
|
||||
import refinedstorage.tile.settings.RedstoneMode;
|
||||
import refinedstorage.util.InventoryUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
public class TileController extends TileBase implements IEnergyReceiver, INetworkTile, IRedstoneModeSetting {
|
||||
public class WirelessGridConsumer {
|
||||
public EntityPlayer player;
|
||||
public EnumHand hand;
|
||||
public ItemStack wirelessGrid;
|
||||
}
|
||||
|
||||
private List<StorageItem> items = new ArrayList<StorageItem>();
|
||||
private List<IStorage> storages = new ArrayList<IStorage>();
|
||||
private List<WirelessGridConsumer> wirelessGridConsumers = new ArrayList<WirelessGridConsumer>();
|
||||
private List<WirelessGridConsumer> wirelessGridConsumersMarkedForRemoval = new ArrayList<WirelessGridConsumer>();
|
||||
|
||||
private RedstoneMode redstoneMode = RedstoneMode.IGNORE;
|
||||
|
||||
@@ -107,6 +116,19 @@ public class TileController extends TileBase implements IEnergyReceiver, INetwor
|
||||
}
|
||||
}
|
||||
|
||||
wirelessGridConsumers.removeAll(wirelessGridConsumersMarkedForRemoval);
|
||||
wirelessGridConsumersMarkedForRemoval.clear();
|
||||
|
||||
Iterator<WirelessGridConsumer> it = wirelessGridConsumers.iterator();
|
||||
while (it.hasNext()) {
|
||||
WirelessGridConsumer consumer = it.next();
|
||||
|
||||
if (!InventoryUtils.compareStack(consumer.wirelessGrid, consumer.player.getHeldItem(consumer.hand))) {
|
||||
onCloseWirelessGrid(consumer.player);
|
||||
consumer.player.closeScreen();
|
||||
}
|
||||
}
|
||||
|
||||
if (lastEnergy != energy.getEnergyStored()) {
|
||||
worldObj.updateComparatorOutputLevel(pos, RefinedStorageBlocks.CONTROLLER);
|
||||
}
|
||||
@@ -248,6 +270,35 @@ public class TileController extends TileBase implements IEnergyReceiver, INetwor
|
||||
return newStack;
|
||||
}
|
||||
|
||||
public void onOpenWirelessGrid(EntityPlayer player, EnumHand hand) {
|
||||
WirelessGridConsumer consumer = new WirelessGridConsumer();
|
||||
consumer.hand = hand;
|
||||
consumer.player = player;
|
||||
consumer.wirelessGrid = player.getHeldItem(hand);
|
||||
wirelessGridConsumers.add(consumer);
|
||||
|
||||
player.openGui(RefinedStorage.INSTANCE, RefinedStorageGui.WIRELESS_GRID, worldObj, hand == EnumHand.OFF_HAND ? 1 : 0, 0, 0);
|
||||
}
|
||||
|
||||
public void onCloseWirelessGrid(EntityPlayer player) {
|
||||
WirelessGridConsumer consumer = getWirelessGridConsumer(player);
|
||||
|
||||
if (consumer != null) {
|
||||
wirelessGridConsumersMarkedForRemoval.add(consumer);
|
||||
}
|
||||
}
|
||||
|
||||
public WirelessGridConsumer getWirelessGridConsumer(EntityPlayer player) {
|
||||
Iterator<WirelessGridConsumer> it = wirelessGridConsumers.iterator();
|
||||
while (it.hasNext()) {
|
||||
WirelessGridConsumer consumer = it.next();
|
||||
if (consumer.player == player) {
|
||||
return consumer;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
super.readFromNBT(nbt);
|
||||
|
27
src/main/java/refinedstorage/tile/grid/IGrid.java
Executable file
27
src/main/java/refinedstorage/tile/grid/IGrid.java
Executable file
@@ -0,0 +1,27 @@
|
||||
package refinedstorage.tile.grid;
|
||||
|
||||
import refinedstorage.block.EnumGridType;
|
||||
import refinedstorage.tile.TileController;
|
||||
import refinedstorage.tile.settings.IRedstoneModeSetting;
|
||||
|
||||
public interface IGrid {
|
||||
EnumGridType getType();
|
||||
|
||||
TileController getController();
|
||||
|
||||
int getSortingType();
|
||||
|
||||
int getSortingDirection();
|
||||
|
||||
int getSearchBoxMode();
|
||||
|
||||
void onSortingTypeChanged(int type);
|
||||
|
||||
void onSortingDirectionChanged(int direction);
|
||||
|
||||
void onSearchBoxModeChanged(int searchBoxMode);
|
||||
|
||||
IRedstoneModeSetting getRedstoneModeSetting();
|
||||
|
||||
boolean isConnected();
|
||||
}
|
@@ -1,4 +1,4 @@
|
||||
package refinedstorage.tile;
|
||||
package refinedstorage.tile.grid;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
@@ -8,17 +8,21 @@ import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.CraftingManager;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import refinedstorage.RefinedStorage;
|
||||
import refinedstorage.RefinedStorageBlocks;
|
||||
import refinedstorage.block.BlockGrid;
|
||||
import refinedstorage.block.EnumGridType;
|
||||
import refinedstorage.container.ContainerGrid;
|
||||
import refinedstorage.inventory.InventorySimple;
|
||||
import refinedstorage.network.MessageGridSettingsUpdate;
|
||||
import refinedstorage.tile.TileMachine;
|
||||
import refinedstorage.tile.settings.IRedstoneModeSetting;
|
||||
import refinedstorage.util.InventoryUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class TileGrid extends TileMachine {
|
||||
public class TileGrid extends TileMachine implements IGrid {
|
||||
public static final String NBT_SORTING_DIRECTION = "SortingDirection";
|
||||
public static final String NBT_SORTING_TYPE = "SortingType";
|
||||
public static final String NBT_SEARCH_BOX_MODE = "SearchBoxMode";
|
||||
@@ -185,6 +189,26 @@ public class TileGrid extends TileMachine {
|
||||
return searchBoxMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSortingTypeChanged(int type) {
|
||||
RefinedStorage.NETWORK.sendToServer(new MessageGridSettingsUpdate(this, sortingDirection, type, searchBoxMode));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSortingDirectionChanged(int direction) {
|
||||
RefinedStorage.NETWORK.sendToServer(new MessageGridSettingsUpdate(this, direction, sortingType, searchBoxMode));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSearchBoxModeChanged(int searchBoxMode) {
|
||||
RefinedStorage.NETWORK.sendToServer(new MessageGridSettingsUpdate(this, sortingDirection, sortingType, searchBoxMode));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IRedstoneModeSetting getRedstoneModeSetting() {
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setSearchBoxMode(int searchBoxMode) {
|
||||
this.searchBoxMode = searchBoxMode;
|
||||
}
|
86
src/main/java/refinedstorage/tile/grid/WirelessGrid.java
Executable file
86
src/main/java/refinedstorage/tile/grid/WirelessGrid.java
Executable file
@@ -0,0 +1,86 @@
|
||||
package refinedstorage.tile.grid;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import refinedstorage.RefinedStorage;
|
||||
import refinedstorage.block.EnumGridType;
|
||||
import refinedstorage.item.ItemWirelessGrid;
|
||||
import refinedstorage.network.MessageWirelessGridSettingsUpdate;
|
||||
import refinedstorage.tile.TileController;
|
||||
import refinedstorage.tile.settings.IRedstoneModeSetting;
|
||||
|
||||
public class WirelessGrid implements IGrid {
|
||||
private ItemStack stack;
|
||||
private EnumHand hand;
|
||||
private World world;
|
||||
private int sortingType;
|
||||
private int sortingDirection;
|
||||
private int searchBoxMode;
|
||||
|
||||
public WirelessGrid(ItemStack stack, EnumHand hand, World world) {
|
||||
this.stack = stack;
|
||||
this.hand = hand;
|
||||
this.world = world;
|
||||
this.sortingType = ItemWirelessGrid.getSortingType(stack);
|
||||
this.sortingDirection = ItemWirelessGrid.getSortingDirection(stack);
|
||||
this.searchBoxMode = ItemWirelessGrid.getSearchBoxMode(stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumGridType getType() {
|
||||
return EnumGridType.WIRELESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileController getController() {
|
||||
return (TileController) world.getTileEntity(new BlockPos(ItemWirelessGrid.getX(stack), ItemWirelessGrid.getY(stack), ItemWirelessGrid.getZ(stack)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSortingType() {
|
||||
return sortingType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSortingDirection() {
|
||||
return sortingDirection;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSearchBoxMode() {
|
||||
return searchBoxMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSortingTypeChanged(int type) {
|
||||
RefinedStorage.NETWORK.sendToServer(new MessageWirelessGridSettingsUpdate(hand == EnumHand.OFF_HAND ? 1 : 0, getSortingDirection(), type, getSearchBoxMode()));
|
||||
|
||||
this.sortingType = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSortingDirectionChanged(int direction) {
|
||||
RefinedStorage.NETWORK.sendToServer(new MessageWirelessGridSettingsUpdate(hand == EnumHand.OFF_HAND ? 1 : 0, direction, getSortingType(), getSearchBoxMode()));
|
||||
|
||||
this.sortingDirection = direction;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSearchBoxModeChanged(int searchBoxMode) {
|
||||
RefinedStorage.NETWORK.sendToServer(new MessageWirelessGridSettingsUpdate(hand == EnumHand.OFF_HAND ? 1 : 0, getSortingDirection(), getSortingType(), searchBoxMode));
|
||||
|
||||
this.searchBoxMode = searchBoxMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IRedstoneModeSetting getRedstoneModeSetting() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConnected() {
|
||||
return getController() instanceof TileController;
|
||||
}
|
||||
}
|
@@ -6,6 +6,7 @@ gui.refinedstorage:controller.machine_position.x=X: %d
|
||||
gui.refinedstorage:controller.machine_position.y=Y: %d
|
||||
gui.refinedstorage:controller.machine_position.z=Z: %d
|
||||
gui.refinedstorage:grid=Grid
|
||||
gui.refinedstorage:wireless_grid=Wireless Grid
|
||||
gui.refinedstorage:disk_drive=Drive
|
||||
gui.refinedstorage:external_storage=External Storage
|
||||
gui.refinedstorage:importer=Importer
|
||||
@@ -31,8 +32,8 @@ misc.refinedstorage:storage.full=%d%% full
|
||||
misc.refinedstorage:wireless_grid.tooltip.0=X: %d
|
||||
misc.refinedstorage:wireless_grid.tooltip.1=Y: %d
|
||||
misc.refinedstorage:wireless_grid.tooltip.2=Z: %d
|
||||
misc.refinedstorage:wireless_grid.out_of_range=Grid out of range.
|
||||
misc.refinedstorage:wireless_grid.not_found=Grid not found.
|
||||
misc.refinedstorage:wireless_grid.out_of_range=Controller out of range.
|
||||
misc.refinedstorage:wireless_grid.not_found=Controller not found.
|
||||
|
||||
misc.refinedstorage:yes=Yes
|
||||
misc.refinedstorage:no=No
|
||||
|
@@ -6,6 +6,7 @@ gui.refinedstorage:controller.machine_position.x=X: %d
|
||||
gui.refinedstorage:controller.machine_position.y=Y: %d
|
||||
gui.refinedstorage:controller.machine_position.z=Z: %d
|
||||
gui.refinedstorage:grid=Rooster
|
||||
gui.refinedstorage:wireless_grid=Draadloos Rooster
|
||||
gui.refinedstorage:disk_drive=Schijf
|
||||
gui.refinedstorage:external_storage=Externe Opslag
|
||||
gui.refinedstorage:importer=Importeur
|
||||
@@ -31,8 +32,8 @@ misc.refinedstorage:storage.full=%d%% vol
|
||||
misc.refinedstorage:wireless_grid.tooltip.0=X: %d
|
||||
misc.refinedstorage:wireless_grid.tooltip.1=Y: %d
|
||||
misc.refinedstorage:wireless_grid.tooltip.2=Z: %d
|
||||
misc.refinedstorage:wireless_grid.out_of_range=Rooster buiten bereik.
|
||||
misc.refinedstorage:wireless_grid.not_found=Rooster werd niet gevonden.
|
||||
misc.refinedstorage:wireless_grid.out_of_range=Controller buiten bereik.
|
||||
misc.refinedstorage:wireless_grid.not_found=Controller werd niet gevonden.
|
||||
|
||||
misc.refinedstorage:yes=Ja
|
||||
misc.refinedstorage:no=Nee
|
||||
@@ -93,7 +94,7 @@ item.refinedstorage:storage_disk.1.name=4k Opslagschijf
|
||||
item.refinedstorage:storage_disk.2.name=16k Opslagschijf
|
||||
item.refinedstorage:storage_disk.3.name=64k Opslagschijf
|
||||
item.refinedstorage:storage_disk.4.name=Creative Opslagschijf
|
||||
item.refinedstorage:wireless_grid.name=Draadloze Rooster
|
||||
item.refinedstorage:wireless_grid.name=Draadloos Rooster
|
||||
item.refinedstorage:quartz_enriched_iron.name=Quartz Verrijkt Iron
|
||||
item.refinedstorage:core.0.name=Constructie Core
|
||||
item.refinedstorage:core.1.name=Destructie Core
|
||||
|
Reference in New Issue
Block a user