Jump to content

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


Recommended Posts

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

_         

___ ___| |__  _ __ 

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

\__ \__ \ | | | | | |

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

Posted

No luck. Even when i put this...

 

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

 

...it isn't working

_         

___ ___| |__  _ __ 

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

\__ \__ \ | | | | | |

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

Posted

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

Posted

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

_         

___ ___| |__  _ __ 

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

\__ \__ \ | | | | | |

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

Posted

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.

Posted

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

_         

___ ___| |__  _ __ 

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

\__ \__ \ | | | | | |

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

Posted

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

_         

___ ___| |__  _ __ 

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

\__ \__ \ | | | | | |

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

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.