Jump to content

1.12.2 trouble detecting armor


JonIsPatented

Recommended Posts

I'm trying to create a poisonous atmosphere in my custom dimension. The code is meant to give the player poison when they are in my dimension and they aren't wearing a gas mask. I can't tell why my code doesn't work. I tried added a println line in there but it didn't show up which probably means that the code isn't being called but I don't know why.

 

Quote

package com.jonispatented.moarmor.world.dimension.overrun;

import com.jonispatented.moarmor.init.ModItems;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.MobEffects;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.PotionEffect;
import net.minecraft.world.World;
import net.minecraft.world.WorldProvider;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;

 

public class PoisonAir {
    
    @SubscribeEvent
    public void playerTick(TickEvent.PlayerTickEvent event)
    {    
        final EntityPlayer player = event.player;
            
        if(player.inventory.armorItemInSlot(3).getItem() != ModItems.GAS_MASK)
        {
            if(player.dimension == 2)
            {
                player.addPotionEffect(new PotionEffect(MobEffects.POISON, 1, 1, false, false));
            }
        }
    }
}

 

Link to comment
Share on other sites

Just now, JonIsPatented said:

which probably means that the code isn't being called but I don't know why.

Did you register an instance of event handler class(Poison Air) to MinecraftForge.EVENT_BUS?

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

4 minutes ago, JonIsPatented said:

How would you recommend I go about it?

Read this.

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

Just now, JonIsPatented said:

That's what I read. And Jabelar's tutorial. I think I'm doing it wrong.

Show what you have.

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

1 minute ago, Animefan8888 said:

Show what you have.

I've tried adding the annotation to the class like this:

Quote

@Mod.EventBusSubscriber
public class PoisonAir {
    
    @SubscribeEvent
    public void playerTick(TickEvent.PlayerTickEvent event)
    {    
        final EntityPlayer player = event.player;
            
        if(player.inventory.armorItemInSlot(3).getItem() != ModItems.GAS_MASK)
        {
            if(player.dimension == 2)
            {
                player.addPotionEffect(new PotionEffect(MobEffects.POISON, 1, 1, false, false));
            }
        }
    }
}

Then I tried adding that line from the tutorial into the main class:

Quote

@EventHandler
    public static void PreInit(FMLPreInitializationEvent event)
    {
        GameRegistry.registerWorldGenerator(new ModWorldGen(), 3);
        DimensionInit.registerDimensions();
        GameRegistry.registerWorldGenerator(new GenerateCustomStructures(), 3);
        MinecraftForge.EVENT_BUS.register(PoisonAir.class);
        
    }

Then I tried something else in my registry handler but I forgot exactly what it was because I deleted all three of those changes after they didn't work.

Link to comment
Share on other sites

2 minutes ago, JonIsPatented said:

Then I tried something else in my registry handler but I forgot exactly what it was because I deleted all three of those changes after they didn't work

Both of those ways to require your method playerTick to be a static method.

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

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.