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.

qpwoeiruty

Members
  • Joined

  • Last visited

  1. 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.
  2. 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")))); }
  3. They need to be used in multiple methods and I need to remove the first constructor.
  4. 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.
  5. 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; } }
  6. My custom item leaves my inventory after I save and quit the world then enter again, no clue why.
  7. How do I do that though, as the parameters don't contain an x, y, or z coordinate.
  8. I am trying to make an item spawn my mob, but I don't understand how to do it. I thought this method would do it but for some reason this doesn't work, nothing spawns: @Override public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player) { if(!world.isRemote) world.spawnEntityInWorld(new EntityBlockling(world, level, xp, upgrade, special)); return itemStack; } I looked in the normal spawn egg code but couldn't figure it out.
  9. I fixed it. The tile was null because I think it was destroyed before I could actually set it to anything or something.
  10. Here is the entire crash report:
  11. I did that but sadly, it had no effect.
  12. I will try that and let you know. This is for two of my custom blocks placed near each other... [18:57:33] [server thread/INFO] [sTDOUT]: [com.phytomining.blocks.BlockPlant:updateTick:54]: com.phytomining.tileentities.TilePlant@303c8bb2 [18:57:41] [server thread/INFO] [sTDOUT]: [com.phytomining.blocks.BlockPlant:updateTick:54]: com.phytomining.tileentities.TilePlant@7b26e0b4
  13. I am having a bit of a problem with a null pointer exception. Whenever I try to System.out.println(tile.getCoal()); which I thought should work I just get a null pointer at that line. I don't really know why though, any help would be much appreciated, thanks. Tile Entity package com.phytomining.tileentities; import java.util.Random; import net.minecraft.block.Block; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.Packet; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; public class TilePlant extends TileEntity { private Random random = new Random(); public int coal = 0; public int iron = 0; public int gold = 0; public int redstone = 0; public int lapis = 0; public int diamond = 0; public int emerald = 0; public World world; public int x; public int y; public int z; @Override public void updateEntity() { world = worldObj; x = xCoord; y = yCoord; z = zCoord; int meta = world.getBlockMetadata(x, y, z); int[][][] blocks = new int[5][5][5]; if(random.nextInt(100) == 0) { for(int xx = 0; xx < 5; xx++) { for(int yy = 0; yy < 5; yy++) { for(int zz = 0; zz < 5; zz++) { Block b = world.getBlock((x - 2) + xx, y - (yy + 1), (z - 2) + zz); int block = b.getIdFromBlock(b); blocks[xx][yy][zz] = block; //System.out.println(xx + ", " + yy + ", " + zz + ": " + blocks[xx][yy][zz]); if(block == 16) coal++; if(block == 15) iron++; if(block == 14) gold++; if(block == 73 || block == 74) redstone++; if(block == 21) lapis++; if(block == 56) diamond++; if(block == 129) emerald++; world.markBlockForUpdate(x, y, z); } } } } } @Override public void writeToNBT(NBTTagCompound tag) { super.writeToNBT(tag); tag.setInteger("coal", this.coal); tag.setInteger("iron", this.iron); tag.setInteger("gold", this.gold); tag.setInteger("redstone", this.redstone); tag.setInteger("lapis", this.lapis); tag.setInteger("diamond", this.diamond); tag.setInteger("coal", this.coal); } @Override public void readFromNBT(NBTTagCompound tag) { super.readFromNBT(tag); this.coal = tag.getInteger("coal"); this.iron = tag.getInteger("iron"); this.gold = tag.getInteger("gold"); this.redstone = tag.getInteger("redstone"); this.lapis = tag.getInteger("lapis"); this.diamond = tag.getInteger("diamond"); this.emerald = tag.getInteger("emerald"); } public int getCoal() { return coal; } } Block package com.phytomining.blocks; import java.util.Random; import net.minecraft.block.Block; import net.minecraft.block.BlockBush; import net.minecraft.block.ITileEntityProvider; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.entity.item.EntityItem; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.IIcon; import net.minecraft.world.World; import com.phytomining.main.Phytomining; import com.phytomining.tileentities.TilePlant; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; public class BlockPlant extends BlockBush implements ITileEntityProvider { private Random random = new Random(); private TilePlant tile; private IIcon texture0; private IIcon texture1; private IIcon texture2; private IIcon texture3; private IIcon texture4; private IIcon texture5; private IIcon texture6; private IIcon texture7; public BlockPlant() { super(Material.plants); setCreativeTab(Phytomining.tabPhytomining); setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F); setTickRandomly(true); setBlockTextureName(Phytomining.MODID + ":texture0"); setBlockName("Jerry"); } @Override public void updateTick(World world, int x, int y, int z, Random r) { super.updateTick(world, x, y, z, r); world.scheduleBlockUpdate(x, y, z, this, 50); } @Override public void onBlockDestroyedByPlayer(World world, int x, int y, int z, int metadata) { tile = (TilePlant)world.getTileEntity(x, y, z); System.out.println(tile.getCoal()); if(!world.isRemote) { world.spawnEntityInWorld(new EntityItem(world, x + (random.nextInt(2)), y, z + (random.nextInt(2)), new ItemStack(Items.coal, tile.getCoal()))); } } @Override public TileEntity createNewTileEntity(World world, int i) { return new TilePlant(); } @Override public void onBlockAdded(World world, int x, int y, int z) { world.scheduleBlockUpdate(x, y, z, this, 50); } @SideOnly(Side.CLIENT) public void registerBlockIcons(IIconRegister i) { texture0 = i.registerIcon(Phytomining.MODID + ":texture0"); texture1 = i.registerIcon(Phytomining.MODID + ":texture1"); texture2 = i.registerIcon(Phytomining.MODID + ":texture2"); texture3 = i.registerIcon(Phytomining.MODID + ":texture3"); texture4 = i.registerIcon(Phytomining.MODID + ":texture4"); texture5 = i.registerIcon(Phytomining.MODID + ":texture5"); texture6 = i.registerIcon(Phytomining.MODID + ":texture6"); texture7 = i.registerIcon(Phytomining.MODID + ":texture7"); } @SideOnly(Side.CLIENT) public IIcon getIcon(int par1, int par2) { if(par2 == 0) return texture0; if(par2 == 1) return texture1; if(par2 == 2) return texture2; if(par2 == 3) return texture3; if(par2 == 4) return texture4; if(par2 == 5) return texture5; if(par2 == 6) return texture6; if(par2 == 7) return texture7; return texture0; } }
  14. Okay thanks, I think I know how to do that.
  15. I set everything up now with my 7 integers in the tile entity class. I am now wondering how I access them in my actual block class.

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.