Jump to content

qpwoeiruty

Members
  • Posts

    159
  • Joined

  • Last visited

Everything posted by qpwoeiruty

  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. I did that but sadly, it had no effect.
  11. 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
  12. 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; } }
  13. Okay thanks, I think I know how to do that.
  14. 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.
  15. I will be storing 7 different integers that I calculate by checking what blocks are within a 5x5x5 area sort of thing.
  16. Okay, thanks. I am currently using metadata to change the texture of my block and am already using the updateTick() method to do so, along with some other code to check the blocks around. Would I need to move that code into my tile entity and do everything in that class rather than the actual block class?
  17. I have used NBT before for entities but I don't know whether it is different for blocks. I have read something about tileEntities, but I don't know if they are relevant. If someone could explain the basics of what I need to do because the only tutorials I can find are outdated.
  18. I figured out why it wasn't working before, I needed to change the name of the registerIcons method to registerBlockIcons...
  19. Oh, that would make a whole lot of sense, I will do that instead.
  20. I am going to be adding a custom flower to my mod, but I am not sure how to get the texture to work. I thought I had everything set up correctly but when I went into my game I had no texture. I looked inside the flower classes and the tall grass class and I think I have everything virtually the same. Is there anything wrong with my class so far? package com.qwertyuiop.blocks; import net.minecraft.block.BlockBush; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.util.IIcon; import net.minecraft.world.ColorizerGrass; import net.minecraft.world.IBlockAccess; import com.qwertyuiop.main.Qwertyuiop; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; public class BlockEnrichedGrass extends BlockBush { public BlockEnrichedGrass() { super(Material.grass); this.setBlockName("asdsa"); this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F); } @SideOnly(Side.CLIENT) public void registerIcons(IIconRegister i) { this.blockIcon = i.registerIcon(Qwertyuiop.MODID + ":texture.png"); } @SideOnly(Side.CLIENT) public IIcon getIcon(int par1, int par2) { return this.blockIcon; } }
  21. I really don'y know why my custom entity isn't spawning, I have done it like this before. I believe I am missing something really obvious here, but I am not sure. package com.livingblocks.entities; import java.util.List; import net.minecraft.entity.EntityList; import net.minecraft.entity.EnumCreatureType; import net.minecraft.world.biome.BiomeGenBase; import net.minecraftforge.common.BiomeDictionary; import net.minecraftforge.common.BiomeDictionary.Type; import com.livingblocks.main.LivingBlocks; import cpw.mods.fml.common.registry.EntityRegistry; public class RegisterEntities { public static void registerEntity() { createEntityBlockAll(EntityBlockAll.class, "entity_block_all", 0x79553A, 0x6FAE44); } public static void createEntityBlockAll(Class entityClass, String entityName, int solidColour, int spotColour) { int randomID = EntityRegistry.findGlobalUniqueEntityId(); EntityRegistry.registerGlobalEntityID(entityClass, entityName, randomID); EntityRegistry.registerModEntity(entityClass, entityName, randomID, LivingBlocks.modInstance, 64, 1, true); EntityRegistry.addSpawn(entityName, 1000, 10, 10, EnumCreatureType.monster); CreateEgg(randomID, solidColour, spotColour); } public static void createEntityBlock(Class entityClass, String entityName, int solidColour, int spotColour) { BiomeGenBase[] a = BiomeDictionary.getBiomesForType(Type.FOREST); BiomeGenBase[] b = BiomeDictionary.getBiomesForType(Type.PLAINS); int randomID = EntityRegistry.findGlobalUniqueEntityId(); EntityRegistry.registerGlobalEntityID(entityClass, entityName, randomID); EntityRegistry.registerModEntity(entityClass, entityName, randomID, LivingBlocks.modInstance, 64, 1, true); EntityRegistry.addSpawn(entityName, 1000, 1, 1, EnumCreatureType.creature, a); EntityRegistry.addSpawn(entityName, 1000, 1, 1, EnumCreatureType.creature, b); CreateEgg(randomID, solidColour, spotColour); } private static void CreateEgg(int randomID, int solidColour, int spotColour) { EntityList.entityEggs.put(Integer.valueOf(randomID), new EntityList.EntityEggInfo(randomID, solidColour, spotColour)); } } package com.livingblocks.main; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.item.Item; import net.minecraftforge.common.BiomeDictionary; import com.livingblocks.entities.RegisterEntities; import com.livingblocks.items.ItemTab; import com.livingblocks.network.ClientPacketHandler; import com.livingblocks.network.ServerPacketHandler; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod.EventHandler; import cpw.mods.fml.common.Mod.Instance; import cpw.mods.fml.common.SidedProxy; import cpw.mods.fml.common.event.FMLInitializationEvent; import cpw.mods.fml.common.event.FMLPostInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.network.FMLEventChannel; import cpw.mods.fml.common.network.NetworkRegistry; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @Mod(name = LivingBlocks.NAME, modid = LivingBlocks.MODID, version = LivingBlocks.VERSION) public class LivingBlocks { public static final String NAME = "Living Blocks"; public static final String MODID = "livingblocks"; public static final String VERSION = "2.0.0"; public static final String networkChannelName = "Living Blocks"; public static FMLEventChannel channel; public final static int PACKET_TYPE_ENTITY_SYNC = 1; public final static int PACKET_TYPE_C2S_TEST = 1; @SidedProxy(clientSide = "com.livingblocks.main.ClientProxy", serverSide = "com.livingblocks.main.ServerProxy") public static ServerProxy proxy; @Instance(LivingBlocks.MODID) public static LivingBlocks modInstance; public static Item itemTab = new ItemTab(); public static CreativeTabs tabBlocklings = new CreativeTabs("tabBlocklings") { @Override @SideOnly(Side.CLIENT) public Item getTabIconItem() { return itemTab; } }; @EventHandler public void preInit(FMLPreInitializationEvent e) { RegisterEntities.registerEntity(); BiomeDictionary.registerAllBiomes(); proxy.renderThings(); } @EventHandler public void init(FMLInitializationEvent e) { LivingBlocks.channel = NetworkRegistry.INSTANCE.newEventDrivenChannel(LivingBlocks.networkChannelName); LivingBlocks.channel.register(new ServerPacketHandler()); LivingBlocks.channel.register(new ClientPacketHandler()); proxy.renderThings(); } @EventHandler public void postInit(FMLPostInitializationEvent e) { } }
  22. I have all this along with the "this.func_152115_b(entityPlayer.getUniqueID().toString());" this.setTamed(true); this.setPathToEntity((PathEntity) null); this.setAttackTarget((EntityLivingBase) null); this.func_152115_b(entityPlayer.getUniqueID().toString()); this.playTameEffect(true); this.worldObj.setEntityState(this, (byte) 7); if(!entityPlayer.capabilities.isCreativeMode) itemstack.stackSize--;
  23. That definitely works, thanks. Does anyone know any other methods I can use to either break or place blocks, from both 1.7.2 and 1.7.10.
×
×
  • Create New...

Important Information

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