Jump to content

Recommended Posts

Posted

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

Posted

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.

Posted

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

Posted

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.

Posted

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.

Posted

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

Posted
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.

Posted

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

Posted

What you are doing there makes absolutely no sense and shows us that you dont know much about java...

This forum isnt a java learning forum.

Learn atleast java basics to try modding.

Posted
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.

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

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