Search in sources :

Example 1 with PacketItemNBTToServer

use of mcjty.rftoolscontrol.network.PacketItemNBTToServer in project RFToolsControl by McJty.

the class ProgramCommand method loadProgram.

private void loadProgram(ICommandSender sender, String arg, ItemStack item) {
    // File file = new File("." + File.separator + "rftoolscontrol" + File.separator + arg);
    File file = new File(arg);
    String json;
    try (FileInputStream stream = new FileInputStream(file)) {
        byte[] data = new byte[(int) file.length()];
        stream.read(data);
        json = new String(data, "UTF-8");
    } catch (IOException e) {
        ITextComponent component = new TextComponentString(TextFormatting.RED + "Error opening file for reading!");
        if (sender instanceof EntityPlayer) {
            ((EntityPlayer) sender).sendStatusMessage(component, false);
        } else {
            sender.sendMessage(component);
        }
        return;
    }
    ProgramCardInstance program = ProgramCardInstance.readFromJson(json);
    program.writeToNBT(item);
    RFToolsCtrlMessages.INSTANCE.sendToServer(new PacketItemNBTToServer(item.getTagCompound()));
    ITextComponent component = new TextComponentString("Loaded program!");
    if (sender instanceof EntityPlayer) {
        ((EntityPlayer) sender).sendStatusMessage(component, false);
    } else {
        sender.sendMessage(component);
    }
}
Also used : ProgramCardInstance(mcjty.rftoolscontrol.logic.grid.ProgramCardInstance) ITextComponent(net.minecraft.util.text.ITextComponent) EntityPlayer(net.minecraft.entity.player.EntityPlayer) TextComponentString(net.minecraft.util.text.TextComponentString) PacketItemNBTToServer(mcjty.rftoolscontrol.network.PacketItemNBTToServer) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 2 with PacketItemNBTToServer

use of mcjty.rftoolscontrol.network.PacketItemNBTToServer in project RFToolsControl by McJty.

the class GuiCraftingCard method createSelectionEvent.

private BlockRenderEvent createSelectionEvent(final int idx) {
    return new BlockRenderEvent() {

        @Override
        public void select(Widget parent) {
            ItemStack itemstack = mc.player.inventory.getItemStack();
            slots[idx].setRenderItem(itemstack);
            ItemStackList stacks = getStacks();
            if (!stacks.isEmpty()) {
                stacks.set(idx, itemstack);
                ItemStack cardItem = mc.player.getHeldItem(EnumHand.MAIN_HAND);
                CraftingCardItem.putStacksInItem(cardItem, stacks);
                RFToolsCtrlMessages.INSTANCE.sendToServer(new PacketItemNBTToServer(cardItem.getTagCompound()));
            }
        }

        @Override
        public void doubleClick(Widget parent) {
        }
    };
}
Also used : ItemStackList(mcjty.lib.varia.ItemStackList) BlockRenderEvent(mcjty.lib.gui.events.BlockRenderEvent) ItemStack(net.minecraft.item.ItemStack) PacketItemNBTToServer(mcjty.rftoolscontrol.network.PacketItemNBTToServer)

Aggregations

PacketItemNBTToServer (mcjty.rftoolscontrol.network.PacketItemNBTToServer)2 BlockRenderEvent (mcjty.lib.gui.events.BlockRenderEvent)1 ItemStackList (mcjty.lib.varia.ItemStackList)1 ProgramCardInstance (mcjty.rftoolscontrol.logic.grid.ProgramCardInstance)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 ItemStack (net.minecraft.item.ItemStack)1 ITextComponent (net.minecraft.util.text.ITextComponent)1 TextComponentString (net.minecraft.util.text.TextComponentString)1