Jump to content

[3/4 SOLVED]Best TickEvent to add PotionEffect through IMessage


xTimPugz

Recommended Posts

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;
        }
    }
}

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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