Jump to content

Grenade Explosions don't destroy blocks


Krazykid1117

Recommended Posts

I have a grenade in my mod which is thrown and on contact with an object or entity explodes. the explosion does not hurt entities and appears to break blocks but the blocks are only invisible. When you leave the world and get back on it the blocks revert to being visible again. If anyone could tell me how to fix this that would be great! Code for the grenade entity below.

 

 

package com.krazykid1117.entity;

 

import net.minecraft.entity.Entity;

import net.minecraft.entity.EntityLivingBase;

import net.minecraft.entity.projectile.EntityThrowable;

import net.minecraft.util.MovingObjectPosition;

import net.minecraft.world.World;

 

public class EntityGrenade extends EntityThrowable{

 

public EntityGrenade(World p_i1776_1_) {

super(p_i1776_1_);

}

public EntityGrenade(World world, EntityLivingBase entity){

super(world, entity);

}

@Override

protected void onImpact(MovingObjectPosition p_70184_1_) {

for(int i = 0; i < 10; i ++){

this.worldObj.spawnParticle("largesmoke", this.posX, this.posY, this.posZ, 0f, 0f, 0f);

}

 

if(!this.worldObj.isRemote);

this.setDead();

if(this.worldObj.isRemote){

this.worldObj.createExplosion((Entity) null, this.posX, this.posY, this.posZ, 5.0f, true);

}

 

}

 

}

 

 

Link to comment
Share on other sites

Try this:

 

protected void onImpact(MovingObjectPosition p_70184_1_) {
  if(!this.worldObj.isRemote) {
    this.worldObj.createExplosion((Entity) null, this.posX, this.posY, this.posZ, 5.0f, true);
    this.setDead();
  }
}

 

You only need to create explosion in server side. The explosion data would be transported to client side via network.

The last parameter of createExplosion decides whether to destroy blocks. Set it false if you don't want blocks destroyed.

Author of Tao Land Mod.

width=200 height=69http://taoland.herbix.me/images/1/14/TaoLandLogo.png[/img]

Also, author of RenderTo

----

I'm not an English native speaker. I just try my best.

Link to comment
Share on other sites

First of all, this line:

 

if(!this.worldObj.isRemote);

does nothing but waste CPU cycles.

 

And then you explicitly create the explosion only on the client. That's not gonna work.

Try this:

 

protected void onImpact(MovingObjectPosition p_70184_1_) {
  if(!this.worldObj.isRemote) {
    this.worldObj.createExplosion((Entity) null, this.posX, this.posY, this.posZ, 5.0f, true);
    this.setDead();
  }
}

 

You only need to create explosion in server side. The explosion data would be transported to client side via network.

The last parameter of createExplosion decides whether to destroy blocks. Set it false if you don't want blocks destroyed.

 

How do I get this to happen on the server's side?

(If this is something very simple that I am missing I am sorry I am new to coding.)

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.