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

}

 

}

 

}

 

 

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.

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

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.