Posted March 16, 201510 yr 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); } } }
March 16, 201510 yr 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. http://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.
March 16, 201510 yr Author 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.)
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.