Fixes #125 "Taking random items out of storage?"
This commit is contained in:
@@ -6,6 +6,8 @@ When updating to this version, you'll have to break and replace your controller.
|
|||||||
**Bugfixes**
|
**Bugfixes**
|
||||||
- Fixed controller not working after leaving chunk
|
- Fixed controller not working after leaving chunk
|
||||||
- Fixed machines not working when leaving chunk
|
- Fixed machines not working when leaving chunk
|
||||||
|
- Fixed getting wrong items back in grid
|
||||||
|
- Fixed wrong item getting crafted
|
||||||
- Rewrote storage networks: they are now saved to disk, so big systems won't lag when rejoining a chunk
|
- Rewrote storage networks: they are now saved to disk, so big systems won't lag when rejoining a chunk
|
||||||
|
|
||||||
### 0.7.16
|
### 0.7.16
|
||||||
|
|||||||
@@ -486,7 +486,7 @@ public class NetworkMaster {
|
|||||||
|
|
||||||
public void syncItemsWithClients() {
|
public void syncItemsWithClients() {
|
||||||
for (EntityPlayer player : world.playerEntities) {
|
for (EntityPlayer player : world.playerEntities) {
|
||||||
if (player.openContainer.getClass() == ContainerGrid.class && pos.equals(((ContainerGrid) player.openContainer).getGrid().getControllerPos())) {
|
if (player.openContainer.getClass() == ContainerGrid.class && pos.equals(((ContainerGrid) player.openContainer).getGrid().getNetworkPosition())) {
|
||||||
syncItemsWithClient((EntityPlayerMP) player);
|
syncItemsWithClient((EntityPlayerMP) player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -98,14 +98,10 @@ public class ContainerGrid extends ContainerBase {
|
|||||||
|
|
||||||
if (slot == craftingResultSlot) {
|
if (slot == craftingResultSlot) {
|
||||||
((TileGrid) grid).onCraftedShift(this, player);
|
((TileGrid) grid).onCraftedShift(this, player);
|
||||||
} else if (slot != patternResultSlot && !(slot instanceof SlotSpecimenLegacy)) {
|
} else if (grid.getStorageHandler() != null && slot != patternResultSlot && !(slot instanceof SlotSpecimenLegacy) && slot.getHasStack()) {
|
||||||
ItemStack stack = inventorySlots.get(slotIndex).getStack();
|
slot.putStack(grid.getStorageHandler().onPush(slot.getStack()));
|
||||||
|
|
||||||
if (stack != null) {
|
detectAndSendChanges();
|
||||||
inventorySlots.get(slotIndex).putStack(grid.onItemPush(player, stack));
|
|
||||||
|
|
||||||
detectAndSendChanges();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,9 +3,12 @@ package refinedstorage.gui;
|
|||||||
import com.google.common.primitives.Ints;
|
import com.google.common.primitives.Ints;
|
||||||
import net.minecraft.client.gui.GuiButton;
|
import net.minecraft.client.gui.GuiButton;
|
||||||
import net.minecraft.client.gui.GuiTextField;
|
import net.minecraft.client.gui.GuiTextField;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraftforge.fml.client.FMLClientHandler;
|
import net.minecraftforge.fml.client.FMLClientHandler;
|
||||||
import org.lwjgl.input.Keyboard;
|
import org.lwjgl.input.Keyboard;
|
||||||
|
import refinedstorage.RefinedStorage;
|
||||||
import refinedstorage.container.ContainerDummy;
|
import refinedstorage.container.ContainerDummy;
|
||||||
|
import refinedstorage.network.MessageGridCraftingStart;
|
||||||
import refinedstorage.tile.controller.StorageHandler;
|
import refinedstorage.tile.controller.StorageHandler;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -13,14 +16,14 @@ import java.io.IOException;
|
|||||||
public class GuiCraftingSettings extends GuiBase {
|
public class GuiCraftingSettings extends GuiBase {
|
||||||
private GuiTextField amountField;
|
private GuiTextField amountField;
|
||||||
private GuiGrid gridGui;
|
private GuiGrid gridGui;
|
||||||
private int id;
|
private ItemStack stack;
|
||||||
private GuiButton startButton;
|
private GuiButton startButton;
|
||||||
|
|
||||||
public GuiCraftingSettings(GuiGrid gridGui, int id) {
|
public GuiCraftingSettings(GuiGrid gridGui, ItemStack stack) {
|
||||||
super(new ContainerDummy(), 143, 61);
|
super(new ContainerDummy(), 143, 61);
|
||||||
|
|
||||||
this.gridGui = gridGui;
|
this.gridGui = gridGui;
|
||||||
this.id = id;
|
this.stack = stack;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -82,7 +85,7 @@ public class GuiCraftingSettings extends GuiBase {
|
|||||||
Integer quantity = Ints.tryParse(amountField.getText());
|
Integer quantity = Ints.tryParse(amountField.getText());
|
||||||
|
|
||||||
if (quantity != null && quantity > 0 && quantity <= StorageHandler.MAX_CRAFTING_PER_REQUEST) {
|
if (quantity != null && quantity > 0 && quantity <= StorageHandler.MAX_CRAFTING_PER_REQUEST) {
|
||||||
gridGui.getGrid().onCraftingRequested(id, quantity);
|
RefinedStorage.NETWORK.sendToServer(new MessageGridCraftingStart(stack, quantity));
|
||||||
|
|
||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,10 +19,7 @@ import refinedstorage.gui.sidebutton.SideButtonGridSortingDirection;
|
|||||||
import refinedstorage.gui.sidebutton.SideButtonGridSortingType;
|
import refinedstorage.gui.sidebutton.SideButtonGridSortingType;
|
||||||
import refinedstorage.gui.sidebutton.SideButtonRedstoneMode;
|
import refinedstorage.gui.sidebutton.SideButtonRedstoneMode;
|
||||||
import refinedstorage.jei.RefinedStorageJEIPlugin;
|
import refinedstorage.jei.RefinedStorageJEIPlugin;
|
||||||
import refinedstorage.network.GridPullFlags;
|
import refinedstorage.network.*;
|
||||||
import refinedstorage.network.MessageGridCraftingClear;
|
|
||||||
import refinedstorage.network.MessageGridPatternCreate;
|
|
||||||
import refinedstorage.tile.ClientItem;
|
|
||||||
import refinedstorage.tile.grid.IGrid;
|
import refinedstorage.tile.grid.IGrid;
|
||||||
import refinedstorage.tile.grid.TileGrid;
|
import refinedstorage.tile.grid.TileGrid;
|
||||||
import refinedstorage.tile.grid.WirelessGrid;
|
import refinedstorage.tile.grid.WirelessGrid;
|
||||||
@@ -31,11 +28,11 @@ import java.io.IOException;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class GuiGrid extends GuiBase {
|
public class GuiGrid extends GuiBase {
|
||||||
private Comparator<ClientItem> quantityComparator = new Comparator<ClientItem>() {
|
private Comparator<ItemStack> quantityComparator = new Comparator<ItemStack>() {
|
||||||
@Override
|
@Override
|
||||||
public int compare(ClientItem left, ClientItem right) {
|
public int compare(ItemStack left, ItemStack right) {
|
||||||
int leftSize = left.getStack().stackSize;
|
int leftSize = left.stackSize;
|
||||||
int rightSize = right.getStack().stackSize;
|
int rightSize = right.stackSize;
|
||||||
|
|
||||||
if (leftSize == rightSize) {
|
if (leftSize == rightSize) {
|
||||||
return 0;
|
return 0;
|
||||||
@@ -51,28 +48,26 @@ public class GuiGrid extends GuiBase {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private Comparator<ClientItem> nameComparator = new Comparator<ClientItem>() {
|
private Comparator<ItemStack> nameComparator = new Comparator<ItemStack>() {
|
||||||
@Override
|
@Override
|
||||||
public int compare(ClientItem left, ClientItem right) {
|
public int compare(ItemStack left, ItemStack right) {
|
||||||
if (grid.getSortingDirection() == TileGrid.SORTING_DIRECTION_ASCENDING) {
|
if (grid.getSortingDirection() == TileGrid.SORTING_DIRECTION_ASCENDING) {
|
||||||
return left.getStack().getDisplayName().compareTo(right.getStack().getDisplayName());
|
return left.getDisplayName().compareTo(right.getDisplayName());
|
||||||
} else if (grid.getSortingDirection() == TileGrid.SORTING_DIRECTION_DESCENDING) {
|
} else if (grid.getSortingDirection() == TileGrid.SORTING_DIRECTION_DESCENDING) {
|
||||||
return right.getStack().getDisplayName().compareTo(left.getStack().getDisplayName());
|
return right.getDisplayName().compareTo(left.getDisplayName());
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private ContainerGrid container;
|
|
||||||
private IGrid grid;
|
|
||||||
|
|
||||||
private List<ClientItem> items = new ArrayList<ClientItem>();
|
|
||||||
|
|
||||||
private GuiTextField searchField;
|
private GuiTextField searchField;
|
||||||
|
|
||||||
|
private ContainerGrid container;
|
||||||
|
private List<ItemStack> items = new ArrayList<ItemStack>();
|
||||||
|
private IGrid grid;
|
||||||
|
|
||||||
private int slotNumber;
|
private int slotNumber;
|
||||||
private int slotId;
|
|
||||||
|
|
||||||
public GuiGrid(ContainerGrid container, IGrid grid) {
|
public GuiGrid(ContainerGrid container, IGrid grid) {
|
||||||
super(container, 193, (grid.getType() == EnumGridType.CRAFTING || grid.getType() == EnumGridType.PATTERN) ? 256 : 208);
|
super(container, 193, (grid.getType() == EnumGridType.CRAFTING || grid.getType() == EnumGridType.PATTERN) ? 256 : 208);
|
||||||
@@ -85,8 +80,8 @@ public class GuiGrid extends GuiBase {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init(int x, int y) {
|
public void init(int x, int y) {
|
||||||
if (grid.getRedstoneModeSetting() != null) {
|
if (grid.getRedstoneModeConfig() != null) {
|
||||||
addSideButton(new SideButtonRedstoneMode(grid.getRedstoneModeSetting()));
|
addSideButton(new SideButtonRedstoneMode(grid.getRedstoneModeConfig()));
|
||||||
}
|
}
|
||||||
|
|
||||||
int sx = x + 80 + 1;
|
int sx = x + 80 + 1;
|
||||||
@@ -123,16 +118,16 @@ public class GuiGrid extends GuiBase {
|
|||||||
String query = searchField.getText().trim().toLowerCase();
|
String query = searchField.getText().trim().toLowerCase();
|
||||||
|
|
||||||
if (!query.isEmpty()) {
|
if (!query.isEmpty()) {
|
||||||
Iterator<ClientItem> t = items.iterator();
|
Iterator<ItemStack> t = items.iterator();
|
||||||
|
|
||||||
while (t.hasNext()) {
|
while (t.hasNext()) {
|
||||||
ClientItem item = t.next();
|
ItemStack item = t.next();
|
||||||
|
|
||||||
if (query.startsWith("@")) {
|
if (query.startsWith("@")) {
|
||||||
String[] parts = query.split(" ");
|
String[] parts = query.split(" ");
|
||||||
|
|
||||||
String modId = parts[0].substring(1);
|
String modId = parts[0].substring(1);
|
||||||
String modIdFromItem = Item.REGISTRY.getNameForObject(item.getStack().getItem()).getResourceDomain();
|
String modIdFromItem = Item.REGISTRY.getNameForObject(item.getItem()).getResourceDomain();
|
||||||
|
|
||||||
if (!modIdFromItem.contains(modId)) {
|
if (!modIdFromItem.contains(modId)) {
|
||||||
t.remove();
|
t.remove();
|
||||||
@@ -147,18 +142,18 @@ public class GuiGrid extends GuiBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!item.getStack().getDisplayName().toLowerCase().contains(itemFromMod.toString())) {
|
if (!item.getDisplayName().toLowerCase().contains(itemFromMod.toString())) {
|
||||||
t.remove();
|
t.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (query.startsWith("#")) {
|
} else if (query.startsWith("#")) {
|
||||||
String tooltip = query.substring(1);
|
String tooltip = query.substring(1);
|
||||||
String tooltipFromItem = StringUtils.join(item.getStack().getTooltip(container.getPlayer(), true), "\n");
|
String tooltipFromItem = StringUtils.join(item.getTooltip(container.getPlayer(), true), "\n");
|
||||||
|
|
||||||
if (!tooltipFromItem.contains(tooltip)) {
|
if (!tooltipFromItem.contains(tooltip)) {
|
||||||
t.remove();
|
t.remove();
|
||||||
}
|
}
|
||||||
} else if (!item.getStack().getDisplayName().toLowerCase().contains(query)) {
|
} else if (!item.getDisplayName().toLowerCase().contains(query)) {
|
||||||
t.remove();
|
t.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -269,14 +264,10 @@ public class GuiGrid extends GuiBase {
|
|||||||
for (int i = 0; i < 9 * getVisibleRows(); ++i) {
|
for (int i = 0; i < 9 * getVisibleRows(); ++i) {
|
||||||
if (inBounds(x, y, 16, 16, mouseX, mouseY) || !grid.isConnected()) {
|
if (inBounds(x, y, 16, 16, mouseX, mouseY) || !grid.isConnected()) {
|
||||||
this.slotNumber = slot;
|
this.slotNumber = slot;
|
||||||
|
|
||||||
if (slot < items.size()) {
|
|
||||||
slotId = items.get(slot).getId();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (slot < items.size()) {
|
if (slot < items.size()) {
|
||||||
ItemStack stack = items.get(slot).getStack();
|
ItemStack stack = items.get(slot);
|
||||||
|
|
||||||
drawItem(x, y, stack, true, formatQuantity(stack.stackSize, slot));
|
drawItem(x, y, stack, true, formatQuantity(stack.stackSize, slot));
|
||||||
}
|
}
|
||||||
@@ -306,7 +297,7 @@ public class GuiGrid extends GuiBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isOverSlotWithItem()) {
|
if (isOverSlotWithItem()) {
|
||||||
drawTooltip(mouseX, mouseY, items.get(slotNumber).getStack());
|
drawTooltip(mouseX, mouseY, items.get(slotNumber));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isOverClear(mouseX, mouseY)) {
|
if (isOverClear(mouseX, mouseY)) {
|
||||||
@@ -362,12 +353,12 @@ public class GuiGrid extends GuiBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isOverSlotArea(mouseX - guiLeft, mouseY - guiTop) && container.getPlayer().inventory.getItemStack() != null && (clickedButton == 0 || clickedButton == 1)) {
|
if (isOverSlotArea(mouseX - guiLeft, mouseY - guiTop) && container.getPlayer().inventory.getItemStack() != null && (clickedButton == 0 || clickedButton == 1)) {
|
||||||
grid.onHeldItemPush(clickedButton == 1);
|
RefinedStorage.NETWORK.sendToServer(new MessageGridHeldPush(clickedButton == 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isOverSlotWithItem() && container.getPlayer().inventory.getItemStack() == null) {
|
if (isOverSlotWithItem() && container.getPlayer().inventory.getItemStack() == null) {
|
||||||
if (items.get(slotNumber).getStack().stackSize == 0 || (GuiScreen.isShiftKeyDown() && GuiScreen.isCtrlKeyDown())) {
|
if (items.get(slotNumber).stackSize == 0 || (GuiScreen.isShiftKeyDown() && GuiScreen.isCtrlKeyDown())) {
|
||||||
FMLCommonHandler.instance().showGuiScreen(new GuiCraftingSettings(this, slotId));
|
FMLCommonHandler.instance().showGuiScreen(new GuiCraftingSettings(this, items.get(slotNumber)));
|
||||||
} else {
|
} else {
|
||||||
int flags = 0;
|
int flags = 0;
|
||||||
|
|
||||||
@@ -383,7 +374,7 @@ public class GuiGrid extends GuiBase {
|
|||||||
flags |= GridPullFlags.PULL_ONE;
|
flags |= GridPullFlags.PULL_ONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
grid.onItemPull(slotId, flags);
|
RefinedStorage.NETWORK.sendToServer(new MessageGridPull(items.get(slotNumber), flags));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,53 +2,47 @@ package refinedstorage.network;
|
|||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import net.minecraft.entity.player.EntityPlayerMP;
|
import net.minecraft.entity.player.EntityPlayerMP;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.inventory.Container;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraftforge.fml.common.network.ByteBufUtils;
|
||||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||||
import refinedstorage.api.network.NetworkMaster;
|
import refinedstorage.container.ContainerGrid;
|
||||||
import refinedstorage.api.network.NetworkMasterRegistry;
|
import refinedstorage.tile.controller.StorageHandler;
|
||||||
|
|
||||||
public class MessageGridCraftingStart extends MessageHandlerPlayerToServer<MessageGridCraftingStart> implements IMessage {
|
public class MessageGridCraftingStart extends MessageHandlerPlayerToServer<MessageGridCraftingStart> implements IMessage {
|
||||||
private int x;
|
private ItemStack stack;
|
||||||
private int y;
|
|
||||||
private int z;
|
|
||||||
private int id;
|
|
||||||
private int quantity;
|
private int quantity;
|
||||||
|
|
||||||
public MessageGridCraftingStart() {
|
public MessageGridCraftingStart() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public MessageGridCraftingStart(int x, int y, int z, int id, int quantity) {
|
public MessageGridCraftingStart(ItemStack stack, int quantity) {
|
||||||
this.x = x;
|
this.stack = stack;
|
||||||
this.y = y;
|
|
||||||
this.z = z;
|
|
||||||
this.id = id;
|
|
||||||
this.quantity = quantity;
|
this.quantity = quantity;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void fromBytes(ByteBuf buf) {
|
public void fromBytes(ByteBuf buf) {
|
||||||
x = buf.readInt();
|
stack = ByteBufUtils.readItemStack(buf);
|
||||||
y = buf.readInt();
|
|
||||||
z = buf.readInt();
|
|
||||||
id = buf.readInt();
|
|
||||||
quantity = buf.readInt();
|
quantity = buf.readInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void toBytes(ByteBuf buf) {
|
public void toBytes(ByteBuf buf) {
|
||||||
buf.writeInt(x);
|
ByteBufUtils.writeItemStack(buf, stack);
|
||||||
buf.writeInt(y);
|
|
||||||
buf.writeInt(z);
|
|
||||||
buf.writeInt(id);
|
|
||||||
buf.writeInt(quantity);
|
buf.writeInt(quantity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handle(MessageGridCraftingStart message, EntityPlayerMP player) {
|
public void handle(MessageGridCraftingStart message, EntityPlayerMP player) {
|
||||||
NetworkMaster network = NetworkMasterRegistry.get(new BlockPos(message.x, message.y, message.z), player.worldObj.provider.getDimension());
|
Container container = player.openContainer;
|
||||||
|
|
||||||
if (network != null && network.canRun()) {
|
if (container instanceof ContainerGrid) {
|
||||||
network.getStorageHandler().onCraftingRequested(message.id, message.quantity);
|
StorageHandler handler = ((ContainerGrid) container).getGrid().getStorageHandler();
|
||||||
|
|
||||||
|
if (handler != null) {
|
||||||
|
handler.onCraftingRequested(message.stack, message.quantity);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,50 +0,0 @@
|
|||||||
package refinedstorage.network;
|
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
|
||||||
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.grid.TileGrid;
|
|
||||||
|
|
||||||
public class MessageGridHeldItemPush extends MessageHandlerPlayerToServer<MessageGridHeldItemPush> implements IMessage {
|
|
||||||
private int x;
|
|
||||||
private int y;
|
|
||||||
private int z;
|
|
||||||
private boolean one;
|
|
||||||
|
|
||||||
public MessageGridHeldItemPush() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public MessageGridHeldItemPush(int x, int y, int z, boolean one) {
|
|
||||||
this.x = x;
|
|
||||||
this.y = y;
|
|
||||||
this.z = z;
|
|
||||||
this.one = one;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void fromBytes(ByteBuf buf) {
|
|
||||||
x = buf.readInt();
|
|
||||||
y = buf.readInt();
|
|
||||||
z = buf.readInt();
|
|
||||||
one = buf.readBoolean();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void toBytes(ByteBuf buf) {
|
|
||||||
buf.writeInt(x);
|
|
||||||
buf.writeInt(y);
|
|
||||||
buf.writeInt(z);
|
|
||||||
buf.writeBoolean(one);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void handle(MessageGridHeldItemPush message, EntityPlayerMP player) {
|
|
||||||
TileEntity tile = player.worldObj.getTileEntity(new BlockPos(message.x, message.y, message.z));
|
|
||||||
|
|
||||||
if (tile instanceof TileGrid && ((TileGrid) tile).isConnected()) {
|
|
||||||
((TileGrid) tile).getNetwork().getStorageHandler().onHeldItemPush(message.one, player);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
42
src/main/java/refinedstorage/network/MessageGridHeldPush.java
Executable file
42
src/main/java/refinedstorage/network/MessageGridHeldPush.java
Executable file
@@ -0,0 +1,42 @@
|
|||||||
|
package refinedstorage.network;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import net.minecraft.entity.player.EntityPlayerMP;
|
||||||
|
import net.minecraft.inventory.Container;
|
||||||
|
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||||
|
import refinedstorage.container.ContainerGrid;
|
||||||
|
import refinedstorage.tile.controller.StorageHandler;
|
||||||
|
|
||||||
|
public class MessageGridHeldPush extends MessageHandlerPlayerToServer<MessageGridHeldPush> implements IMessage {
|
||||||
|
private boolean single;
|
||||||
|
|
||||||
|
public MessageGridHeldPush() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public MessageGridHeldPush(boolean single) {
|
||||||
|
this.single = single;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void fromBytes(ByteBuf buf) {
|
||||||
|
single = buf.readBoolean();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void toBytes(ByteBuf buf) {
|
||||||
|
buf.writeBoolean(single);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handle(MessageGridHeldPush message, EntityPlayerMP player) {
|
||||||
|
Container container = player.openContainer;
|
||||||
|
|
||||||
|
if (container instanceof ContainerGrid) {
|
||||||
|
StorageHandler handler = ((ContainerGrid) container).getGrid().getStorageHandler();
|
||||||
|
|
||||||
|
if (handler != null) {
|
||||||
|
handler.onHeldItemPush(message.single, player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,14 +10,13 @@ import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
|
|||||||
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
|
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
|
||||||
import refinedstorage.api.network.NetworkMaster;
|
import refinedstorage.api.network.NetworkMaster;
|
||||||
import refinedstorage.container.ContainerGrid;
|
import refinedstorage.container.ContainerGrid;
|
||||||
import refinedstorage.tile.ClientItem;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class MessageGridItems implements IMessage, IMessageHandler<MessageGridItems, IMessage> {
|
public class MessageGridItems implements IMessage, IMessageHandler<MessageGridItems, IMessage> {
|
||||||
private NetworkMaster network;
|
private NetworkMaster network;
|
||||||
private List<ClientItem> items = new ArrayList<ClientItem>();
|
private List<ItemStack> items = new ArrayList<ItemStack>();
|
||||||
|
|
||||||
public MessageGridItems() {
|
public MessageGridItems() {
|
||||||
}
|
}
|
||||||
@@ -36,7 +35,7 @@ public class MessageGridItems implements IMessage, IMessageHandler<MessageGridIt
|
|||||||
ItemStack stack = ByteBufUtils.readItemStack(buf);
|
ItemStack stack = ByteBufUtils.readItemStack(buf);
|
||||||
stack.stackSize = size;
|
stack.stackSize = size;
|
||||||
|
|
||||||
this.items.add(new ClientItem(i, stack));
|
this.items.add(stack);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
48
src/main/java/refinedstorage/network/MessageGridPull.java
Executable file
48
src/main/java/refinedstorage/network/MessageGridPull.java
Executable file
@@ -0,0 +1,48 @@
|
|||||||
|
package refinedstorage.network;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import net.minecraft.entity.player.EntityPlayerMP;
|
||||||
|
import net.minecraft.inventory.Container;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraftforge.fml.common.network.ByteBufUtils;
|
||||||
|
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||||
|
import refinedstorage.container.ContainerGrid;
|
||||||
|
import refinedstorage.tile.controller.StorageHandler;
|
||||||
|
|
||||||
|
public class MessageGridPull extends MessageHandlerPlayerToServer<MessageGridPull> implements IMessage {
|
||||||
|
private ItemStack stack;
|
||||||
|
private int flags;
|
||||||
|
|
||||||
|
public MessageGridPull() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public MessageGridPull(ItemStack stack, int flags) {
|
||||||
|
this.stack = stack;
|
||||||
|
this.flags = flags;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void fromBytes(ByteBuf buf) {
|
||||||
|
stack = ByteBufUtils.readItemStack(buf);
|
||||||
|
flags = buf.readInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void toBytes(ByteBuf buf) {
|
||||||
|
ByteBufUtils.writeItemStack(buf, stack);
|
||||||
|
buf.writeInt(flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handle(MessageGridPull message, EntityPlayerMP player) {
|
||||||
|
Container container = player.openContainer;
|
||||||
|
|
||||||
|
if (container instanceof ContainerGrid) {
|
||||||
|
StorageHandler handler = ((ContainerGrid) container).getGrid().getStorageHandler();
|
||||||
|
|
||||||
|
if (handler != null) {
|
||||||
|
handler.onPull(message.stack, message.flags, player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,54 +0,0 @@
|
|||||||
package refinedstorage.network;
|
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
|
||||||
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.grid.TileGrid;
|
|
||||||
|
|
||||||
public class MessageGridStoragePull extends MessageHandlerPlayerToServer<MessageGridStoragePull> implements IMessage {
|
|
||||||
private int x;
|
|
||||||
private int y;
|
|
||||||
private int z;
|
|
||||||
private int id;
|
|
||||||
private int flags;
|
|
||||||
|
|
||||||
public MessageGridStoragePull() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public MessageGridStoragePull(int x, int y, int z, int id, int flags) {
|
|
||||||
this.x = x;
|
|
||||||
this.y = y;
|
|
||||||
this.z = z;
|
|
||||||
this.id = id;
|
|
||||||
this.flags = flags;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void fromBytes(ByteBuf buf) {
|
|
||||||
x = buf.readInt();
|
|
||||||
y = buf.readInt();
|
|
||||||
z = buf.readInt();
|
|
||||||
id = buf.readInt();
|
|
||||||
flags = buf.readInt();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void toBytes(ByteBuf buf) {
|
|
||||||
buf.writeInt(x);
|
|
||||||
buf.writeInt(y);
|
|
||||||
buf.writeInt(z);
|
|
||||||
buf.writeInt(id);
|
|
||||||
buf.writeInt(flags);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void handle(MessageGridStoragePull message, EntityPlayerMP player) {
|
|
||||||
TileEntity tile = player.worldObj.getTileEntity(new BlockPos(message.x, message.y, message.z));
|
|
||||||
|
|
||||||
if (tile instanceof TileGrid && ((TileGrid) tile).isConnected()) {
|
|
||||||
((TileGrid) tile).getNetwork().getStorageHandler().onPull(message.id, message.flags, player);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,54 +0,0 @@
|
|||||||
package refinedstorage.network;
|
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
|
||||||
import net.minecraft.entity.player.EntityPlayerMP;
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
|
||||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
|
||||||
import refinedstorage.api.network.NetworkMaster;
|
|
||||||
import refinedstorage.api.network.NetworkMasterRegistry;
|
|
||||||
|
|
||||||
public class MessageWirelessGridCraftingStart extends MessageHandlerPlayerToServer<MessageWirelessGridCraftingStart> implements IMessage {
|
|
||||||
private int controllerX;
|
|
||||||
private int controllerY;
|
|
||||||
private int controllerZ;
|
|
||||||
private int id;
|
|
||||||
private int quantity;
|
|
||||||
|
|
||||||
public MessageWirelessGridCraftingStart() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public MessageWirelessGridCraftingStart(int controllerX, int controllerY, int controllerZ, int id, int quantity) {
|
|
||||||
this.controllerX = controllerX;
|
|
||||||
this.controllerY = controllerY;
|
|
||||||
this.controllerZ = controllerZ;
|
|
||||||
this.id = id;
|
|
||||||
this.quantity = quantity;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void fromBytes(ByteBuf buf) {
|
|
||||||
controllerX = buf.readInt();
|
|
||||||
controllerY = buf.readInt();
|
|
||||||
controllerZ = buf.readInt();
|
|
||||||
id = buf.readInt();
|
|
||||||
quantity = buf.readInt();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void toBytes(ByteBuf buf) {
|
|
||||||
buf.writeInt(controllerX);
|
|
||||||
buf.writeInt(controllerY);
|
|
||||||
buf.writeInt(controllerZ);
|
|
||||||
buf.writeInt(id);
|
|
||||||
buf.writeInt(quantity);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void handle(MessageWirelessGridCraftingStart message, EntityPlayerMP player) {
|
|
||||||
NetworkMaster network = NetworkMasterRegistry.get(new BlockPos(message.controllerX, message.controllerY, message.controllerZ), player.worldObj.provider.getDimension());
|
|
||||||
|
|
||||||
if (network != null && network.canRun()) {
|
|
||||||
network.getStorageHandler().onCraftingRequested(message.id, message.quantity);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
package refinedstorage.network;
|
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
|
||||||
import net.minecraft.entity.player.EntityPlayerMP;
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
|
||||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
|
||||||
import refinedstorage.api.network.NetworkMaster;
|
|
||||||
import refinedstorage.api.network.NetworkMasterRegistry;
|
|
||||||
|
|
||||||
public class MessageWirelessGridHeldItemPush extends MessageHandlerPlayerToServer<MessageWirelessGridHeldItemPush> implements IMessage {
|
|
||||||
private int controllerX;
|
|
||||||
private int controllerY;
|
|
||||||
private int controllerZ;
|
|
||||||
private boolean one;
|
|
||||||
|
|
||||||
public MessageWirelessGridHeldItemPush() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public MessageWirelessGridHeldItemPush(int controllerX, int controllerY, int controllerZ, boolean one) {
|
|
||||||
this.controllerX = controllerX;
|
|
||||||
this.controllerY = controllerY;
|
|
||||||
this.controllerZ = controllerZ;
|
|
||||||
this.one = one;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void fromBytes(ByteBuf buf) {
|
|
||||||
controllerX = buf.readInt();
|
|
||||||
controllerY = buf.readInt();
|
|
||||||
controllerZ = buf.readInt();
|
|
||||||
one = buf.readBoolean();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void toBytes(ByteBuf buf) {
|
|
||||||
buf.writeInt(controllerX);
|
|
||||||
buf.writeInt(controllerY);
|
|
||||||
buf.writeInt(controllerZ);
|
|
||||||
buf.writeBoolean(one);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void handle(MessageWirelessGridHeldItemPush message, EntityPlayerMP player) {
|
|
||||||
NetworkMaster network = NetworkMasterRegistry.get(new BlockPos(message.controllerX, message.controllerY, message.controllerZ), player.worldObj.provider.getDimension());
|
|
||||||
|
|
||||||
if (network != null && network.canRun()) {
|
|
||||||
network.getStorageHandler().onHeldItemPush(message.one, player);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,54 +0,0 @@
|
|||||||
package refinedstorage.network;
|
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
|
||||||
import net.minecraft.entity.player.EntityPlayerMP;
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
|
||||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
|
||||||
import refinedstorage.api.network.NetworkMaster;
|
|
||||||
import refinedstorage.api.network.NetworkMasterRegistry;
|
|
||||||
|
|
||||||
public class MessageWirelessGridStoragePull extends MessageHandlerPlayerToServer<MessageWirelessGridStoragePull> implements IMessage {
|
|
||||||
private int controllerX;
|
|
||||||
private int controllerY;
|
|
||||||
private int controllerZ;
|
|
||||||
private int id;
|
|
||||||
private int flags;
|
|
||||||
|
|
||||||
public MessageWirelessGridStoragePull() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public MessageWirelessGridStoragePull(int controllerX, int controllerY, int controllerZ, int id, int flags) {
|
|
||||||
this.controllerX = controllerX;
|
|
||||||
this.controllerY = controllerY;
|
|
||||||
this.controllerZ = controllerZ;
|
|
||||||
this.id = id;
|
|
||||||
this.flags = flags;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void fromBytes(ByteBuf buf) {
|
|
||||||
controllerX = buf.readInt();
|
|
||||||
controllerY = buf.readInt();
|
|
||||||
controllerZ = buf.readInt();
|
|
||||||
id = buf.readInt();
|
|
||||||
flags = buf.readInt();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void toBytes(ByteBuf buf) {
|
|
||||||
buf.writeInt(controllerX);
|
|
||||||
buf.writeInt(controllerY);
|
|
||||||
buf.writeInt(controllerZ);
|
|
||||||
buf.writeInt(id);
|
|
||||||
buf.writeInt(flags);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void handle(MessageWirelessGridStoragePull message, EntityPlayerMP player) {
|
|
||||||
NetworkMaster network = NetworkMasterRegistry.get(new BlockPos(message.controllerX, message.controllerY, message.controllerZ), player.worldObj.provider.getDimension());
|
|
||||||
|
|
||||||
if (network != null && network.canRun()) {
|
|
||||||
network.getStorageHandler().onPull(message.id, message.flags, player);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -45,8 +45,8 @@ public class CommonProxy {
|
|||||||
|
|
||||||
RefinedStorage.NETWORK.registerMessage(MessageTileContainerUpdate.class, MessageTileContainerUpdate.class, id++, Side.CLIENT);
|
RefinedStorage.NETWORK.registerMessage(MessageTileContainerUpdate.class, MessageTileContainerUpdate.class, id++, Side.CLIENT);
|
||||||
RefinedStorage.NETWORK.registerMessage(MessageRedstoneModeUpdate.class, MessageRedstoneModeUpdate.class, id++, Side.SERVER);
|
RefinedStorage.NETWORK.registerMessage(MessageRedstoneModeUpdate.class, MessageRedstoneModeUpdate.class, id++, Side.SERVER);
|
||||||
RefinedStorage.NETWORK.registerMessage(MessageGridHeldItemPush.class, MessageGridHeldItemPush.class, id++, Side.SERVER);
|
RefinedStorage.NETWORK.registerMessage(MessageGridHeldPush.class, MessageGridHeldPush.class, id++, Side.SERVER);
|
||||||
RefinedStorage.NETWORK.registerMessage(MessageGridStoragePull.class, MessageGridStoragePull.class, id++, Side.SERVER);
|
RefinedStorage.NETWORK.registerMessage(MessageGridPull.class, MessageGridPull.class, id++, Side.SERVER);
|
||||||
RefinedStorage.NETWORK.registerMessage(MessageCompareUpdate.class, MessageCompareUpdate.class, id++, Side.SERVER);
|
RefinedStorage.NETWORK.registerMessage(MessageCompareUpdate.class, MessageCompareUpdate.class, id++, Side.SERVER);
|
||||||
RefinedStorage.NETWORK.registerMessage(MessageModeToggle.class, MessageModeToggle.class, id++, Side.SERVER);
|
RefinedStorage.NETWORK.registerMessage(MessageModeToggle.class, MessageModeToggle.class, id++, Side.SERVER);
|
||||||
RefinedStorage.NETWORK.registerMessage(MessageDetectorModeUpdate.class, MessageDetectorModeUpdate.class, id++, Side.SERVER);
|
RefinedStorage.NETWORK.registerMessage(MessageDetectorModeUpdate.class, MessageDetectorModeUpdate.class, id++, Side.SERVER);
|
||||||
@@ -56,10 +56,7 @@ public class CommonProxy {
|
|||||||
RefinedStorage.NETWORK.registerMessage(MessageGridSettingsUpdate.class, MessageGridSettingsUpdate.class, id++, Side.SERVER);
|
RefinedStorage.NETWORK.registerMessage(MessageGridSettingsUpdate.class, MessageGridSettingsUpdate.class, id++, Side.SERVER);
|
||||||
RefinedStorage.NETWORK.registerMessage(MessageGridCraftingTransfer.class, MessageGridCraftingTransfer.class, id++, Side.SERVER);
|
RefinedStorage.NETWORK.registerMessage(MessageGridCraftingTransfer.class, MessageGridCraftingTransfer.class, id++, Side.SERVER);
|
||||||
RefinedStorage.NETWORK.registerMessage(MessageWirelessGridSettingsUpdate.class, MessageWirelessGridSettingsUpdate.class, id++, Side.SERVER);
|
RefinedStorage.NETWORK.registerMessage(MessageWirelessGridSettingsUpdate.class, MessageWirelessGridSettingsUpdate.class, id++, Side.SERVER);
|
||||||
RefinedStorage.NETWORK.registerMessage(MessageWirelessGridHeldItemPush.class, MessageWirelessGridHeldItemPush.class, id++, Side.SERVER);
|
|
||||||
RefinedStorage.NETWORK.registerMessage(MessageWirelessGridStoragePull.class, MessageWirelessGridStoragePull.class, id++, Side.SERVER);
|
|
||||||
RefinedStorage.NETWORK.registerMessage(MessageGridCraftingStart.class, MessageGridCraftingStart.class, id++, Side.SERVER);
|
RefinedStorage.NETWORK.registerMessage(MessageGridCraftingStart.class, MessageGridCraftingStart.class, id++, Side.SERVER);
|
||||||
RefinedStorage.NETWORK.registerMessage(MessageWirelessGridCraftingStart.class, MessageWirelessGridCraftingStart.class, id++, Side.SERVER);
|
|
||||||
RefinedStorage.NETWORK.registerMessage(MessageGridPatternCreate.class, MessageGridPatternCreate.class, id++, Side.SERVER);
|
RefinedStorage.NETWORK.registerMessage(MessageGridPatternCreate.class, MessageGridPatternCreate.class, id++, Side.SERVER);
|
||||||
RefinedStorage.NETWORK.registerMessage(MessageCraftingMonitorCancel.class, MessageCraftingMonitorCancel.class, id++, Side.SERVER);
|
RefinedStorage.NETWORK.registerMessage(MessageCraftingMonitorCancel.class, MessageCraftingMonitorCancel.class, id++, Side.SERVER);
|
||||||
RefinedStorage.NETWORK.registerMessage(MessageGridItems.class, MessageGridItems.class, id++, Side.CLIENT);
|
RefinedStorage.NETWORK.registerMessage(MessageGridItems.class, MessageGridItems.class, id++, Side.CLIENT);
|
||||||
|
|||||||
@@ -1,21 +0,0 @@
|
|||||||
package refinedstorage.tile;
|
|
||||||
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
|
|
||||||
public final class ClientItem {
|
|
||||||
private int id;
|
|
||||||
private ItemStack stack;
|
|
||||||
|
|
||||||
public ClientItem(int id, ItemStack stack) {
|
|
||||||
this.id = id;
|
|
||||||
this.stack = stack;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ItemStack getStack() {
|
|
||||||
return stack;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -19,17 +19,11 @@ public class StorageHandler {
|
|||||||
this.network = network;
|
this.network = network;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onPull(int id, int flags, EntityPlayerMP player) {
|
public void onPull(ItemStack stack, int flags, EntityPlayerMP player) {
|
||||||
if (player.inventory.getItemStack() != null) {
|
if (player.inventory.getItemStack() != null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (id < 0 || id > network.getItems().size() - 1) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ItemStack stack = network.getItems().get(id);
|
|
||||||
|
|
||||||
int size = 64;
|
int size = 64;
|
||||||
|
|
||||||
if (GridPullFlags.isPullingHalf(flags) && stack.stackSize > 1) {
|
if (GridPullFlags.isPullingHalf(flags) && stack.stackSize > 1) {
|
||||||
@@ -62,15 +56,19 @@ public class StorageHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onHeldItemPush(boolean one, EntityPlayerMP player) {
|
public ItemStack onPush(ItemStack stack) {
|
||||||
|
return network.push(stack, stack.stackSize, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onHeldItemPush(boolean single, EntityPlayerMP player) {
|
||||||
if (player.inventory.getItemStack() == null) {
|
if (player.inventory.getItemStack() == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemStack stack = player.inventory.getItemStack();
|
ItemStack stack = player.inventory.getItemStack();
|
||||||
int size = one ? 1 : stack.stackSize;
|
int size = single ? 1 : stack.stackSize;
|
||||||
|
|
||||||
if (one) {
|
if (single) {
|
||||||
if (network.push(stack, size, true) == null) {
|
if (network.push(stack, size, true) == null) {
|
||||||
network.push(stack, size, false);
|
network.push(stack, size, false);
|
||||||
|
|
||||||
@@ -89,30 +87,30 @@ public class StorageHandler {
|
|||||||
network.getWirelessGridHandler().drainEnergy(player, ItemWirelessGrid.USAGE_PUSH);
|
network.getWirelessGridHandler().drainEnergy(player, ItemWirelessGrid.USAGE_PUSH);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onCraftingRequested(int id, int quantity) {
|
public void onCraftingRequested(ItemStack stack, int quantity) {
|
||||||
if (id >= 0 && id < network.getItems().size() && quantity > 0 && quantity <= MAX_CRAFTING_PER_REQUEST) {
|
if (quantity <= 0 || quantity > MAX_CRAFTING_PER_REQUEST) {
|
||||||
ItemStack requested = network.getItems().get(id);
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
int quantityPerRequest = 0;
|
int quantityPerRequest = 0;
|
||||||
|
|
||||||
CraftingPattern pattern = network.getPatternWithBestScore(requested);
|
CraftingPattern pattern = network.getPatternWithBestScore(stack);
|
||||||
|
|
||||||
if (pattern != null) {
|
if (pattern != null) {
|
||||||
for (ItemStack output : pattern.getOutputs()) {
|
for (ItemStack output : pattern.getOutputs()) {
|
||||||
if (RefinedStorageUtils.compareStackNoQuantity(requested, output)) {
|
if (RefinedStorageUtils.compareStackNoQuantity(stack, output)) {
|
||||||
quantityPerRequest += output.stackSize;
|
quantityPerRequest += output.stackSize;
|
||||||
|
|
||||||
if (!pattern.isProcessing()) {
|
if (!pattern.isProcessing()) {
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
while (quantity > 0) {
|
while (quantity > 0) {
|
||||||
network.addCraftingTaskAsLast(network.createCraftingTask(pattern));
|
network.addCraftingTaskAsLast(network.createCraftingTask(pattern));
|
||||||
|
|
||||||
quantity -= quantityPerRequest;
|
quantity -= quantityPerRequest;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,28 +1,23 @@
|
|||||||
package refinedstorage.tile.grid;
|
package refinedstorage.tile.grid;
|
||||||
|
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import refinedstorage.block.EnumGridType;
|
import refinedstorage.block.EnumGridType;
|
||||||
import refinedstorage.tile.ClientItem;
|
|
||||||
import refinedstorage.tile.config.IRedstoneModeConfig;
|
import refinedstorage.tile.config.IRedstoneModeConfig;
|
||||||
|
import refinedstorage.tile.controller.StorageHandler;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface IGrid {
|
public interface IGrid {
|
||||||
EnumGridType getType();
|
EnumGridType getType();
|
||||||
|
|
||||||
List<ClientItem> getItems();
|
List<ItemStack> getItems();
|
||||||
|
|
||||||
void setItems(List<ClientItem> items);
|
void setItems(List<ItemStack> items);
|
||||||
|
|
||||||
BlockPos getControllerPos();
|
BlockPos getNetworkPosition();
|
||||||
|
|
||||||
ItemStack onItemPush(EntityPlayer player, ItemStack stack);
|
StorageHandler getStorageHandler();
|
||||||
|
|
||||||
void onHeldItemPush(boolean one);
|
|
||||||
|
|
||||||
void onItemPull(int id, int flags);
|
|
||||||
|
|
||||||
int getSortingType();
|
int getSortingType();
|
||||||
|
|
||||||
@@ -36,9 +31,7 @@ public interface IGrid {
|
|||||||
|
|
||||||
void onSearchBoxModeChanged(int searchBoxMode);
|
void onSearchBoxModeChanged(int searchBoxMode);
|
||||||
|
|
||||||
void onCraftingRequested(int id, int quantity);
|
IRedstoneModeConfig getRedstoneModeConfig();
|
||||||
|
|
||||||
IRedstoneModeConfig getRedstoneModeSetting();
|
|
||||||
|
|
||||||
boolean isConnected();
|
boolean isConnected();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,13 +20,10 @@ import refinedstorage.container.ContainerGrid;
|
|||||||
import refinedstorage.inventory.BasicItemHandler;
|
import refinedstorage.inventory.BasicItemHandler;
|
||||||
import refinedstorage.inventory.BasicItemValidator;
|
import refinedstorage.inventory.BasicItemValidator;
|
||||||
import refinedstorage.item.ItemPattern;
|
import refinedstorage.item.ItemPattern;
|
||||||
import refinedstorage.network.MessageGridCraftingStart;
|
|
||||||
import refinedstorage.network.MessageGridHeldItemPush;
|
|
||||||
import refinedstorage.network.MessageGridSettingsUpdate;
|
import refinedstorage.network.MessageGridSettingsUpdate;
|
||||||
import refinedstorage.network.MessageGridStoragePull;
|
|
||||||
import refinedstorage.tile.ClientItem;
|
|
||||||
import refinedstorage.tile.TileSlave;
|
import refinedstorage.tile.TileSlave;
|
||||||
import refinedstorage.tile.config.IRedstoneModeConfig;
|
import refinedstorage.tile.config.IRedstoneModeConfig;
|
||||||
|
import refinedstorage.tile.controller.StorageHandler;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -69,7 +66,8 @@ public class TileGrid extends TileSlave implements IGrid {
|
|||||||
private int sortingType = SORTING_TYPE_NAME;
|
private int sortingType = SORTING_TYPE_NAME;
|
||||||
private int searchBoxMode = SEARCH_BOX_MODE_NORMAL;
|
private int searchBoxMode = SEARCH_BOX_MODE_NORMAL;
|
||||||
|
|
||||||
private List<ClientItem> items = new ArrayList<ClientItem>();
|
// Used clientside only
|
||||||
|
private List<ItemStack> items = new ArrayList<ItemStack>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getEnergyUsage() {
|
public int getEnergyUsage() {
|
||||||
@@ -98,17 +96,17 @@ public class TileGrid extends TileSlave implements IGrid {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ClientItem> getItems() {
|
public List<ItemStack> getItems() {
|
||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setItems(List<ClientItem> items) {
|
public void setItems(List<ItemStack> items) {
|
||||||
this.items = items;
|
this.items = items;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BlockPos getControllerPos() {
|
public BlockPos getNetworkPosition() {
|
||||||
return network != null ? network.getPosition() : null;
|
return network != null ? network.getPosition() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,18 +117,8 @@ public class TileGrid extends TileSlave implements IGrid {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack onItemPush(EntityPlayer player, ItemStack stack) {
|
public StorageHandler getStorageHandler() {
|
||||||
return isConnected() ? network.push(stack, stack.stackSize, false) : stack;
|
return isConnected() ? network.getStorageHandler() : null;
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onHeldItemPush(boolean one) {
|
|
||||||
RefinedStorage.NETWORK.sendToServer(new MessageGridHeldItemPush(getPos().getX(), getPos().getY(), getPos().getZ(), one));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onItemPull(int id, int flags) {
|
|
||||||
RefinedStorage.NETWORK.sendToServer(new MessageGridStoragePull(getPos().getX(), getPos().getY(), getPos().getZ(), id, flags));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public InventoryCrafting getMatrix() {
|
public InventoryCrafting getMatrix() {
|
||||||
@@ -318,12 +306,7 @@ public class TileGrid extends TileSlave implements IGrid {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCraftingRequested(int id, int quantity) {
|
public IRedstoneModeConfig getRedstoneModeConfig() {
|
||||||
RefinedStorage.NETWORK.sendToServer(new MessageGridCraftingStart(getPos().getX(), getPos().getY(), getPos().getZ(), id, quantity));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IRedstoneModeConfig getRedstoneModeSetting() {
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,12 +11,9 @@ import refinedstorage.api.network.NetworkMaster;
|
|||||||
import refinedstorage.api.network.NetworkMasterRegistry;
|
import refinedstorage.api.network.NetworkMasterRegistry;
|
||||||
import refinedstorage.block.EnumGridType;
|
import refinedstorage.block.EnumGridType;
|
||||||
import refinedstorage.item.ItemWirelessGrid;
|
import refinedstorage.item.ItemWirelessGrid;
|
||||||
import refinedstorage.network.MessageWirelessGridCraftingStart;
|
|
||||||
import refinedstorage.network.MessageWirelessGridHeldItemPush;
|
|
||||||
import refinedstorage.network.MessageWirelessGridSettingsUpdate;
|
import refinedstorage.network.MessageWirelessGridSettingsUpdate;
|
||||||
import refinedstorage.network.MessageWirelessGridStoragePull;
|
|
||||||
import refinedstorage.tile.ClientItem;
|
|
||||||
import refinedstorage.tile.config.IRedstoneModeConfig;
|
import refinedstorage.tile.config.IRedstoneModeConfig;
|
||||||
|
import refinedstorage.tile.controller.StorageHandler;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -28,7 +25,7 @@ public class WirelessGrid implements IGrid {
|
|||||||
private int sortingType;
|
private int sortingType;
|
||||||
private int sortingDirection;
|
private int sortingDirection;
|
||||||
private int searchBoxMode;
|
private int searchBoxMode;
|
||||||
private List<ClientItem> items = new ArrayList<ClientItem>();
|
private List<ItemStack> items = new ArrayList<ItemStack>();
|
||||||
private long lastUpdate;
|
private long lastUpdate;
|
||||||
|
|
||||||
public WirelessGrid(World world, ItemStack stack, EnumHand hand) {
|
public WirelessGrid(World world, ItemStack stack, EnumHand hand) {
|
||||||
@@ -46,46 +43,34 @@ public class WirelessGrid implements IGrid {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ClientItem> getItems() {
|
public List<ItemStack> getItems() {
|
||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setItems(List<ClientItem> items) {
|
public void setItems(List<ItemStack> items) {
|
||||||
this.items = items;
|
this.items = items;
|
||||||
this.lastUpdate = System.currentTimeMillis();
|
this.lastUpdate = System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BlockPos getControllerPos() {
|
public BlockPos getNetworkPosition() {
|
||||||
return controllerPos;
|
return controllerPos;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack onItemPush(EntityPlayer player, ItemStack stack) {
|
public StorageHandler getStorageHandler() {
|
||||||
NetworkMaster network = NetworkMasterRegistry.get(controllerPos, player.worldObj.provider.getDimension());
|
NetworkMaster network = NetworkMasterRegistry.get(controllerPos, world.provider.getDimension());
|
||||||
|
|
||||||
if (network != null && network.canRun()) {
|
if (network != null) {
|
||||||
network.getWirelessGridHandler().drainEnergy(player, ItemWirelessGrid.USAGE_PUSH);
|
return network.getStorageHandler();
|
||||||
|
|
||||||
return network.push(stack, stack.stackSize, false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return stack;
|
return null;
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onHeldItemPush(boolean one) {
|
|
||||||
RefinedStorage.NETWORK.sendToServer(new MessageWirelessGridHeldItemPush(controllerPos.getX(), controllerPos.getY(), controllerPos.getZ(), one));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onItemPull(int id, int flags) {
|
|
||||||
RefinedStorage.NETWORK.sendToServer(new MessageWirelessGridStoragePull(controllerPos.getX(), controllerPos.getY(), controllerPos.getZ(), id, flags));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onClose(EntityPlayer player) {
|
public void onClose(EntityPlayer player) {
|
||||||
NetworkMaster network = NetworkMasterRegistry.get(controllerPos, player.worldObj.provider.getDimension());
|
NetworkMaster network = NetworkMasterRegistry.get(controllerPos, world.provider.getDimension());
|
||||||
|
|
||||||
if (network != null) {
|
if (network != null) {
|
||||||
network.getWirelessGridHandler().handleClose(player);
|
network.getWirelessGridHandler().handleClose(player);
|
||||||
@@ -129,12 +114,7 @@ public class WirelessGrid implements IGrid {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCraftingRequested(int id, int quantity) {
|
public IRedstoneModeConfig getRedstoneModeConfig() {
|
||||||
RefinedStorage.NETWORK.sendToServer(new MessageWirelessGridCraftingStart(controllerPos.getX(), controllerPos.getY(), controllerPos.getZ(), id, quantity));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IRedstoneModeConfig getRedstoneModeSetting() {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user