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

Hello

 

The question is simple this time.. What is the best TickEvent for potions? I noticed that my PlayerTick is way slower than the ServerTick, and so it flashes the PotionEffect.

 

Thanks

  • Author

Current Tickhandler:

 

package me.xtimpugz.lotraddons;

import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.TickEvent;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import me.xtimpugz.lotraddons.effects.ringseffects.ClickableEffect;
import me.xtimpugz.lotraddons.effects.ringseffects.Effect;
import me.xtimpugz.lotraddons.effects.ringseffects.special.EffectFireBall;
import me.xtimpugz.lotraddons.effects.ringseffects.special.spawning.EffectInvasion;
import me.xtimpugz.lotraddons.item.Ring;
import me.xtimpugz.lotraddons.messages.MessageEffect;
import me.xtimpugz.lotraddons.messages.MessageFireball;
import me.xtimpugz.lotraddons.messages.MessageRegular;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.EnumChatFormatting;

/**
* Created by jove on 16/08/2016.
*/
public class Ticker {
    @SubscribeEvent
    public void onPlayerTick(TickEvent.PlayerTickEvent event) {
        if(!event.player.worldObj.isRemote) {
            EffectManager.ticks++;
            EntityPlayer player = event.player;
            ProxyCommon.wrapper.sendToServer(new MessageRegular(player));
        }


    }
    @SubscribeEvent
    public void onServerTick(TickEvent.ServerTickEvent event){
        EffectManager.ticks++;

    }
}

 

MessageHandler and Registry of the message

 

        wrapper = NetworkRegistry.INSTANCE.newSimpleChannel("effectChannel");
        wrapper.registerMessage(MessageEffect.CustomServerPacketManager.class, MessageEffect.class, 0, Side.SERVER);
        wrapper.registerMessage(MessageRegular.MessageRegularServerHandler.class, MessageRegular.class, 1, Side.SERVER);
        wrapper.registerMessage(MessageFireball.MessageFireballServerHandler.class, MessageFireball.class, 2, Side.SERVER);
        wrapper.registerMessage(MessageOpenGUI.Handler.class, MessageOpenGUI.class, 3, Side.SERVER);

        wrapper.registerMessage(SyncPacket.SynchPacketHandler.class, SyncPacket.class, 4, Side.CLIENT);

package me.xtimpugz.lotraddons.messages;

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 cpw.mods.fml.relauncher.Side;
import io.netty.buffer.ByteBuf;
import me.xtimpugz.lotraddons.EffectManager;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;

/**
* Created by jove on 16/08/2016.
*/
public class MessageRegular implements IMessage {


    public EntityPlayer player;

    public MessageRegular(){
    }

    public MessageRegular(EntityPlayer player){
        this.player = player;
    }


    @Override
    public void fromBytes(ByteBuf buf) {

    }

    @Override
    public void toBytes(ByteBuf buf) {

    }

    public static class MessageRegularServerHandler implements IMessageHandler<MessageRegular,IMessage> {

        @Override
        public IMessage onMessage(MessageRegular message, MessageContext ctx) {
            if (ctx.side == Side.SERVER) {
                EntityPlayerMP player =  ctx.getServerHandler().playerEntity;
                EffectManager.runEffectsClient(player);

                return null;
            }else{
                System.err.println("Not supposed to be called from client..");
            }
            return null;
        }
    }
}

 

Why do you need to send a message in the first place, why are you trying to add a potion effect on the client when it is handled server side?

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

  • Author

I see where we are going to. This concept had me confused for a while now.

I thought, that for security the potion effect must be added by the server? (And it does send to the server, check the registration of the IMessage and its handler).

 

Thanks

The server should be handling the tick events and adding the effect, the client shouldn't be doing anything here. There's no need for packets.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

  • Author

Then why are you checking if it is a server world?

if(!event.player.worldObj.isRemote) {

Pardon that "!". I just added that in the code and forgot to remove it. (with the reversed boolean it crashed, for anyone wondering! :D)

The server should be handling the tick events and adding the effect, the client shouldn't be doing anything here. There's no need for packets.

Ah I see now.

So I can basically just add the PotionEffects in the PlayerTick event directly? Thanks!

  • Author

Thank you guys it's fixed now. I did a check if it was calling from Server Side.

One thing though, invisibility tends to flash suddenly... Any idea why?

 

  • Author

I made some sort of effect system to add multiple effects with commands and such, but basically the invisibility effect is just calling the

        player.setInvisible(true);

method, to prevent particles.

  • Author

Hmh. I'll see if I can find a way to get these particles removed when using the normal Potion, perhaps that will work.

 

Use the PotionEffect constructor that has the args Potion potionIn, int durationIn, int amplifierIn, boolean ambientIn, boolean showParticlesIn

 

ambientIn is true if the effect is caused by a beacon.

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.