Jump to content

Need a lille help


Anonymous1611

Recommended Posts

Hey guys,

 

Im bussy with a horse mod. Once you mount the horse it shows you the speed etc via a chatmessage. But i keep getting a null pointer exception when adding double and int values to TextComponentString any idea?

 

This works: https://gyazo.com/5a371815b692aa6b8ad4d07a7e26d163

This doesnt (eg nullpointer exception): https://gyazo.com/e648adf81b24f6f67e44a2028c898ee0

Ive tried:https://gyazo.com/d0d82f7b3b67bf1b59f62f4b3fc41557

 

Any help would be appreciated!

 

 

Link to comment
Share on other sites

Edit: Figured it out. Im a retard >.>

 

    @SubscribeEvent
    public void onEntityMount(EntityMountEvent event) {
        if(event.getEntityMounting() instanceof EntityPlayer) {
            if (event.getEntityBeingMounted() instanceof EntityHorse) {
                EntityPlayerSP player = Minecraft.getMinecraft().player;
                double speed = 14.3D;
                player.sendMessage(new TextComponentString("This is a " + speed));
            }
        }
    }
}

 

Adding solved it.:

EntityPlayerSP player = Minecraft.getMinecraft().player;

 

 

Edited by Anonymous1611
Link to comment
Share on other sites

Thank you very mucht. Im facing another issue currently.

 

@SubscribeEvent
public void onMount(EntityMountEvent event) {
        EntityPlayerSP player = Minecraft.getMinecraft().player;
        if ((player.getHeldItemMainhand().getItem() == Items.NAME_TAG) && (player.getHeldItemMainhand().getDisplayName().equalsIgnoreCase("Name Tag"))) {
            if (event.isMounting() == true) {
                if (event.getEntityMounting() != null) {
                    if (event.getEntityMounting() instanceof EntityPlayer) {
                        if (event.getEntityBeingMounted() instanceof EntityHorse) {
                            event.setCanceled(true);
                        }
                    }
                }
            }
        }
    }

 

Basically if im holding a nametag and trying to mount a horse it has to dismount or cancel the action. I canceled the action so i dont mount the horse. Now how do i tell the server that i canceled the event? Because currently on my screen im not on the horse but the server thinks i am.


Thanks in advance im really learning stuff here!

Edited by Anonymous1611
Link to comment
Share on other sites

Alright im completly stuck.

 

EntityMountEvent is server-sided, i can read it but cant change it (Ghosting as shown in the gyazo link)

 

Now how do i properly check that EntityPlayerSP is mounting a horse with an specific item in hand so i can prevent it 

    @Mod.EventHandler
    public void onInit(FMLInitializationEvent event) {
        Main horseStats = new Main();
        FMLCommonHandler.instance().bus().register(horseStats);
        MinecraftForge.EVENT_BUS.register(horseStats);
    }

    @SubscribeEvent
    public void onInteract(PlayerInteractEvent.EntityInteractSpecific event) {
        EntityPlayerSP player = Minecraft.getMinecraft().player;
        if (event.getTarget() instanceof EntityHorse) {
            if (event.getHand() == EnumHand.MAIN_HAND) {
                if ((player.getHeldItemMainhand().getItem() == Items.NAME_TAG) && (player.getHeldItemMainhand().getDisplayName().equalsIgnoreCase("Name Tag"))) {
                    if (System.currentTimeMillis() - this.lastTime > 600L) {
                        this.lastTime = System.currentTimeMillis();
                        sendInfo(player, (EntityHorse) event.getTarget());
                    }
                }
            }
        }
    }
    
    public void sendInfo(EntityPlayerSP player, EntityHorse horse) {
        double speed = horse.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).getAttributeValue();
        double jump = horse.getHorseJumpStrength();

        DecimalFormat df = new DecimalFormat("0.00");
        String jumpBlock = df.format(-0.1817584952D * Math.pow(jump, 3.0D) + 3.689713992D * Math.pow(jump, 2.0D) + 2.128599134D * jump - 0.343930367D);
        df = new DecimalFormat("0.0");

        player.sendMessage(new TextComponentString(ChatFormatting.GRAY + "[" + ChatFormatting.DARK_GRAY + "HorseStats" + ChatFormatting.GRAY + "]" + ChatFormatting.WHITE + " Dit is een " + df.format(43.1111111D * speed) + " paard die " + jumpBlock + " blokken hoog springt!"));
    }
}
Edited by Anonymous1611
Link to comment
Share on other sites

6 minutes ago, diesieben07 said:

EntityPlayerSP is client-side.

You need to stop using it.

 

Yes i get that. 

 

So as shown in the code above. The player interacts with the entity (right click, also mounting as in vanilla minecraft) while holding an item and gets an message accordingly. How do i cancel EntityMountEvent then? Or is there a server-sided mod needed for this, if so how do i prevent the player from mounting the entity when it tries to interact (right clicck) on the horse.

 

Thanks in advance im really trying to understand and learn here.

Link to comment
Share on other sites

Also, you're using the arrow anti-pattern.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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.