Jump to content

[Solved] (1.16.5) Event won't fire


Bowtruckle_HD

Recommended Posts

package bowtruckle.mods.gods.data;


import bowtruckle.mods.gods.tools.Settings;
import bowtruckle.mods.gods.tools.Vector3;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.event.AttachCapabilitiesEvent;
import net.minecraftforge.event.TickEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import bowtruckle.mods.gods.tools.Settings;

@Mod.EventBusSubscriber(modid = Settings.MODID, bus = Mod.EventBusSubscriber.Bus.FORGE, value = Dist.CLIENT)
public class PlayerInfoEventHandler {

	@SubscribeEvent
    public static void attachCapability(AttachCapabilitiesEvent<Entity> e) {
        if(e.getObject() instanceof PlayerEntity) {
            PlayerInfoProvider provider = new PlayerInfoProvider();
            e.addCapability(new ResourceLocation(Settings.MODID,"lastPos"), provider);
            e.addListener(provider::invalidate);
        }
    }
      
	@SubscribeEvent
    public static void onPlayerMove(TickEvent.PlayerTickEvent e) {
        System.out.println("event called");
        if(e.getPhase().equals(TickEvent.Phase.END)) {
            System.out.println("Event Phase End");
            e.player.getCapability(CapabilityPlayerInfo.PLAYER_INFO_CAPABILITY).ifPresent(information -> {
                Vector3 pos = new Vector3(e.player.getPosX(), e.player.getPosY(), e.player.getPosZ());
                if (pos == information.getLastPos()) {
                    e.player.setInvisible(true);
                }else{
                    e.player.setInvisible(false);
                }
                System.out.println(information.getLastPos());
            });
        }
    }
}

Try using this code and remove the register of FMLCommonSetupEvent

Link to comment
Share on other sites

  • Bowtruckle_HD changed the title to [Solved] (1.16.5) Event won't fire

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.