Jump to content

Item in inventory?


RiceAndCheese

Recommended Posts

So, I have this code.
What I wanna do is that when the item is in my inventory, the player is set on fire.

It isn't working... Any Idea on what is the problem (Eclipse shows me no problem)

I almost forgot to say, I used ACATIA_BUTTON just to test and I'm kinda new at this.

 

package com.riceandcheese.jademod.common.items;

import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.Items;
import net.minecraftforge.event.TickEvent.PlayerTickEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;

public class SpecialItem4 extends Item {

    public SpecialItem4(Properties properties) {
        super(properties);
    }
    @SubscribeEvent
    public void onTickPlayerEvent(PlayerTickEvent event){

        if(event.player instanceof PlayerEntity){
            PlayerEntity player = (PlayerEntity) event.player;
            if(player.inventory.hasItemStack(Items.ACACIA_BUTTON.getDefaultInstance())) {
                player.forceFireTicks(21);
            }
        }
    }
}

 

Edited by RiceAndCheese
Link to comment
Share on other sites

 

3 hours ago, diesieben07 said:

Several things don't make sense about your code.

  • Do you want to use an item that is not added by your mod (e.g. the acacia button)? If so, why do you have a class that extends Item then?
  • If you want to do it for an item added by your mod (e.g. the "SpecialItem4"), why do you use an event for this? Override inventoryTick in your Item class instead.

Ok so, this is my EventHandler class:

package com.riceandcheese.jademod.core.event;

import com.riceandcheese.jademod.Jademod;
import com.riceandcheese.jademod.core.init.Iteminit;

import net.minecraft.entity.player.PlayerEntity;
import net.minecraftforge.event.TickEvent.PlayerTickEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus;

@EventBusSubscriber(modid = Jademod.MOD_ID, bus = Bus.FORGE)
public class EventHandler {
	@SubscribeEvent
	public void onTickPlayerEvent(PlayerTickEvent event){

		if(event.player instanceof PlayerEntity){
			PlayerEntity player = (PlayerEntity) event.player;
			if(player.inventory.hasItemStack(Iteminit.fire_fragment.get().getDefaultInstance())) {
				player.forceFireTicks(21);
			}
		}
	}
}

It's still not working (fire_fragment is the item that's gonna make it happen)
 

Link to comment
Share on other sites

12 minutes ago, RiceAndCheese said:

fire_fragment is the item that's gonna make it happen

 

3 hours ago, diesieben07 said:
  • If you want to do it for an item added by your mod (e.g. the "SpecialItem4"), why do you use an event for this? Override inventoryTick in your Item class instead.

*Squint*

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

Worked thanks!
If anyone wants the code:

package com.riceandcheese.jademod.common.items;

import com.riceandcheese.jademod.core.init.Iteminit;

import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;

public class SpecialItem4 extends Item {

	public SpecialItem4(Properties properties) {
		super(properties);
	}
	@Override
	public void inventoryTick(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) {
		if(entityIn instanceof PlayerEntity){
			PlayerEntity player = (PlayerEntity) entityIn;
			if(player.inventory.hasItemStack(Iteminit.fire_fragment.get().getDefaultInstance())) {
				player.forceFireTicks(30);
			}
		}
		super.inventoryTick(stack, worldIn, entityIn, itemSlot, isSelected);
	}
}

 

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.