<commit_before>package mcjty.rftools.blocks.crafter;

import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
import io.netty.buffer.ByteBuf;
import mcjty.rftools.network.NetworkTools;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;

public class PacketCrafter implements IMessage, IMessageHandler<PacketCrafter, IMessage> {
    private int x;
    private int y;
    private int z;

    private int recipeIndex;
    private ItemStack items[];
    private boolean keepOne;
    private boolean craftInternal;

    @Override
    public void fromBytes(ByteBuf buf) {
        x = buf.readInt();
        y = buf.readInt();
        z = buf.readInt();
        keepOne = buf.readBoolean();
        craftInternal = buf.readBoolean();

        recipeIndex = buf.readByte();
        int l = buf.readByte();
        if (l == 0) {
            items = null;
        } else {
            items = new ItemStack[l];
            for (int i = 0 ; i < l ; i++) {
                boolean b = buf.readBoolean();
                if (b) {
                    items[i] = NetworkTools.readItemStack(buf);
                } else {
                    items[i] = null;
                }
            }
        }
    }

    @Override
    public void toBytes(ByteBuf buf) {
        buf.writeInt(x);
        buf.writeInt(y);
        buf.writeInt(z);
        buf.writeBoolean(keepOne);
        buf.writeBoolean(craftInternal);

        buf.writeByte(recipeIndex);
        if (items != null) {
            buf.writeByte(items.length);
            for (ItemStack item : items) {
                if (item == null) {
                    buf.writeBoolean(false);
                } else {
                    buf.writeBoolean(true);
                    NetworkTools.writeItemStack(buf, item);
                }
            }
        } else {
            buf.writeByte(0);
        }
    }

    public PacketCrafter() {
    }

    public PacketCrafter(int x, int y, int z, int recipeIndex, InventoryCrafting inv, ItemStack result, boolean keepOne, boolean craftInternal) {
        this.x = x;
        this.y = y;
        this.z = z;
        this.recipeIndex = recipeIndex;
        this.items = new ItemStack[10];
        if (inv != null) {
            for (int i = 0 ; i < 9 ; i++) {
                items[i] = inv.getStackInSlot(i);
            }
        }
        items[9] = result;
        this.keepOne = keepOne;
        this.craftInternal = craftInternal;
    }

    @Override
    public IMessage onMessage(PacketCrafter message, MessageContext ctx) {
        TileEntity te = ctx.getServerHandler().playerEntity.worldObj.getTileEntity(message.x, message.y, message.z);
        if(!(te instanceof CrafterBaseTE)) {
            // @Todo better logging
            System.out.println("createPowerMonitotPacket: TileEntity is not a CrafterBlockTileEntity!");
            return null;
        }
        CrafterBaseTE crafterBlockTileEntity = (CrafterBaseTE) te;
        if (message.recipeIndex != -1) {
            CraftingRecipe recipe = crafterBlockTileEntity.getRecipe(message.recipeIndex);
            recipe.setRecipe(message.items, message.items[9]);
            recipe.setKeepOne(message.keepOne);
            recipe.setCraftInternal(message.craftInternal);
        }
        return null;
    }

}<commit_msg>Added proper syncing from server to clients in case the crafter is updated. Previously it was possible that a player could not see a new recipe that was set on the crafter by another player.<commit_after>package mcjty.rftools.blocks.crafter;

import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
import io.netty.buffer.ByteBuf;
import mcjty.rftools.network.NetworkTools;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;

public class PacketCrafter implements IMessage, IMessageHandler<PacketCrafter, IMessage> {
    private int x;
    private int y;
    private int z;

    private int recipeIndex;
    private ItemStack items[];
    private boolean keepOne;
    private boolean craftInternal;

    @Override
    public void fromBytes(ByteBuf buf) {
        x = buf.readInt();
        y = buf.readInt();
        z = buf.readInt();
        keepOne = buf.readBoolean();
        craftInternal = buf.readBoolean();

        recipeIndex = buf.readByte();
        int l = buf.readByte();
        if (l == 0) {
            items = null;
        } else {
            items = new ItemStack[l];
            for (int i = 0 ; i < l ; i++) {
                boolean b = buf.readBoolean();
                if (b) {
                    items[i] = NetworkTools.readItemStack(buf);
                } else {
                    items[i] = null;
                }
            }
        }
    }

    @Override
    public void toBytes(ByteBuf buf) {
        buf.writeInt(x);
        buf.writeInt(y);
        buf.writeInt(z);
        buf.writeBoolean(keepOne);
        buf.writeBoolean(craftInternal);

        buf.writeByte(recipeIndex);
        if (items != null) {
            buf.writeByte(items.length);
            for (ItemStack item : items) {
                if (item == null) {
                    buf.writeBoolean(false);
                } else {
                    buf.writeBoolean(true);
                    NetworkTools.writeItemStack(buf, item);
                }
            }
        } else {
            buf.writeByte(0);
        }
    }

    public PacketCrafter() {
    }

    public PacketCrafter(int x, int y, int z, int recipeIndex, InventoryCrafting inv, ItemStack result, boolean keepOne, boolean craftInternal) {
        this.x = x;
        this.y = y;
        this.z = z;
        this.recipeIndex = recipeIndex;
        this.items = new ItemStack[10];
        if (inv != null) {
            for (int i = 0 ; i < 9 ; i++) {
                items[i] = inv.getStackInSlot(i);
            }
        }
        items[9] = result;
        this.keepOne = keepOne;
        this.craftInternal = craftInternal;
    }

    @Override
    public IMessage onMessage(PacketCrafter message, MessageContext ctx) {
        TileEntity te = ctx.getServerHandler().playerEntity.worldObj.getTileEntity(message.x, message.y, message.z);
        if(!(te instanceof CrafterBaseTE)) {
            // @Todo better logging
            System.out.println("createPowerMonitotPacket: TileEntity is not a CrafterBlockTileEntity!");
            return null;
        }
        CrafterBaseTE crafterBlockTileEntity = (CrafterBaseTE) te;
        if (message.recipeIndex != -1) {
            CraftingRecipe recipe = crafterBlockTileEntity.getRecipe(message.recipeIndex);
            recipe.setRecipe(message.items, message.items[9]);
            recipe.setKeepOne(message.keepOne);
            recipe.setCraftInternal(message.craftInternal);
            crafterBlockTileEntity.markDirty();
            crafterBlockTileEntity.getWorldObj().markBlockForUpdate(crafterBlockTileEntity.xCoord, crafterBlockTileEntity.yCoord, crafterBlockTileEntity.zCoord);

        }
        return null;
    }

}
{'fraction_non_alphanumeric': 0.10174102285092491, 'fraction_numerical': 0.002720348204570185, 'mean_word_length': 2.006132461161079, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3226330', 'n_tokens_mistral': 2164, 'n_tokens_neox': 2091, 'n_words': 460}