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.

THE_GOLDEN_CASTLE

Members
  • Joined

  • Last visited

  1. Thank you! I didn't intend to have 2 preInitializationEvents, I copied the recipe portion from another mod I was working on and accidentally grabbed that part. That makes sense that the item should be registered before the recipe. It looks like the if (!world.isRemote) fixed the item issue also. Thank you very much!
  2. Mecblader: I had this same issue before I created the crafting recipe, so i don't think that is the problem Edit: I meant to say: I had the "items can't be picked up issue" before I had the crafting recipe. You might be on to something about the crash on crafting. I will have to dig deeper on this. larsgerrits: I changed the shearSheep method to include if (!world.isRemote), but now it crashes every time I try to craft the item??? code here: public void shearSheep(World world, int x, int y, int z, Entity target) { if (!world.isRemote) { Entity theSheep = (Entity) target; if (target instanceof IShearable) { IShearable Entity = (IShearable) theSheep; if (Entity.isShearable(null, world, x, y, z)) { ArrayList<ItemStack> drops = ((IShearable) theSheep) .onSheared(null, world, (int) target.posX, (int) target.posY, (int) target.posZ, 3); Random rand = new Random(); for (ItemStack stack : drops) { EntityItem ent = ((Entity) Entity).entityDropItem( stack, 1.0F); ent.motionY += rand.nextFloat() * 0.05F; ent.motionX += (rand.nextFloat() - rand.nextFloat()) * 0.1F; ent.motionZ += (rand.nextFloat() - rand.nextFloat()) * 0.1F; } } } else { } } } Here is the message from the server: java.lang.NullPointerException at net.minecraft.item.ItemStack.func_77980_a(ItemStack.java:385) ~[add.class:?] at net.minecraft.inventory.SlotCrafting.func_75208_c(SlotCrafting.java:53) ~[aax.class:?] at net.minecraft.inventory.SlotCrafting.func_82870_a(SlotCrafting.java:110) ~[aax.class:?] at net.minecraft.inventory.Container.func_75144_a(SourceFile:238) ~[zs.class:?] at net.minecraft.network.NetHandlerPlayServer.func_147351_a(NetHandlerPlayServer.java:878) ~[nh.class:?] at net.minecraft.network.play.client.C0EPacketClickWindow.func_148833_a(SourceFile:32) ~[ix.class:?] at net.minecraft.network.play.client.C0EPacketClickWindow.func_148833_a(SourceFile:10) ~[ix.class:?] at net.minecraft.network.NetworkManager.func_74428_b(NetworkManager.java:212) ~[ej.class:?] at net.minecraft.network.NetworkSystem.func_151269_c(NetworkSystem.java:165) [nc.class:?] at net.minecraft.server.MinecraftServer.func_71190_q(MinecraftServer.java:659) [MinecraftServer.class:?] at net.minecraft.server.dedicated.DedicatedServer.func_71190_q(DedicatedServer.java:335) [lt.class:?] at net.minecraft.server.MinecraftServer.func_71217_p(MinecraftServer.java:547) [MinecraftServer.class:?] at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:427) [MinecraftServer.class:?] at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:685) [li.class:?]
  3. Hi all, I have been working on making a simple mod that shears sheep when they collide with the block. Everything works fine, except sometimes on loading, the first time the block shears the sheep I can't pick up the wool. I think it has something to do with the server side not registering the items on the first collision but i am not sure. Another odd thing that happens, usually right after loading, the game sometimes crashes when crafting the "Shear Block". Here is the code: ShearBlockMod.java package net.bb.shearblockmod; import java.util.logging.LogManager; import java.util.logging.Logger; import net.minecraft.block.Block; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import cpw.mods.fml.common.FMLLog; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod.EventHandler; 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.registry.GameRegistry; @Mod(modid = ShearBlockMod.modid, version = ShearBlockMod.version) public class ShearBlockMod { public static final String modid = "ShearBlockMod"; public static final String version = "0.1 MC1.7.2"; @EventHandler public void preinit(FMLPreInitializationEvent event) { GameRegistry.addRecipe(new ItemStack(ShearBlockMod.shearBlock), new Object[]{ " A", " A ", "A ", 'A', Items.iron_ingot}); } public static CreativeTabs tabExample = new CreativeTabs("tabExample") { public Item getTabIconItem() { return Items.bed; } }; public static CreativeTabs tabExample2 = new CreativeTabs("tabExample2") { public Item getTabIconItem() { return Item.getItemFromBlock(Blocks.carpet); } }; public static Item tutorialItem; public static Block shearBlock; @EventHandler public void preInit(FMLPreInitializationEvent event) { shearBlock = new BlockShearBlock().setBlockName("shearBlock").setCreativeTab(tabExample2).setBlockTextureName(modid + ":" + "shearBlock"); GameRegistry.registerBlock(shearBlock, "shearBlock"); tutorialItem = new Item().setCreativeTab(tabExample).setUnlocalizedName("tutorialItem").setTextureName(modid + ":" + "tutorialItem"); GameRegistry.registerItem(tutorialItem, "tutorialItem"); } @EventHandler public void init(FMLInitializationEvent event) { } @EventHandler public void postInit(FMLPostInitializationEvent event) { } } BlockShearBlock.java package net.bb.shearblockmod; import java.util.ArrayList; import java.util.Random; import net.minecraft.block.*; import net.minecraft.block.material.Material; import net.minecraft.entity.Entity; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; import net.minecraft.util.AxisAlignedBB; import net.minecraft.world.World; import net.minecraftforge.common.IShearable; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; public class BlockShearBlock extends Block{ boolean powered; public BlockShearBlock(){ super(Material.rock); this.setTickRandomly(true); } public void onBlockAdded(World world, int x, int y, int z, Block id) { if (!world.isRemote) { //AxisAlignedBB myAABB = AxisAlignedBB.getBoundingBox(x+1, y+1, z+1, x-1, y+2, z-1); if (world.getBlockPowerInput(x, y, z) > 0) { System.out.println("new power on!"); powered = true; } else { System.out.println("new power off!"); powered = false; } } //world.notifyBlocksOfNeighborChange(x, y, z, this); } @Override public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9) { int shearBlockID = Block.getIdFromBlock(null); if (!par1World.isRemote) System.out.println("Block Activated Test" + shearBlockID ); return true; } public void shearSheep(World world, int x, int y, int z, Entity target) { Entity theSheep = (Entity)target; if (target instanceof IShearable) { IShearable Entity = (IShearable)theSheep; if (Entity.isShearable(null, world , x, y, z)) { ArrayList<ItemStack> drops = ((IShearable) theSheep).onSheared(null, world, (int)target.posX, (int)target.posY, (int)target.posZ, 3); Random rand = new Random(); for(ItemStack stack : drops) { EntityItem ent = ((Entity) Entity).entityDropItem(stack, 1.0F); ent.motionY += rand.nextFloat() * 0.05F; ent.motionX += (rand.nextFloat() - rand.nextFloat()) * 0.1F; ent.motionZ += (rand.nextFloat() - rand.nextFloat()) * 0.1F; } } } } @Override public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int i, int j, int k) { float f = 0.0625F; return AxisAlignedBB.getBoundingBox((float)i + f, j, (float)k + f, (float)(i + 1) - f, (float)(j + 1) - f, (float)(k + 1) - f); } @Override public AxisAlignedBB getSelectedBoundingBoxFromPool(World world, int i, int j, int k) { float f = 0.0625F; return AxisAlignedBB.getBoundingBox((float)i + f, j, (float)k + f, (float)(i + 1) - f, j + 1, (float)(k + 1) - f); } @Override public void onEntityCollidedWithBlock(World world, int i, int j, int k, Entity entity) { //if(powered == true) { System.out.println("Engage Shearing!"); shearSheep(world, (int)entity.posX, (int)entity.posY, (int)entity.posZ, entity); } } } Any help would be much appreciated....

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.