Java Code Examples for net.minecraft.client.Minecraft#addScheduledTask()

The following examples show how to use net.minecraft.client.Minecraft#addScheduledTask() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UIFactory.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
@SideOnly(Side.CLIENT)
public final void initClientUI(PacketBuffer serializedHolder, int windowId, List<PacketUIWidgetUpdate> initialWidgetUpdates) {
    E holder = readHolderFromSyncData(serializedHolder);
    Minecraft minecraft = Minecraft.getMinecraft();
    EntityPlayerSP entityPlayer = minecraft.player;

    ModularUI uiTemplate = createUITemplate(holder, entityPlayer);
    uiTemplate.initWidgets();
    ModularUIGui modularUIGui = new ModularUIGui(uiTemplate);
    modularUIGui.inventorySlots.windowId = windowId;
    for (PacketUIWidgetUpdate packet : initialWidgetUpdates) {
        modularUIGui.handleWidgetUpdate(packet);
    }
    minecraft.addScheduledTask(() -> {
        minecraft.displayGuiScreen(modularUIGui);
        minecraft.player.openContainer.windowId = windowId;
    });
}
 
Example 2
Source File: SchematicProject.java    From litematica with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void onTaskCompleted()
{
    Minecraft mc = Minecraft.getMinecraft();

    if (mc.isCallingFromMinecraftThread())
    {
        this.saveVersion();
    }
    else
    {
        mc.addScheduledTask(new Runnable()
        {
            @Override
            public void run()
            {
                SaveCompletionListener.this.saveVersion();
            }
        });
    }
}
 
Example 3
Source File: MessageSyncTileEntity.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public IMessage onMessage(final MessageSyncTileEntity message, MessageContext ctx)
{
    if (ctx.side != Side.CLIENT)
    {
        EnderUtilities.logger.error("Wrong side in MessageSyncTileEntity: " + ctx.side);
        return null;
    }

    Minecraft mc = FMLClientHandler.instance().getClient();
    final EntityPlayer player = EnderUtilities.proxy.getPlayerFromMessageContext(ctx);

    if (mc == null || player == null)
    {
        EnderUtilities.logger.error("Minecraft or player was null in MessageSyncTileEntity");
        return null;
    }

    mc.addScheduledTask(new Runnable()
    {
        public void run()
        {
            processMessage(message, player);
        }
    });

    return null;
}
 
Example 4
Source File: MessageSyncCustomSlot.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public IMessage onMessage(final MessageSyncCustomSlot message, MessageContext ctx)
{
    if (ctx.side != Side.CLIENT)
    {
        EnderUtilities.logger.error("Wrong side in MessageSyncCustomSlot: " + ctx.side);
        return null;
    }

    Minecraft mc = FMLClientHandler.instance().getClient();
    final EntityPlayer player = EnderUtilities.proxy.getPlayerFromMessageContext(ctx);

    if (mc == null || player == null)
    {
        EnderUtilities.logger.error("Minecraft or player was null in MessageSyncCustomSlot");
        return null;
    }

    mc.addScheduledTask(new Runnable()
    {
        public void run()
        {
            processMessage(message, player);
        }
    });

    return null;
}
 
Example 5
Source File: MessageSyncSlot.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public IMessage onMessage(final MessageSyncSlot message, MessageContext ctx)
{
    if (ctx.side != Side.CLIENT)
    {
        EnderUtilities.logger.error("Wrong side in MessageSyncSlot: " + ctx.side);
        return null;
    }

    Minecraft mc = FMLClientHandler.instance().getClient();
    final EntityPlayer player = EnderUtilities.proxy.getPlayerFromMessageContext(ctx);

    if (mc == null || player == null)
    {
        EnderUtilities.logger.error("Minecraft or player was null in MessageSyncSlot");
        return null;
    }

    mc.addScheduledTask(new Runnable()
    {
        public void run()
        {
            processMessage(message, player);
        }
    });

    return null;
}
 
Example 6
Source File: MessageSyncNBTTag.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public IMessage onMessage(final MessageSyncNBTTag message, MessageContext ctx)
{
    if (ctx.side != Side.CLIENT)
    {
        EnderUtilities.logger.error("Wrong side in MessageSyncNBTTag: " + ctx.side);
        return null;
    }

    final Minecraft mc = FMLClientHandler.instance().getClient();

    if (mc == null)
    {
        EnderUtilities.logger.error("Minecraft was null in MessageSyncNBTTag");
        return null;
    }

    mc.addScheduledTask(new Runnable()
    {
        public void run()
        {
            processMessage(message);
        }
    });

    return null;
}
 
Example 7
Source File: MessageAddEffects.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public IMessage onMessage(final MessageAddEffects message, MessageContext ctx)
{
    if (ctx.side != Side.CLIENT)
    {
        EnderUtilities.logger.error("Wrong side in MessageAddEffects: " + ctx.side);
        return null;
    }

    Minecraft mc = FMLClientHandler.instance().getClient();
    final EntityPlayer player = EnderUtilities.proxy.getPlayerFromMessageContext(ctx);
    if (mc == null || player == null)
    {
        EnderUtilities.logger.error("Minecraft or player was null in MessageAddEffects");
        return null;
    }

    mc.addScheduledTask(new Runnable()
    {
        public void run()
        {
            processMessage(message, player, player.getEntityWorld(), mc.getSoundHandler());
        }
    });

    return null;
}
 
Example 8
Source File: PacketCustom.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void handle(final INetHandler netHandler, final String channel, final PacketCustom packet) {
    if (netHandler instanceof INetHandlerPlayClient) {
        Minecraft mc = Minecraft.getMinecraft();
        if (!mc.isCallingFromMinecraftThread())
            mc.addScheduledTask(new Runnable() {
                public void run() {
                    handle(netHandler, channel, packet);
                }
            });
        else
            handler.handlePacket(packet, mc, (INetHandlerPlayClient) netHandler);
    } else
        System.err.println("Invalid INetHandler for PacketCustom on channel: " + channel);
}