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

  • Author

There is the item code:

 

package com.blocklings.items;

import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityList;
import net.minecraft.entity.IEntityLivingData;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.MathHelper;
import net.minecraft.util.StatCollector;
import net.minecraft.world.World;

import com.blocklings.entity.EntityBlockling;
import com.blocklings.main.Blocklings;

public class ItemBlockling extends Item {

public EntityBlockling blockling;

public int level, xp, upgrade, special;

public String blocklingName, name;

public ItemBlockling() {

	super();
	this.setUnlocalizedName("blockling");
	this.setMaxStackSize(1);
	this.setTextureName(Blocklings.MODID + ":" + "blockling");

}

public ItemBlockling(String name, int level, int xp, int upgrade, int special) {

	super();
	this.setUnlocalizedName("blockling");
	this.setMaxStackSize(1);
	this.setTextureName(Blocklings.MODID + ":" + "blockling");

	blocklingName = name;
	this.level = level;
	this.xp = xp;
	this.upgrade = upgrade;
	this.special = special;

}

@Override
public void onUpdate(ItemStack itemStack, World world, Entity entity, int i, boolean b) {

	itemStack.stackTagCompound = new NBTTagCompound();

	if(blocklingName.length() > 0) {

		name = blocklingName;

	} else {

		name = "Blockling";

	}

	for(int j = 0; j < 1; j++) {

		itemStack.stackTagCompound.setString("name", blocklingName);
		itemStack.stackTagCompound.setInteger("level", level);
		itemStack.stackTagCompound.setInteger("xp", xp);
		itemStack.stackTagCompound.setInteger("upgrade", upgrade);
		itemStack.stackTagCompound.setInteger("special", special);

	}

	level = itemStack.stackTagCompound.getInteger("level");

}

@Override
public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player) {

	EntityBlockling blockling = new EntityBlockling(world, level, xp, upgrade, special);

	blockling.setLocationAndAngles(player.posX, player.posY, player.posZ, MathHelper.wrapAngleTo180_float(world.rand.nextFloat() * 360.0F), 0.0F);
        blockling.onSpawnWithEgg((IEntityLivingData)null);
        if(!world.isRemote) world.spawnEntityInWorld(blockling);
        if(!world.isRemote) world.playSoundAtEntity(blockling, "fireworks.twinkle1", 1.0F, 1.0F); 
        if(!world.isRemote) itemStack.stackSize--;
        
        return itemStack;
        
    }

@Override
public String getItemStackDisplayName(ItemStack itemStack) {

        return name;
        
    }

}

  • Author

I thought because I am using NBT that the variables would be different as they get saved and then set again, or am I missing something? When I have two different items they work fine, as if they were two different items.

  • Author

That makes sense, sorry. However, why does doing this in my entity class, mean the item that I pick up disappears after I exit the world?

 

if(this.isDead && !this.worldObj.isRemote) {

		this.worldObj.spawnEntityInWorld(new EntityItem(this.worldObj, posX, posY, posZ, new ItemStack(new ItemBow().setUnlocalizedName("bow").setTextureName("bow")))); 

	}

new ItemBow()

You are creating a new item instance. The game doesn't know what it is after reload. Thus the info gets discarded.

Use "Items.bow".

  • Author

If I wanted to do it like that for a custom item that takes parameters in the constructor depending on things within the entity class, how can I do that? I thought that would be the way to do it.

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.