DonKresenko Posted December 31, 2014 Share Posted December 31, 2014 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"); } Quote _ ___ ___| |__ _ __ / __/ __| '_ \| '_ \ \__ \__ \ | | | | | | |___/___/_| |_|_| |_| Link to comment Share on other sites More sharing options...
Nephroid Posted December 31, 2014 Share Posted December 31, 2014 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. Quote GitHub|Recipe API Proposal Link to comment Share on other sites More sharing options...
larsgerrits Posted December 31, 2014 Share Posted December 31, 2014 Yes, the method is executed twice: on the server and on the client. Quote 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/ Link to comment Share on other sites More sharing options...
DonKresenko Posted December 31, 2014 Author Share Posted December 31, 2014 No luck. Even when i put this... if(world.getBlock(i, j, k) == Test.testBlock){...} ...it isn't working Quote _ ___ ___| |__ _ __ / __/ __| '_ \| '_ \ \__ \__ \ | | | | | | |___/___/_| |_|_| |_| Link to comment Share on other sites More sharing options...
pickaxe_engineer Posted December 31, 2014 Share Posted December 31, 2014 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 Quote 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. Link to comment Share on other sites More sharing options...
Nephroid Posted December 31, 2014 Share Posted December 31, 2014 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). Quote GitHub|Recipe API Proposal Link to comment Share on other sites More sharing options...
DonKresenko Posted December 31, 2014 Author Share Posted December 31, 2014 Thank you for replaying, but removing the clientside only doesn't fix this. The item is spawned twice again Quote _ ___ ___| |__ _ __ / __/ __| '_ \| '_ \ \__ \__ \ | | | | | | |___/___/_| |_|_| |_| Link to comment Share on other sites More sharing options...
DonKresenko Posted January 1, 2015 Author Share Posted January 1, 2015 Any ideas? Quote _ ___ ___| |__ _ __ / __/ __| '_ \| '_ \ \__ \__ \ | | | | | | |___/___/_| |_|_| |_| Link to comment Share on other sites More sharing options...
Ernio Posted January 1, 2015 Share Posted January 1, 2015 Could you post updated code (or update 1st post), there is just no way this spawns twice if you did as suggested. Quote 1.7.10 is no longer supported by forge, you are on your own. Link to comment Share on other sites More sharing options...
DonKresenko Posted January 1, 2015 Author Share Posted January 1, 2015 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 Quote _ ___ ___| |__ _ __ / __/ __| '_ \| '_ \ \__ \__ \ | | | | | | |___/___/_| |_|_| |_| Link to comment Share on other sites More sharing options...
larsgerrits Posted January 1, 2015 Share Posted January 1, 2015 Is there somewhere you call the onBlockAdded method yourself? If so,you shouldn't. Quote 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/ Link to comment Share on other sites More sharing options...
DonKresenko Posted January 1, 2015 Author Share Posted January 1, 2015 I call this method in my block class, nowhere else Quote _ ___ ___| |__ _ __ / __/ __| '_ \| '_ \ \__ \__ \ | | | | | | |___/___/_| |_|_| |_| Link to comment Share on other sites More sharing options...
DonKresenko Posted January 1, 2015 Author Share Posted January 1, 2015 In other word, what should i do in order to my item to dorp whenever the block is placed? Quote _ ___ ___| |__ _ __ / __/ __| '_ \| '_ \ \__ \__ \ | | | | | | |___/___/_| |_|_| |_| Link to comment Share on other sites More sharing options...
DonKresenko Posted January 1, 2015 Author Share Posted January 1, 2015 Sorry, I don't quite get it Quote _ ___ ___| |__ _ __ / __/ __| '_ \| '_ \ \__ \__ \ | | | | | | |___/___/_| |_|_| |_| Link to comment Share on other sites More sharing options...
DonKresenko Posted January 1, 2015 Author Share Posted January 1, 2015 Oh, wait. Nevermind. I fixed it Quote _ ___ ___| |__ _ __ / __/ __| '_ \| '_ \ \__ \__ \ | | | | | | |___/___/_| |_|_| |_| Link to comment Share on other sites More sharing options...
Recommended Posts
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.