Posted June 7, 20169 yr Attempting to build a simple item that can be crafted (I have the crafting path set up and all) and used as a permanent egg essentially. I'm hoping for it to be able to spawn any random monster on whatever ground is right clicked with it. My current code is basically this public boolean onItemUse(ItemStack item, EntityPlayer player, World world, int x, int y, int z, int side, float xOffset, float yOffset, float zOffSet) { if (world.getBlockId(x, y + 1, z) == 0 && (world.getBlockId(x, y, z) == Block.grass.blockID || world.getBlockId(x, y, z) == Block.stone.blockID || world.getBlockId(x, y, z) == Block.dirt.blockID || world.getBlockId(x, y, z) == Block.sand.blockID)) { int x = math.random(); if(x<0.05) { EntitySkeleton ent = new EntitySkeleton(world); ent.setLocationAndAngles(x, y + 1, z, MathHelper.wrapAngleTo180_float(world.rand.nextFloat() * 360.0F), 0.0F); ent.initCreature(); world.spawnEntityInWorld(ent); } else if(x<0.1) { ...and so on } return true; } I keep on coming up with these errors: Description Resource Path Location Type Block cannot be resolved to a variable Book.java /Minecraft/src/main/java/com/daniel/fail line 11 Java Problem Block cannot be resolved to a variable Book.java /Minecraft/src/main/java/com/daniel/fail line 11 Java Problem Block cannot be resolved to a variable Book.java /Minecraft/src/main/java/com/daniel/fail line 11 Java Problem Block cannot be resolved to a variable Book.java /Minecraft/src/main/java/com/daniel/fail line 11 Java Problem EntitySkeleton cannot be resolved to a type Book.java /Minecraft/src/main/java/com/daniel/fail line 13 Java Problem EntitySkeleton cannot be resolved to a type Book.java /Minecraft/src/main/java/com/daniel/fail line 13 Java Problem ItemStack cannot be resolved to a type Book.java /Minecraft/src/main/java/com/daniel/fail line 8 Java Problem MathHelper cannot be resolved Book.java /Minecraft/src/main/java/com/daniel/fail line 14 Java Problem World cannot be resolved to a type Book.java /Minecraft/src/main/java/com/daniel/fail line 8 Java Problem and my full code is package com.derp.fail; import net.minecraft.block.Block; import net.minecraft.entity.monster.EntitySkeleton; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.MathHelper; import net.minecraft.world.World; public class Book extends Item { public Book() { } public boolean onItemUse(ItemStack item, EntityPlayer player, World world, int x, int y, int z, int side, float xOffset, float yOffset, float zOffSet) { if (world.getBlockMetadata(x, y + 1, z) == 0 && (world.getBlockMetadata(x, y, z) == Blocks.grass.blockID || world.getBlockMetadata(x, y, z) == Blocks.stone.blockID || world.getBlockMetadata(x, y, z) == Blocks.dirt.getBlockMetadata(x, y, z) || world.getBlockMetadata(x, y, z) == Blocks.sand.blockID)) { EntitySkeleton ent = new EntitySkeleton(world); ent.setLocationAndAngles(x, y + 1, z, MathHelper.wrapAngleTo180_float(world.rand.nextFloat() * 360.0F), 0.0F); ent.initCreature(); world.spawnEntityInWorld(ent); } return true; } } Thanks in advance for any help/suggestion that you could provide. I'd like to finish this ASAP, so a quick response would be greatly appreciated.
June 7, 20169 yr There is no Block#blockID field in 1.7.10 since IDs are automatically managed. Use World#getBlock and compare the Block instances directly with == . There is no initCreature method in any subclass of Entity . Were you looking for EntityLiving#onSpawnWithEgg ? Always annotate override methods with @Override so you get a compilation error if the method doesn't actually override a super method. 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.
June 7, 20169 yr Are you using Eclipse as your IDE? If so, then it should be helping you to see syntax and semantic errors. Between Eclipse's bright red X's, its power features, and your knowledge of Java, you should be able to get pretty close to compiled before coming here. If not, then tell us what's still marked red in Eclipse so we can point you toward the Forge class / method that you need to pick up. If you're using Eclipse correctly (and have an uncorrupted decompiled workspace), then gradle will never give you compilation errors. PS: If you're using Eclipse for Java but it's unfamiliar to you, then take time out to go walk through an Eclipse tutorial. The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.
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.