Jump to content

Recommended Posts

Posted

So I have a strange crash with making my items spawn particles when they get hit using this:

 

@Override
public boolean hitEntity(ItemStack par1ItemStack, EntityLivingBase hit, EntityLivingBase player) {
	Random r = new Random();
		for(int i = 0; i < 10; i++)
			ClientProxy.spawnParticle(EnumParticlesClasses.SNOWBALL_POOF, player.worldObj, hit.posX + r.nextFloat() - 0.5F, hit.posY + 0.5D + r.nextFloat(), hit.posZ + r.nextFloat() - 0.5F, false);
	return super.hitEntity(par1ItemStack, hit, player);
}

 

 

public static void spawnParticle(EnumParticlesClasses particle, World worldObj, double posX, double posY, double posZ, boolean b) {
	try {
		EntityFX fx = null;
		if(b) {
			fx = (EntityFX)particle.getParticle().getConstructor(World.class, double.class, double.class, double.class).newInstance(worldObj, posX, posY, posZ);
		} else {
			fx = (EntityFX)particle.getParticle().getConstructor(World.class, double.class, double.class, double.class, double.class, double.class, double.class).newInstance(worldObj, posX, posY, posZ, 0D, 0D, 0D);
		}
		Minecraft.getMinecraft().effectRenderer.addEffect(fx);
	} catch (Exception e) {
		e.printStackTrace();
	}
}

 

 

public enum EnumParticlesClasses {

LAVA(EntityLavaFX.class),
SMOKE(EntitySmokeFX.class),
FLAME(EntityFlameFX.class),
SNOWBALL_POOF(EntitySnowShovelFX.class);

private Class particle;

private EnumParticlesClasses(Class<? extends EntityFX> clazz) {
	particle = clazz;
}

public Class getParticle() {
	return particle;
}

 

Crash report:

 

  Reveal hidden contents

 

 

The crash seems to be caused at "moveEntity(Entity)".

 

The particles spawn but when they hit the ground they crash.

 

So if anyone can help, that would be great... :)

Former developer for DivineRPG, Pixelmon and now the maker of Essence of the Gods

Posted

Okay, so I added this to my main class:

public static ClientProxy clientProxy;

 

this is now the particle method:

public void spawnParticle(EnumParticlesClasses particle, World worldObj, double posX, double posY, double posZ, boolean b) {
	try {
		EntityFX fx = null;
		if(b) {
			fx = (EntityFX)particle.getParticle().getConstructor(World.class, double.class, double.class, double.class).newInstance(worldObj, posX, posY, posZ);
		} else {
			fx = (EntityFX)particle.getParticle().getConstructor(World.class, double.class, double.class, double.class, double.class, double.class, double.class).newInstance(worldObj, posX, posY, posZ, 0D, 0D, 0D);
		}
		Minecraft.getMinecraft().effectRenderer.addEffect(fx);
	} catch (Exception e) {
		e.printStackTrace();
	}
}

 

and am now using this in the item class:

@Override
public boolean hitEntity(ItemStack par1ItemStack, EntityLivingBase hit, EntityLivingBase player) {
	Random r = new Random();
		for(int i = 0; i < 40; i++) {
			if(!player.worldObj.isRemote) {
				Essence.clientProxy.spawnParticle(EnumParticlesClasses.FLAME, player.worldObj, hit.posX + r.nextFloat() - 0.5F, hit.posY + 0.5D + r.nextFloat(), hit.posZ + r.nextFloat() - 0.5F, false);
				Essence.clientProxy.spawnParticle(EnumParticlesClasses.SMOKE, player.worldObj, hit.posX + r.nextFloat() - 0.5F, hit.posY + 0.5D + r.nextFloat(), hit.posZ + r.nextFloat() - 0.5F, false);
				Essence.clientProxy.spawnParticle(EnumParticlesClasses.LAVA, player.worldObj, hit.posX + r.nextFloat() - 0.5F, hit.posY + 0.5D + r.nextFloat(), hit.posZ + r.nextFloat() - 0.5F, true);
	}
	return super.hitEntity(par1ItemStack, hit, player);
}

Former developer for DivineRPG, Pixelmon and now the maker of Essence of the Gods

Posted

Wait... you don't think that i think that just because the method is in the ClientProxy that it automatically get called on the client do you?! I just put it there because I don't want to make a new class for client methods.

Former developer for DivineRPG, Pixelmon and now the maker of Essence of the Gods

Posted

So i changed this to make it be called on the client only:

 

@Override
public boolean hitEntity(ItemStack par1ItemStack, EntityLivingBase hit, EntityLivingBase player) {
	Random r = new Random();
	hit.setFire(10);
	if(Config.spawnSwordParticles) {
		for(int i = 0; i < 70; i++) {
			Essence.proxy.spawnParticle(EnumParticlesClasses.FLAME, player.worldObj, hit.posX + r.nextFloat() - 0.5F, hit.posY + 0.5D + r.nextFloat(), hit.posZ + r.nextFloat() - 0.5F, false);
			Essence.proxy.spawnParticle(EnumParticlesClasses.SMOKE, player.worldObj, hit.posX + r.nextFloat() - 0.5F, hit.posY + 0.5D + r.nextFloat(), hit.posZ + r.nextFloat() - 0.5F, false);
			Essence.proxy.spawnParticle(EnumParticlesClasses.LAVA, player.worldObj, hit.posX + r.nextFloat() - 0.5F, hit.posY + 0.5D + r.nextFloat(), hit.posZ + r.nextFloat() - 0.5F, true);
		}
	}
	return super.hitEntity(par1ItemStack, hit, player);
}

 

common proxy

public void spawnParticle(EnumParticlesClasses particle, World worldObj, double posX, double posY, double posZ, boolean b) { }

 

and it now overrides the method in the client proxy

Former developer for DivineRPG, Pixelmon and now the maker of Essence of the Gods

Posted

I forgot to mention, this is the new method:

 

@Override
public void spawnParticle(EnumParticlesClasses particle, World worldObj, double posX, double posY, double posZ, boolean b) {
	if(!worldObj.isRemote) {
		try {
			EntityFX fx = null;
			if(b) {
				fx = (EntityFX)particle.getParticle().getConstructor(World.class, double.class, double.class, double.class).newInstance(worldObj, posX, posY, posZ);
			} else {
				fx = (EntityFX)particle.getParticle().getConstructor(World.class, double.class, double.class, double.class, double.class, double.class, double.class).newInstance(worldObj, posX, posY, posZ, 0D, 0D, 0D);
			}
			Minecraft.getMinecraft().effectRenderer.addEffect(fx);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

Former developer for DivineRPG, Pixelmon and now the maker of Essence of the Gods

Posted

So i basically changed these:

 

@Override
public void spawnParticle(EnumParticlesClasses particle, World worldObj, double x, double y, double z) {
	if(!worldObj.isRemote) {
		try {
			worldObj.spawnParticle(particle.getParticle(), x, y, z, 0D, 0D, 0D);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

 

public enum EnumParticlesClasses {

LAVA("lava"),
SMOKE("smoke"),
FLAME("flame"),
SNOWBALL_POOF("snowballpoof");

private String particle;

private EnumParticlesClasses(String name) {
	particle = name;
}

public String getParticle() {
	return particle;
}
}

 

@Override
public boolean hitEntity(ItemStack par1ItemStack, EntityLivingBase hit, EntityLivingBase player) {
	Random r = new Random();
	hit.setFire(10);
	if(Config.spawnSwordParticles) {
		for(int i = 0; i < 70; i++) {
			Essence.proxy.spawnParticle(EnumParticlesClasses.FLAME, player.worldObj, hit.posX + r.nextFloat() - 0.5F, hit.posY + 0.5D + r.nextFloat(), hit.posZ + r.nextFloat() - 0.5F);
			Essence.proxy.spawnParticle(EnumParticlesClasses.SMOKE, player.worldObj, hit.posX + r.nextFloat() - 0.5F, hit.posY + 0.5D + r.nextFloat(), hit.posZ + r.nextFloat() - 0.5F);
			Essence.proxy.spawnParticle(EnumParticlesClasses.LAVA, player.worldObj, hit.posX + r.nextFloat() - 0.5F, hit.posY + 0.5D + r.nextFloat(), hit.posZ + r.nextFloat() - 0.5F);
		}
	}
	return super.hitEntity(par1ItemStack, hit, player);
}

 

And it doesn't spawn any particles at all

Former developer for DivineRPG, Pixelmon and now the maker of Essence of the Gods

Posted

This is still not spawning anything...

@Override
public void spawnParticle(EnumParticlesClasses particle, World worldObj, double x, double y, double z) {
	if(worldObj.isRemote) {
		worldObj.spawnParticle(particle.getParticle(), x, y, z, 0D, 0D, 0D);
	}
}

Former developer for DivineRPG, Pixelmon and now the maker of Essence of the Gods

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.