Jump to content

[SOLVED][1.7.10] On block placed method is executed twice?


DonKresenko

Recommended Posts

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

_         

___ ___| |__  _ __ 

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

\__ \__ \ | | | | | |

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

Link to comment
Share on other sites

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/

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

_         

___ ___| |__  _ __ 

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

\__ \__ \ | | | | | |

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

Link to comment
Share on other sites

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/

Link to comment
Share on other sites

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

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.