Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

What would be the best way to create an event that happens in the world. Like on the push of a button in a gui, cause a system of actions to occur for the next say ten seconds? Would i be easier to do this in the same tileentity or can i do it with a separate ticking entity?

The seven became one and the one became two.

15 minutes ago, Merthew said:

Like on the push of a button in a gui, cause a system of actions to occur for the next say ten seconds?

Depends. If you do not care whether the execution finishes or not then you can do it in your TE. However if you do care then you need to do it in a different way since a TE can get unloaded. Something like this(pseudo-code):

class Gui
{
    ...
    void onButtonPress(GuiButton btn)
    {
        Network.sendMessageToServer(new MessageDoThings());
    }
    ...
}

class MessageDoThingsHandler implements IMessageHandler<MessageDoThings, IMessage>
{
    ...
    IMessage handleMessage(MessageDoThings message, IContext context)
    {
        EntityPlayerMP sender = cotext.getSender();
        World world = sender.world;
        IWorldCap worldCap = world.getCapability(YOUR_CAP, null);
        worldCap.addAction(new DoThings(YOUR_TIMER));
    }
}

class WorldCap implements IWorldCap
{
    List<IWorldAction> actions = Lists.newArrayList();
    
    @Override
    void addAction(IWorldAction action)
    {
        this.actions.add(action);
    }
    
    @Override
    void onTick()
    {
        for (int i = this.actions.size() - 1; i >= 0; --i)
        {
            IWorldAction act = this.actions.get(i);
            if (!act.run())
            {
                this.actions.remove(act);
            }
        }
    }
}

interface IWorldAction
{
    boolean run();
}

class DoThings implements IWorldAction
{
    final int timer = 0;
    
    DoThings(int i)
    {
        this.timer = i;
    }
    
    @Override
    boolean run()
    {
        if (this.timer % 20 == 0)
        {
            this.doThings();
        }
        
        return this.timer-- == 0;
    }
    
    void doThings()
    {
        ...
    }
}

@EventBusSubscriber
class WorldHandler
{
    @SubscribeEvent
    static void onWorldTick(WorldTickEvent event)
    {
        if (event.phase != Phase.END)
        {
            event.world.getCapability(YOUR_CAP, null).onTick();
        }
    }
}

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.