Jump to content

1.10.2 Item has wither


NoVaGaming

Recommended Posts

Me and my friend have a item called UraniumIngot and we want it to give us a wither effect when were holding it

 

Items Class

package com.team.ne.init;

import com.team.ne.client.MainVariables;

import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.fml.common.registry.GameRegistry;

public class NEItems {
public static Item CadiumIngot;
public static Item ElectroliumIngot;
public static Item DialuxIngot;
public static Item UraniumIngot;

public static void init(){
	CadiumIngot = new Item().setCreativeTab(NETabs.eetab).setMaxStackSize(64).setUnlocalizedName("CadiumIngot");
	ElectroliumIngot = new Item().setCreativeTab(NETabs.eetab).setMaxStackSize(64).setUnlocalizedName("ElectroliumIngot");
	DialuxIngot = new Item().setCreativeTab(NETabs.eetab).setMaxStackSize(64).setUnlocalizedName("DialuxIngot");
	UraniumIngot = new Item().setCreativeTab(NETabs.eetab).setMaxStackSize(64).setUnlocalizedName("UraniumIngot");
}

public static void register(){
	GameRegistry.registerItem(CadiumIngot, CadiumIngot.getUnlocalizedName().substring(5));
	GameRegistry.registerItem(ElectroliumIngot, ElectroliumIngot.getUnlocalizedName().substring(5));
	GameRegistry.registerItem(DialuxIngot, DialuxIngot.getUnlocalizedName().substring(5));
	GameRegistry.registerItem(UraniumIngot, UraniumIngot.getUnlocalizedName().substring(5));
}

public static void registerRenders(){
	registerRender(CadiumIngot);
	registerRender(ElectroliumIngot);
	registerRender(DialuxIngot);
	registerRender(UraniumIngot);
}

public static void registerRender(Item item){
	ModelLoader.setCustomModelResourceLocation(item, 0, new ModelResourceLocation(item.getRegistryName(), "inventory"));
}
}

Are You Feeling it now Mr.Krabs?

 

GitHub

https://github.com/nuclearelectricity/Nuclear-Electricity

Link to comment
Share on other sites

When you are holding it or when it is in your inventory either way use onUpdate(...) in your item class.

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

Create a class that extends

Item

and overrides

Item#onUpdate

.

 

In your override, check if the

entityIn

argument is an instance of

EntityLivingBase

. If it is, cast it to

EntityLivingBase

and call

EntityLivingBase#isPotionActive

to check if it has the

MobEffects.WITHER

effect active. If it doesn't, create a

PotionEffect

and call

EntityLivingBase#addPotionEffect

to add it.

 

Create and register an instance of this class instead of

Item

.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

I dont understand. I made a new class Called UraniumIngotEffect and Overrided onUpdate i dont understand you if statement and casting

Heres what i have so far.

package item;

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

public class UraniumIngotEffect extends Item{

@Override
public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) {
	if(entityIn = EntityLivingBase )
	super.onUpdate(stack, worldIn, entityIn, itemSlot, isSelected);
}

}

Are You Feeling it now Mr.Krabs?

 

GitHub

https://github.com/nuclearelectricity/Nuclear-Electricity

Link to comment
Share on other sites

I dont understand. I made a new class Called UraniumIngotEffect and Overrided onUpdate i dont understand you if statement and casting

 

Then you don't know Java well enough to make a mod. Learn Java properly before trying to make a mod.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

I dont understand the way your wording it. Im having a problem. I thought fourms were to help... But forreal me and my friend want to continue. Could you please tell us what were doing wrong.

Look up casting in programming and you will see.

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

So we sorta figured it out were gonna keep following his instuctions but heres our code so far

package item;

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

public class UraniumIngotEffect extends Item{


@Override
public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) {
	if(entityIn instanceof EntityLivingBase)
	super.onUpdate(stack, worldIn, entityIn, itemSlot, isSelected);
}

}

Are You Feeling it now Mr.Krabs?

 

GitHub

https://github.com/nuclearelectricity/Nuclear-Electricity

Link to comment
Share on other sites

If we cast

 

Entity entityIn = EntityLivingBase.this.isPotionActive(MobEffects.WITHER);

We get an error saying

No enclosing instance of the type EntityLivingBase is accessible in scope

Im sorry if this is basic but i rlly need to hurry to get this done but the set time for my friend

Are You Feeling it now Mr.Krabs?

 

GitHub

https://github.com/nuclearelectricity/Nuclear-Electricity

Link to comment
Share on other sites

facepalm.jpg

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

Dracos that was a stuped question srry :D. But forreal this is as far as i could get i tryed mutiple ways with the "Else" Statment and here what i ended up with

 

package item;

import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.init.MobEffects;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.PotionEffect;
import net.minecraft.world.World;

public class UraniumIngotEffect extends Item{


@Override
public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) {
	if(entityIn instanceof EntityLivingBase){
		 Object EntityLivingBase = ((EntityLivingBase) entityIn).isPotionActive(MobEffects.WITHER);

	}else{
	    PotionEffect PotionEffect =  ((EntityLivingBase) entityIn).addPotionEffect(MobEffects.WITHER);
	}


	super.onUpdate(stack, worldIn, entityIn, itemSlot, isSelected);
}

}

Are You Feeling it now Mr.Krabs?

 

GitHub

https://github.com/nuclearelectricity/Nuclear-Electricity

Link to comment
Share on other sites

dumb.png

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

Guest
This topic is now closed to further replies.


×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.