Fix crafting monitors

This commit is contained in:
Raoul Van den Berge
2016-11-04 13:07:12 +01:00
parent 6272d692ed
commit e4a189ea09
16 changed files with 182 additions and 172 deletions

View File

@@ -167,30 +167,7 @@ public interface INetworkMaster {
* @param toSchedule the amount of tasks to schedule
* @param compare the compare value to find patterns
*/
default void scheduleCraftingTask(ItemStack stack, int toSchedule, int compare) {
int alreadyScheduled = 0;
for (ICraftingTask task : getCraftingTasks()) {
for (ItemStack output : task.getPattern().getOutputs()) {
if (API.instance().getComparer().isEqual(output, stack, compare)) {
alreadyScheduled++;
}
}
}
for (int i = 0; i < toSchedule - alreadyScheduled; ++i) {
ICraftingPattern pattern = getPattern(stack, compare);
if (pattern != null) {
ICraftingTask task = createCraftingTask(stack, pattern, 1);
task.calculate();
task.getMissing().clear();
addCraftingTask(task);
}
}
}
void scheduleCraftingTask(ItemStack stack, int toSchedule, int compare);
/**
* Sends a grid update packet with all the items to all clients that are watching a grid connected to this network.
@@ -228,11 +205,26 @@ public interface INetworkMaster {
*/
void sendFluidStorageDeltaToClient(FluidStack stack, int delta);
/**
* Makes the network send a crafting monitor update to all players as soon as it can.
*/
void markCraftingMonitorForUpdate();
/**
* Sends a crafting monitor update to all players that are watching a crafting monitor.
* <p>
* WARNING: In most cases, you should just use {@link INetworkMaster#markCraftingMonitorForUpdate()}, if not,
* you can get high bandwidth usage.
*/
void sendCraftingMonitorUpdate();
/**
* Sends a crafting monitor update to a specific player.
*
* @param player the player
*/
void sendCraftingMonitorUpdate(EntityPlayerMP player);
/**
* Inserts an item in this network.
*

View File

@@ -132,7 +132,7 @@ public abstract class CraftingStep implements ICraftingStep {
satisfied.put(hashcode, received + toReceive);
stack.stackSize -= toReceive;
network.sendCraftingMonitorUpdate();
network.markCraftingMonitorForUpdate();
if (stack.stackSize == 0) {
return true;

View File

@@ -270,7 +270,7 @@ public class CraftingTask implements ICraftingTask {
network.insertFluid(stack, stack.amount, false);
}
network.sendCraftingMonitorUpdate();
network.markCraftingMonitorForUpdate();
}
@Override
@@ -307,7 +307,7 @@ public class CraftingTask implements ICraftingTask {
if (stackExtracted != null) {
toTakeFluids.remove(stack, stack.amount, false);
tookFluids.add(stackExtracted);
network.sendCraftingMonitorUpdate();
network.markCraftingMonitorForUpdate();
}
}
@@ -326,7 +326,7 @@ public class CraftingTask implements ICraftingTask {
step.setStartedProcessing();
step.execute(toInsertItems, toInsertFluids);
usedContainers.put(container, timesUsed);
network.sendCraftingMonitorUpdate();
network.markCraftingMonitorForUpdate();
}
}
}
@@ -370,7 +370,7 @@ public class CraftingTask implements ICraftingTask {
if (quantity > 0) {
calculate();
}
network.sendCraftingMonitorUpdate();
network.markCraftingMonitorForUpdate();
}
}

View File

@@ -26,6 +26,8 @@ public class BlockCraftingMonitor extends BlockNode {
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) {
if (!world.isRemote) {
player.openGui(RS.INSTANCE, RSGui.CRAFTING_MONITOR, world, pos.getX(), pos.getY(), pos.getZ());
((TileCraftingMonitor) world.getTileEntity(pos)).onOpened(player);
}
return true;

View File

@@ -60,7 +60,7 @@ public class BlockGrid extends BlockNode {
if (!world.isRemote) {
player.openGui(RS.INSTANCE, RSGui.GRID, world, pos.getX(), pos.getY(), pos.getZ());
((TileGrid) world.getTileEntity(pos)).onGridOpened(player);
((TileGrid) world.getTileEntity(pos)).onOpened(player);
}
return true;

View File

@@ -1,12 +1,20 @@
package com.raoulvdberge.refinedstorage.container;
import com.raoulvdberge.refinedstorage.tile.craftingmonitor.TileCraftingMonitor;
import com.raoulvdberge.refinedstorage.tile.craftingmonitor.ICraftingMonitor;
import net.minecraft.entity.player.EntityPlayer;
public class ContainerCraftingMonitor extends ContainerBase {
public ContainerCraftingMonitor(TileCraftingMonitor craftingMonitor, EntityPlayer player) {
super(craftingMonitor, player);
private ICraftingMonitor craftingMonitor;
public ContainerCraftingMonitor(ICraftingMonitor craftingMonitor, EntityPlayer player) {
super(null, player);
this.craftingMonitor = craftingMonitor;
addPlayerInventory(8, 148);
}
public ICraftingMonitor getCraftingMonitor() {
return craftingMonitor;
}
}

View File

@@ -1,11 +1,12 @@
package com.raoulvdberge.refinedstorage.gui;
import com.raoulvdberge.refinedstorage.RS;
import com.raoulvdberge.refinedstorage.api.autocrafting.craftingmonitor.ICraftingMonitorElement;
import com.raoulvdberge.refinedstorage.api.render.IElementDrawer;
import com.raoulvdberge.refinedstorage.api.render.IElementDrawers;
import com.raoulvdberge.refinedstorage.container.ContainerCraftingMonitor;
import com.raoulvdberge.refinedstorage.gui.sidebutton.SideButtonRedstoneMode;
import com.raoulvdberge.refinedstorage.tile.craftingmonitor.ICraftingMonitor;
import com.raoulvdberge.refinedstorage.network.MessageCraftingMonitorCancel;
import com.raoulvdberge.refinedstorage.tile.craftingmonitor.TileCraftingMonitor;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.renderer.GlStateManager;
@@ -13,8 +14,12 @@ import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.resources.I18n;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
public class GuiCraftingMonitor extends GuiBase {
public static List<ICraftingMonitorElement> ELEMENTS = Collections.emptyList();
public class CraftingMonitorElementDrawers extends ElementDrawers {
private IElementDrawer<Integer> overlayDrawer = (x, y, colour) -> {
GlStateManager.color(1, 1, 1, 1);
@@ -33,8 +38,6 @@ public class GuiCraftingMonitor extends GuiBase {
private static final int ITEM_WIDTH = 143;
private static final int ITEM_HEIGHT = 18;
private ICraftingMonitor craftingMonitor;
private GuiButton cancelButton;
private GuiButton cancelAllButton;
@@ -45,11 +48,9 @@ public class GuiCraftingMonitor extends GuiBase {
private int itemSelectedX = -1;
private int itemSelectedY = -1;
public GuiCraftingMonitor(ContainerCraftingMonitor container, ICraftingMonitor craftingMonitor) {
public GuiCraftingMonitor(ContainerCraftingMonitor container) {
super(container, 176, 230);
this.craftingMonitor = craftingMonitor;
this.scrollbar = new Scrollbar(157, 20, 12, 89);
}
@@ -72,12 +73,12 @@ public class GuiCraftingMonitor extends GuiBase {
scrollbar.setEnabled(getRows() > VISIBLE_ROWS);
scrollbar.setMaxOffset(getRows() - VISIBLE_ROWS);
if (itemSelected >= craftingMonitor.getElements().size()) {
if (itemSelected >= ELEMENTS.size()) {
itemSelected = -1;
}
cancelButton.enabled = itemSelected != -1 && craftingMonitor.getElements().get(itemSelected).getTaskId() != -1;
cancelAllButton.enabled = craftingMonitor.getElements().size() > 0;
cancelButton.enabled = itemSelected != -1 && ELEMENTS.get(itemSelected).getTaskId() != -1;
cancelAllButton.enabled = ELEMENTS.size() > 0;
}
@Override
@@ -89,8 +90,8 @@ public class GuiCraftingMonitor extends GuiBase {
if (itemSelectedX != -1 &&
itemSelectedY != -1 &&
itemSelected >= 0 &&
itemSelected < craftingMonitor.getElements().size() &&
craftingMonitor.getElements().get(itemSelected).canDrawSelection()) {
itemSelected < ELEMENTS.size() &&
ELEMENTS.get(itemSelected).canDrawSelection()) {
drawTexture(x + itemSelectedX, y + itemSelectedY, 0, 232, ITEM_WIDTH, ITEM_HEIGHT);
}
}
@@ -113,8 +114,8 @@ public class GuiCraftingMonitor extends GuiBase {
String itemSelectedTooltip = null;
for (int i = 0; i < VISIBLE_ROWS; ++i) {
if (item < craftingMonitor.getElements().size()) {
ICraftingMonitorElement element = craftingMonitor.getElements().get(item);
if (item < ELEMENTS.size()) {
ICraftingMonitorElement element = ELEMENTS.get(item);
if (item == itemSelected) {
itemSelectedX = x;
@@ -140,7 +141,7 @@ public class GuiCraftingMonitor extends GuiBase {
}
private int getRows() {
return craftingMonitor.getElements().size();
return ELEMENTS.size();
}
@Override
@@ -148,13 +149,13 @@ public class GuiCraftingMonitor extends GuiBase {
super.actionPerformed(button);
if (button == cancelButton && itemSelected != -1) {
ICraftingMonitorElement element = craftingMonitor.getElements().get(itemSelected);
ICraftingMonitorElement element = ELEMENTS.get(itemSelected);
if (element.getTaskId() != -1) {
craftingMonitor.onCancelled(element);
RS.INSTANCE.network.sendToServer(new MessageCraftingMonitorCancel(element.getTaskId()));
}
} else if (button == cancelAllButton && craftingMonitor.getElements().size() > 0) {
craftingMonitor.onCancelledAll();
} else if (button == cancelAllButton && ELEMENTS.size() > 0) {
RS.INSTANCE.network.sendToServer(new MessageCraftingMonitorCancel(-1));
}
}
@@ -171,7 +172,7 @@ public class GuiCraftingMonitor extends GuiBase {
int ix = 8;
int iy = 20 + (i * ITEM_HEIGHT);
if (inBounds(ix, iy, ITEM_WIDTH, ITEM_HEIGHT, mouseX - guiLeft, mouseY - guiTop) && (item + i) < craftingMonitor.getElements().size()) {
if (inBounds(ix, iy, ITEM_WIDTH, ITEM_HEIGHT, mouseX - guiLeft, mouseY - guiTop) && (item + i) < ELEMENTS.size()) {
itemSelected = item + i;
}
}

View File

@@ -111,7 +111,7 @@ public class GuiHandler implements IGuiHandler {
case RSGui.INTERFACE:
return new GuiInterface((ContainerInterface) getContainer(ID, player, tile));
case RSGui.CRAFTING_MONITOR:
return new GuiCraftingMonitor((ContainerCraftingMonitor) getContainer(ID, player, tile), (TileCraftingMonitor) tile);
return new GuiCraftingMonitor((ContainerCraftingMonitor) getContainer(ID, player, tile));
case RSGui.WIRELESS_TRANSMITTER:
return new GuiWirelessTransmitter((ContainerWirelessTransmitter) getContainer(ID, player, tile));
case RSGui.CRAFTER:

View File

@@ -1,55 +1,34 @@
package com.raoulvdberge.refinedstorage.network;
import com.raoulvdberge.refinedstorage.tile.craftingmonitor.TileCraftingMonitor;
import com.raoulvdberge.refinedstorage.container.ContainerCraftingMonitor;
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;
public class MessageCraftingMonitorCancel extends MessageHandlerPlayerToServer<MessageCraftingMonitorCancel> implements IMessage {
private int x;
private int y;
private int z;
private int id;
private int depth;
public MessageCraftingMonitorCancel() {
}
public MessageCraftingMonitorCancel(TileCraftingMonitor craftingMonitor, int id) {
this.x = craftingMonitor.getPos().getX();
this.y = craftingMonitor.getPos().getY();
this.z = craftingMonitor.getPos().getZ();
public MessageCraftingMonitorCancel(int id) {
this.id = id;
}
@Override
public void fromBytes(ByteBuf buf) {
x = buf.readInt();
y = buf.readInt();
z = buf.readInt();
id = buf.readInt();
}
@Override
public void toBytes(ByteBuf buf) {
buf.writeInt(x);
buf.writeInt(y);
buf.writeInt(z);
buf.writeInt(id);
}
@Override
public void handle(MessageCraftingMonitorCancel message, EntityPlayerMP player) {
TileEntity tile = player.worldObj.getTileEntity(new BlockPos(message.x, message.y, message.z));
if (tile instanceof TileCraftingMonitor) {
TileCraftingMonitor monitor = (TileCraftingMonitor) tile;
if (monitor.isConnected()) {
monitor.getNetwork().getItemGridHandler().onCraftingCancelRequested(message.id);
}
if (player.openContainer instanceof ContainerCraftingMonitor) {
((ContainerCraftingMonitor) player.openContainer).getCraftingMonitor().onCancelled(message.id);
}
}
}

View File

@@ -0,0 +1,56 @@
package com.raoulvdberge.refinedstorage.network;
import com.raoulvdberge.refinedstorage.api.autocrafting.craftingmonitor.ICraftingMonitorElement;
import com.raoulvdberge.refinedstorage.apiimpl.API;
import com.raoulvdberge.refinedstorage.gui.GuiCraftingMonitor;
import io.netty.buffer.ByteBuf;
import net.minecraftforge.fml.common.network.ByteBufUtils;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
public class MessageCraftingMonitorElements implements IMessage, IMessageHandler<MessageCraftingMonitorElements, IMessage> {
private List<ICraftingMonitorElement> elements = new ArrayList<>();
public MessageCraftingMonitorElements() {
}
public MessageCraftingMonitorElements(List<ICraftingMonitorElement> elements) {
this.elements = elements;
}
@Override
public void fromBytes(ByteBuf buf) {
int size = buf.readInt();
for (int i = 0; i < size; ++i) {
Function<ByteBuf, ICraftingMonitorElement> factory = API.instance().getCraftingMonitorElementRegistry().getFactory(ByteBufUtils.readUTF8String(buf));
if (factory != null) {
elements.add(factory.apply(buf));
}
}
}
@Override
public void toBytes(ByteBuf buf) {
buf.writeInt(elements.size());
for (ICraftingMonitorElement task : elements) {
ByteBufUtils.writeUTF8String(buf, task.getId());
task.write(buf);
}
}
@Override
public IMessage onMessage(MessageCraftingMonitorElements message, MessageContext ctx) {
GuiCraftingMonitor.ELEMENTS = message.elements;
return null;
}
}

View File

@@ -85,6 +85,7 @@ public class ProxyCommon {
RS.INSTANCE.network.registerMessage(MessageGridCraftingStart.class, MessageGridCraftingStart.class, id++, Side.SERVER);
RS.INSTANCE.network.registerMessage(MessageGridPatternCreate.class, MessageGridPatternCreate.class, id++, Side.SERVER);
RS.INSTANCE.network.registerMessage(MessageCraftingMonitorCancel.class, MessageCraftingMonitorCancel.class, id++, Side.SERVER);
RS.INSTANCE.network.registerMessage(MessageCraftingMonitorElements.class, MessageCraftingMonitorElements.class, id++, Side.CLIENT);
RS.INSTANCE.network.registerMessage(MessageGridItemUpdate.class, MessageGridItemUpdate.class, id++, Side.CLIENT);
RS.INSTANCE.network.registerMessage(MessageGridItemDelta.class, MessageGridItemDelta.class, id++, Side.CLIENT);
RS.INSTANCE.network.registerMessage(MessageGridFluidUpdate.class, MessageGridFluidUpdate.class, id++, Side.CLIENT);

View File

@@ -35,6 +35,7 @@ import com.raoulvdberge.refinedstorage.apiimpl.storage.item.ItemStorageCache;
import com.raoulvdberge.refinedstorage.block.BlockController;
import com.raoulvdberge.refinedstorage.block.EnumControllerType;
import com.raoulvdberge.refinedstorage.block.EnumGridType;
import com.raoulvdberge.refinedstorage.container.ContainerCraftingMonitor;
import com.raoulvdberge.refinedstorage.container.ContainerGrid;
import com.raoulvdberge.refinedstorage.integration.forgeenergy.ControllerEnergyForge;
import com.raoulvdberge.refinedstorage.integration.ic2.ControllerEnergyIC2;
@@ -43,13 +44,9 @@ import com.raoulvdberge.refinedstorage.integration.ic2.IControllerEnergyIC2;
import com.raoulvdberge.refinedstorage.integration.ic2.IntegrationIC2;
import com.raoulvdberge.refinedstorage.integration.tesla.ControllerEnergyTesla;
import com.raoulvdberge.refinedstorage.integration.tesla.IntegrationTesla;
import com.raoulvdberge.refinedstorage.network.MessageGridFluidDelta;
import com.raoulvdberge.refinedstorage.network.MessageGridFluidUpdate;
import com.raoulvdberge.refinedstorage.network.MessageGridItemDelta;
import com.raoulvdberge.refinedstorage.network.MessageGridItemUpdate;
import com.raoulvdberge.refinedstorage.network.*;
import com.raoulvdberge.refinedstorage.tile.config.IRedstoneConfigurable;
import com.raoulvdberge.refinedstorage.tile.config.RedstoneMode;
import com.raoulvdberge.refinedstorage.tile.craftingmonitor.TileCraftingMonitor;
import com.raoulvdberge.refinedstorage.tile.data.ITileDataProducer;
import com.raoulvdberge.refinedstorage.tile.data.RSSerializers;
import com.raoulvdberge.refinedstorage.tile.data.TileDataParameter;
@@ -77,6 +74,7 @@ import net.minecraftforge.items.ItemHandlerHelper;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.*;
import java.util.stream.Collectors;
public class TileController extends TileBase implements INetworkMaster, IEnergyReceiver, IRedstoneConfigurable {
public static final TileDataParameter<Integer> REDSTONE_MODE = RedstoneMode.createParameter();
@@ -288,11 +286,7 @@ public class TileController extends TileBase implements INetworkMaster, IEnergyR
if (craftingMonitorUpdateRequested) {
craftingMonitorUpdateRequested = false;
for (INetworkNode node : nodeGraph.all()) {
if (node instanceof TileCraftingMonitor) {
((TileCraftingMonitor) node).dataManager.sendParameterToWatchers(TileCraftingMonitor.ELEMENTS);
}
}
sendCraftingMonitorUpdate();
}
}
@@ -328,10 +322,24 @@ public class TileController extends TileBase implements INetworkMaster, IEnergyR
}
@Override
public void sendCraftingMonitorUpdate() {
public void markCraftingMonitorForUpdate() {
craftingMonitorUpdateRequested = true;
}
@Override
public void sendCraftingMonitorUpdate() {
worldObj.getMinecraftServer().getPlayerList().getPlayerList().stream()
.filter(player -> player.openContainer instanceof ContainerCraftingMonitor)
.forEach(this::sendCraftingMonitorUpdate);
}
@Override
public void sendCraftingMonitorUpdate(EntityPlayerMP player) {
RS.INSTANCE.network.sendTo(new MessageCraftingMonitorElements(
craftingTasks.stream().flatMap(t -> t.getCraftingMonitorElements().stream()).collect(Collectors.toList())
), player);
}
@Override
public void invalidate() {
super.invalidate();
@@ -448,6 +456,40 @@ public class TileController extends TileBase implements INetworkMaster, IEnergyR
return patterns.get(highestPattern);
}
@Override
public void scheduleCraftingTask(ItemStack stack, int toSchedule, int compare) {
int alreadyScheduled = 0;
for (ICraftingTask task : getCraftingTasks()) {
for (ItemStack output : task.getPattern().getOutputs()) {
if (API.instance().getComparer().isEqual(output, stack, compare)) {
alreadyScheduled++;
}
}
}
boolean scheduled = false;
for (int i = 0; i < toSchedule - alreadyScheduled; ++i) {
ICraftingPattern pattern = getPattern(stack, compare);
if (pattern != null) {
ICraftingTask task = createCraftingTask(stack, pattern, 1);
task.calculate();
task.getMissing().clear();
addCraftingTask(task);
scheduled = true;
}
}
if (scheduled) {
markCraftingMonitorForUpdate();
}
}
@Override
public void rebuildPatterns() {
patterns.clear();

View File

@@ -1,13 +1,5 @@
package com.raoulvdberge.refinedstorage.tile.craftingmonitor;
import com.raoulvdberge.refinedstorage.api.autocrafting.craftingmonitor.ICraftingMonitorElement;
import java.util.List;
public interface ICraftingMonitor {
void onCancelled(ICraftingMonitorElement element);
void onCancelledAll();
List<ICraftingMonitorElement> getElements();
void onCancelled(int id);
}

View File

@@ -1,33 +1,11 @@
package com.raoulvdberge.refinedstorage.tile.craftingmonitor;
import com.raoulvdberge.refinedstorage.RS;
import com.raoulvdberge.refinedstorage.api.autocrafting.craftingmonitor.ICraftingMonitorElement;
import com.raoulvdberge.refinedstorage.network.MessageCraftingMonitorCancel;
import com.raoulvdberge.refinedstorage.tile.TileNode;
import com.raoulvdberge.refinedstorage.tile.data.ITileDataProducer;
import com.raoulvdberge.refinedstorage.tile.data.RSSerializers;
import com.raoulvdberge.refinedstorage.tile.data.TileDataParameter;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
public class TileCraftingMonitor extends TileNode implements ICraftingMonitor {
public static final TileDataParameter<List<ICraftingMonitorElement>> ELEMENTS = new TileDataParameter<>(RSSerializers.CRAFTING_MONITOR_ELEMENT_SERIALIZER, Collections.emptyList(), new ITileDataProducer<List<ICraftingMonitorElement>, TileCraftingMonitor>() {
@Override
public List<ICraftingMonitorElement> getValue(TileCraftingMonitor tile) {
if (tile.connected) {
return tile.network.getCraftingTasks().stream().flatMap(t -> t.getCraftingMonitorElements().stream()).collect(Collectors.toList());
} else {
return Collections.emptyList();
}
}
});
public TileCraftingMonitor() {
dataManager.addParameter(ELEMENTS);
}
@Override
public int getEnergyUsage() {
return RS.INSTANCE.config.craftingMonitorUsage;
@@ -43,17 +21,15 @@ public class TileCraftingMonitor extends TileNode implements ICraftingMonitor {
}
@Override
public void onCancelled(ICraftingMonitorElement element) {
RS.INSTANCE.network.sendToServer(new MessageCraftingMonitorCancel(this, element.getTaskId()));
public void onCancelled(int id) {
if (isConnected()) {
network.getItemGridHandler().onCraftingCancelRequested(id);
}
}
@Override
public void onCancelledAll() {
RS.INSTANCE.network.sendToServer(new MessageCraftingMonitorCancel(this, -1));
public void onOpened(EntityPlayer player) {
if (isConnected()) {
network.sendCraftingMonitorUpdate((EntityPlayerMP) player);
}
@Override
public List<ICraftingMonitorElement> getElements() {
return ELEMENTS.getValue();
}
}

View File

@@ -1,11 +1,8 @@
package com.raoulvdberge.refinedstorage.tile.data;
import com.raoulvdberge.refinedstorage.RSUtils;
import com.raoulvdberge.refinedstorage.api.autocrafting.craftingmonitor.ICraftingMonitorElement;
import com.raoulvdberge.refinedstorage.api.storage.AccessType;
import com.raoulvdberge.refinedstorage.apiimpl.API;
import com.raoulvdberge.refinedstorage.tile.ClientNode;
import io.netty.buffer.ByteBuf;
import net.minecraft.network.PacketBuffer;
import net.minecraft.network.datasync.DataParameter;
import net.minecraft.network.datasync.DataSerializer;
@@ -16,7 +13,6 @@ import net.minecraftforge.fml.common.network.ByteBufUtils;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
public final class RSSerializers {
public static final DataSerializer<List<ClientNode>> CLIENT_NODE_SERIALIZER = new DataSerializer<List<ClientNode>>() {
@@ -50,41 +46,6 @@ public final class RSSerializers {
}
};
public static final DataSerializer<List<ICraftingMonitorElement>> CRAFTING_MONITOR_ELEMENT_SERIALIZER = new DataSerializer<List<ICraftingMonitorElement>>() {
@Override
public void write(PacketBuffer buf, List<ICraftingMonitorElement> elements) {
buf.writeInt(elements.size());
for (ICraftingMonitorElement task : elements) {
ByteBufUtils.writeUTF8String(buf, task.getId());
task.write(buf);
}
}
@Override
public List<ICraftingMonitorElement> read(PacketBuffer buf) {
List<ICraftingMonitorElement> elements = new ArrayList<>();
int size = buf.readInt();
for (int i = 0; i < size; ++i) {
Function<ByteBuf, ICraftingMonitorElement> factory = API.instance().getCraftingMonitorElementRegistry().getFactory(ByteBufUtils.readUTF8String(buf));
if (factory != null) {
elements.add(factory.apply(buf));
}
}
return elements;
}
@Override
public DataParameter<List<ICraftingMonitorElement>> createKey(int id) {
return null;
}
};
public static final DataSerializer<FluidStack> FLUID_STACK_SERIALIZER = new DataSerializer<FluidStack>() {
@Override
public void write(PacketBuffer buf, FluidStack value) {

View File

@@ -214,7 +214,7 @@ public class TileGrid extends TileNode implements IGrid {
return network != null ? network.getPosition() : null;
}
public void onGridOpened(EntityPlayer player) {
public void onOpened(EntityPlayer player) {
if (isConnected()) {
if (getType() == EnumGridType.FLUID) {
network.sendFluidStorageToClient((EntityPlayerMP) player);