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.

Featured Replies

Posted

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");
}

_         

___ ___| |__  _ __ 

/ __/ __| '_ \| '_ \

\__ \__ \ | | | | | |

|___/___/_| |_|_| |_|

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/

  • Author

No luck. Even when i put this...

 

if(world.getBlock(i, j, k) == Test.testBlock){...}

 

...it isn't working

_         

___ ___| |__  _ __ 

/ __/ __| '_ \| '_ \

\__ \__ \ | | | | | |

|___/___/_| |_|_| |_|

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).

  • Author

Thank you for replaying, but removing the clientside only doesn't fix this. The item is spawned twice again

_         

___ ___| |__  _ __ 

/ __/ __| '_ \| '_ \

\__ \__ \ | | | | | |

|___/___/_| |_|_| |_|

  • Author

Any ideas?

_         

___ ___| |__  _ __ 

/ __/ __| '_ \| '_ \

\__ \__ \ | | | | | |

|___/___/_| |_|_| |_|

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.

  • 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

_         

___ ___| |__  _ __ 

/ __/ __| '_ \| '_ \

\__ \__ \ | | | | | |

|___/___/_| |_|_| |_|

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/

  • Author

I call this method in my block class, nowhere else

_         

___ ___| |__  _ __ 

/ __/ __| '_ \| '_ \

\__ \__ \ | | | | | |

|___/___/_| |_|_| |_|

  • Author

In other word, what should i do in order to my item to dorp whenever the block is placed?

_         

___ ___| |__  _ __ 

/ __/ __| '_ \| '_ \

\__ \__ \ | | | | | |

|___/___/_| |_|_| |_|

  • Author

Sorry, I don't quite get it

_         

___ ___| |__  _ __ 

/ __/ __| '_ \| '_ \

\__ \__ \ | | | | | |

|___/___/_| |_|_| |_|

  • 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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

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.