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

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

 

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.

  • Author

No. I can't figure out how, after trying multiple ways listed on the internet. Either I'm not doing it right, or it doesn't fix it. How would you recommend I go about it?

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.

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

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.

  • Author
Just now, Animefan8888 said:

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

Ok thank you I got it working.

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.