Posted December 31, 201410 yr I'm trying to make whenever I place my block, the item pops out. The problem is, that the method is somehow executed twice. Here's my code @SideOnly(Side.CLIENT) public void onBlockAdded(World world, int i, int j, int k) { super.onBlockAdded(world, i, j, k); if(!world.isRemote) { float f = 0.7F; double d = world.rand.nextFloat() * f + (1.0F - f) * 0.5D; double d1 = world.rand.nextFloat() * f + (1.0F - f) * 0.2D + 0.6D; double d2 = world.rand.nextFloat() * f + (1.0F - f) * 0.5D; EntityItem pan = new EntityItem(world, i + d, j + d1, k + d2, new ItemStack(Items.blaze_rod, 1)); pan.delayBeforeCanPickup = 5; world.spawnEntityInWorld(pan); } System.out.println("executed"); } _ ___ ___| |__ _ __ / __/ __| '_ \| '_ \ \__ \__ \ | | | | | | |___/___/_| |_|_| |_|
December 31, 201410 yr I'm pretty sure it's because your print statement is both client and server side. If you put it inside the if block, it should only be executed once. GitHub|Recipe API Proposal
December 31, 201410 yr Yes, the method is executed twice: on the server and on the client. Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support. 1.12 -> 1.13 primer by williewillus. 1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support. http://www.howoldisminecraft1710.today/
December 31, 201410 yr Author No luck. Even when i put this... if(world.getBlock(i, j, k) == Test.testBlock){...} ...it isn't working _ ___ ___| |__ _ __ / __/ __| '_ \| '_ \ \__ \__ \ | | | | | | |___/___/_| |_|_| |_|
December 31, 201410 yr Hi I assume your issue is that you marked the method to clientside only. Read this: http://www.minecraftforge.net/forum/index.php/topic,22764.0.html Sincerely -pick Since English is not my mother tongue, my sentences may are confusing. I'm coding java for a long time now - just MC and forge stop me sometimes.
December 31, 201410 yr No luck. Even when i put this... if(world.getBlock(i, j, k) == Test.testBlock){...} ...it isn't working How does this new piece of code relate to the original code? Anyways, like I said before, if you move the print statement inside the if block, it should only be printed once. if(!world.isRemote) { ... print("Hello World"); } Also remove the SideOnly annotation, that physically removes code from the client/server (think of it as commenting code out on one side). GitHub|Recipe API Proposal
December 31, 201410 yr Author Thank you for replaying, but removing the clientside only doesn't fix this. The item is spawned twice again _ ___ ___| |__ _ __ / __/ __| '_ \| '_ \ \__ \__ \ | | | | | | |___/___/_| |_|_| |_|
January 1, 201510 yr Author Any ideas? _ ___ ___| |__ _ __ / __/ __| '_ \| '_ \ \__ \__ \ | | | | | | |___/___/_| |_|_| |_|
January 1, 201510 yr Could you post updated code (or update 1st post), there is just no way this spawns twice if you did as suggested. 1.7.10 is no longer supported by forge, you are on your own.
January 1, 201510 yr Author This is what i have currently in my block class //@SideOnly(Side.CLIENT) public void onBlockAdded(World world, int i, int j, int k) { super.onBlockAdded(world, i, j, k); if (!world.isRemote && world.getBlock(i,j,k) == Test.testBlock) { float f = 0.7F; double d = world.rand.nextFloat() * f + (1.0F - f) * 0.5D; double d1 = world.rand.nextFloat() * f + (1.0F - f) * 0.2D + 0.6D; double d2 = world.rand.nextFloat() * f + (1.0F - f) * 0.5D; EntityItem entityitem = new EntityItem(world, i + d, j + d1, k + d2, new ItemStack(Items.blaze_powder, 1)); entityitem.delayBeforeCanPickup = 5; world.spawnEntityInWorld(entityitem); } } And, as I said, the items is spawned twice _ ___ ___| |__ _ __ / __/ __| '_ \| '_ \ \__ \__ \ | | | | | | |___/___/_| |_|_| |_|
January 1, 201510 yr Is there somewhere you call the onBlockAdded method yourself? If so,you shouldn't. Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support. 1.12 -> 1.13 primer by williewillus. 1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support. http://www.howoldisminecraft1710.today/
January 1, 201510 yr Author I call this method in my block class, nowhere else _ ___ ___| |__ _ __ / __/ __| '_ \| '_ \ \__ \__ \ | | | | | | |___/___/_| |_|_| |_|
January 1, 201510 yr Author In other word, what should i do in order to my item to dorp whenever the block is placed? _ ___ ___| |__ _ __ / __/ __| '_ \| '_ \ \__ \__ \ | | | | | | |___/___/_| |_|_| |_|
January 1, 201510 yr Author Sorry, I don't quite get it _ ___ ___| |__ _ __ / __/ __| '_ \| '_ \ \__ \__ \ | | | | | | |___/___/_| |_|_| |_|
January 1, 201510 yr Author Oh, wait. Nevermind. I fixed 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.