Jump to content

[1.8] Explosion particles not visible?


DonkeyCore

Recommended Posts

Sorry for posting again so soon, but I have another problem.

I have a bomb block that causes an explosion based on redstone signals / time settings. It works fine, but the explosion particles (EXPLOSION_LARGE / EXPLOSION_HUGE) do not appear. I have a subclass of explosion that I'm using, but it works virtually the same way. Here is the method used to summon the explosion:

	public static final FusionExplosion createFusionExplosion(World w, double x, double y, double z, float size, boolean fire, boolean smoke, boolean strong) {
	FusionExplosion explosion = new FusionExplosion(w, null, x, y, z, size, fire, smoke, strong);
	if (ForgeEventFactory.onExplosionStart(w, explosion))
		return explosion;
	explosion.doExplosionA();
	explosion.doExplosionB(true);
	return explosion;
}

Here is FusionExplosion.class:

package donkeycore.fusion;

import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Random;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.enchantment.EnchantmentProtection;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.MathHelper;
import net.minecraft.util.Vec3;
import net.minecraft.world.Explosion;
import net.minecraft.world.World;
import net.minecraftforge.event.ForgeEventFactory;

import com.google.common.collect.Maps;
import com.google.common.collect.Sets;

public class FusionExplosion extends Explosion {

private final boolean f;
private final boolean s;
private final Random r;
private final World w;
private final double x;
private final double y;
private final double z;
private final Entity e;
private final float size;
private final List<Object> blocks;
private final Map<Object, Object> map;
private final boolean strong;

public FusionExplosion(World w, Entity e, double x, double y, double z, float size, List<Object> l) {
	this(w, e, x, y, z, size, false, true, l);
}

public FusionExplosion(World w, Entity e, double x, double y, double z, float size, boolean f, boolean s, List<Object> l) {
	this(w, e, x, y, z, size, f, s, false);
	blocks.addAll(l);
}

public FusionExplosion(World w, Entity e, double x, double y, double z, float size, boolean f, boolean s, boolean strong) {
	super(w, e, x, y, z, size, f, s);
	this.r = new Random();
	this.blocks = com.google.common.collect.Lists.newArrayList();
	this.map = Maps.newHashMap();
	this.w = w;
	this.e = e;
	this.size = size;
	this.x = x;
	this.y = y;
	this.z = z;
	this.f = f;
	this.s = s;
	this.strong = strong;
}

@SuppressWarnings({"unchecked", "rawtypes"})
public void doExplosionA() {
	HashSet<Object> hashset = Sets.newHashSet();
	for(int i = 0; i < 16; i++) {
		for(int j = 0; j < 16; j++) {
			for(int k = 0; k < 16; k++) {
				if ((i == 0) || (i == 15) || (j == 0) || (j == 15) || (k == 0) || (k == 15)) {
					double d0 = i / 15.0F * 2.0F - 1.0F;
					double d1 = j / 15.0F * 2.0F - 1.0F;
					double d2 = k / 15.0F * 2.0F - 1.0F;
					double d3 = Math.sqrt(d0 * d0 + d1 * d1 + d2 * d2);
					d0 /= d3;
					d1 /= d3;
					d2 /= d3;
					float f = this.size * (0.7F + this.w.rand.nextFloat() * 0.6F);
					double d4 = this.x;
					double d6 = this.y;
					double d8 = this.z;
					for(; f > 0.0F; f -= 0.22500001F) {
						BlockPos blockpos = new BlockPos(d4, d6, d8);
						IBlockState iblockstate = this.w.getBlockState(blockpos);
						if (iblockstate.getBlock().getMaterial() != Material.air) {
							float f2 = this.e != null ? this.e.getExplosionResistance(this, this.w, blockpos, iblockstate) : iblockstate.getBlock().getExplosionResistance(this.w, blockpos, (Entity) null, this);
							f -= (f2 + 0.3F) * 0.3F;
						}
						if ((f > 0.0F) && ((this.e == null) || (this.e.func_174816_a(this, this.w, blockpos, iblockstate, f)))) {
							hashset.add(blockpos);
						}
						d4 += d0 * 0.30000001192092896D;
						d6 += d1 * 0.30000001192092896D;
						d8 += d2 * 0.30000001192092896D;
					}
				}
			}
		}
	}
	this.blocks.addAll(hashset);
	float f3 = this.size * 2.0F;
	int j = MathHelper.floor_double(this.x - f3 - 1.0D);
	int k = MathHelper.floor_double(this.x + f3 + 1.0D);
	int j1 = MathHelper.floor_double(this.y - f3 - 1.0D);
	int l = MathHelper.floor_double(this.y + f3 + 1.0D);
	int k1 = MathHelper.floor_double(this.z - f3 - 1.0D);
	int i1 = MathHelper.floor_double(this.z + f3 + 1.0D);
	List list = this.w.getEntitiesWithinAABBExcludingEntity(this.e, new AxisAlignedBB(j, j1, k1, k, l, i1));
	ForgeEventFactory.onExplosionDetonate(this.w, this, list, f3);
	Vec3 vec3 = new Vec3(this.x, this.y, this.z);
	for(int l1 = 0; l1 < list.size(); l1++) {
		Entity entity = (Entity) list.get(l1);
		if (!entity.func_180427_aV()) {
			double d12 = entity.getDistance(this.x, this.y, this.z) / f3;
			if (d12 <= 1.0D) {
				double d5 = entity.posX - this.x;
				double d7 = entity.posY + entity.getEyeHeight() - this.y;
				double d9 = entity.posZ - this.z;
				double d13 = MathHelper.sqrt_double(d5 * d5 + d7 * d7 + d9 * d9);
				if (d13 != 0.0D) {
					d5 /= d13;
					d7 /= d13;
					d9 /= d13;
					double d14 = this.w.getBlockDensity(vec3, entity.getEntityBoundingBox());
					double d10 = (1.0D - d12) * d14;
					entity.attackEntityFrom((strong ? Fusion.sourceStrongRadiation : Fusion.sourceRadiation), (int) ((d10 * d10 + d10) / 2.0D * 8.0D * f3 + 1.0D));
					double d11 = EnchantmentProtection.func_92092_a(entity, d10);
					entity.motionX += d5 * d11;
					entity.motionY += d7 * d11;
					entity.motionZ += d9 * d11;
					if ((entity instanceof EntityPlayer)) {
						this.map.put((EntityPlayer) entity, new Vec3(d5 * d10, d7 * d10, d9 * d10));
					}
				}
			}
		}
	}
}

public void doExplosionB(boolean b) {
	this.w.playSoundEffect(this.x, this.y, this.z, "random.explode", 4.0F, (1.0F + (this.w.rand.nextFloat() - this.w.rand.nextFloat()) * 0.2F) * 0.7F);
	if ((this.size >= 2.0F) && (this.s))
		this.w.spawnParticle(EnumParticleTypes.EXPLOSION_HUGE, this.x, this.y, this.z, 1.0D, 0.0D, 0.0D, new int[0]);
	else
		this.w.spawnParticle(EnumParticleTypes.EXPLOSION_LARGE, this.x, this.y, this.z, 1.0D, 0.0D, 0.0D, new int[0]);
	if (this.s) {
		Iterator<Object> iterator = this.blocks.iterator();
		while(iterator.hasNext()) {
			BlockPos blockpos = (BlockPos) iterator.next();
			Block block = this.w.getBlockState(blockpos).getBlock();
			if (b) {
				double d0 = blockpos.getX() + this.w.rand.nextFloat();
				double d1 = blockpos.getY() + this.w.rand.nextFloat();
				double d2 = blockpos.getZ() + this.w.rand.nextFloat();
				double d3 = d0 - this.x;
				double d4 = d1 - this.y;
				double d5 = d2 - this.z;
				double d6 = MathHelper.sqrt_double(d3 * d3 + d4 * d4 + d5 * d5);
				d3 /= d6;
				d4 /= d6;
				d5 /= d6;
				double d7 = 0.5D / (d6 / this.size + 0.1D);
				d7 *= (this.w.rand.nextFloat() * this.w.rand.nextFloat() + 0.3F);
				d3 *= d7;
				d4 *= d7;
				d5 *= d7;
				this.w.spawnParticle(EnumParticleTypes.EXPLOSION_NORMAL, (d0 + this.x * 1.0D) / 2.0D, (d1 + this.y * 1.0D) / 2.0D, (d2 + this.z * 1.0D) / 2.0D, d3, d4, d5, new int[0]);
				this.w.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, d0, d1, d2, d3, d4, d5, new int[0]);
			}
			if (block.getMaterial() != Material.air) {
				if (block.canDropFromExplosion(this))
					block.dropBlockAsItemWithChance(this.w, blockpos, this.w.getBlockState(blockpos), 1.0F / this.size, 0);
				block.onBlockExploded(this.w, blockpos, this);
			}
		}
	}
	if (this.f) {
		Iterator<Object> iterator = this.blocks.iterator();
		while(iterator.hasNext()) {
			BlockPos blockpos = (BlockPos) iterator.next();
			if ((this.w.getBlockState(blockpos).getBlock().getMaterial() == Material.air) && (this.w.getBlockState(blockpos.down()).getBlock().isFullBlock()) && (this.r.nextInt(3) == 0))
				this.w.setBlockState(blockpos, net.minecraft.init.Blocks.fire.getDefaultState());
		}
	}
}
}

And here is FusionBomb.class, which calls the first method to create the explosion:

package donkeycore.fusion.blocks;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.world.Explosion;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.fml.relauncher.Side;
import donkeycore.fusion.Fusion;
import donkeycore.fusion.IFusionObject;

public class FusionBomb extends Block implements IFusionObject {

public static final String name = "fusion_bomb";

public FusionBomb() {
	super(Material.tnt);
	setHarvestLevel(null, 0);
	setStepSound(Block.soundTypeMetal);
	setHardness(2F);
	setLightLevel(1F);
	setCreativeTab(Fusion.tabFusion);
	setUnlocalizedName(name);
}

@Override
public void onBlockDestroyedByExplosion(World w, BlockPos p, Explosion e) {
	explode(w, p);
}

@Override
public IBlockState onBlockPlaced(World w, BlockPos p, EnumFacing f, float hitx, float hity, float hitz, int meta, EntityLivingBase e) {
	if (w.isBlockIndirectlyGettingPowered(p) > 0) {
		explode(w, p);
		w.notifyNeighborsOfStateChange(p, this);
	}
	return super.onBlockPlaced(w, p, f, hitx, hity, hitz, meta, e);
}

@Override
public void onNeighborBlockChange(World w, BlockPos p, IBlockState s, Block b) {
	if (w.isBlockIndirectlyGettingPowered(p) > 0) {
		explode(w, p);
		w.notifyNeighborsOfStateChange(p, this);
	}
}

public static void explode(World w, BlockPos p) {
	if(!w.isRemote)
		Fusion.createFusionExplosion(w, p.getX(), p.getY(), p.getZ(), 6F, true, true, true);
}

@Override
public void preinit() {
	GameRegistry.registerBlock(this, name);
	GameRegistry.addShapedRecipe(new ItemStack(this), "RAR", "FTF", "RAR", 'F', Fusion.getItemFromId("fusion_ingot"), 'A', Fusion.getItemFromId("active_fusion_ingot"), 'T', Blocks.tnt, 'R', Items.redstone);
	GameRegistry.addShapedRecipe(new ItemStack(this), "RFR", "ATA", "RFR", 'F', Fusion.getItemFromId("fusion_ingot"), 'A', Fusion.getItemFromId("active_fusion_ingot"), 'T', Blocks.tnt, 'R', Items.redstone);
}

@Override
public void init() {
	if (Fusion.SIDE == Side.CLIENT)
		Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(GameRegistry.findItem(Fusion.MODID, name), 0, new ModelResourceLocation(Fusion.MODID + ":" + name, "inventory"));
}
}

And yes, it is shown that I checked !World.isRemote before creating the explosion. I'm stumped, thanks in advance.

 

Edit: Added [1.8] prefix

~DonkeyCore

Link to comment
Share on other sites

Hi

 

>And yes, it is shown that I checked !World.isRemote before creating the explosion. I'm stumped, thanks in advance.

ironic really :)    In this case the explosion needs to execute on both client and server. You can tell this if you put a breakpoint in the vanilla doExplosionB - it breaks twice, once on server thread, once on client thread.  Particle spawning does nothing on the server, which is why you don't see anything.

 

-TGG

 

Link to comment
Share on other sites

Hmmm that's curious

 

Try putting a breakpoint here

 

public void doExplosionB(boolean b) {

this.w.playSoundEffect(this.x, this.y, this.z, "random.explode", 4.0F, (1.0F + (this.w.rand.nextFloat() - this.w.rand.nextFloat()) * 0.2F) * 0.7F);

if ((this.size >= 2.0F) && (this.s))  // HERE

 

and seeing whether it calls triggered on both the client and the server threads.

 

-TGG

Link to comment
Share on other sites

That's okay. Your help was wonderful nonetheless.

 

In other words, I'm slightly closer to figuring out the problem. In this class:

package donkeycore.fusion.blocks;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.world.Explosion;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.fml.relauncher.Side;
import donkeycore.fusion.Fusion;
import donkeycore.fusion.IFusionObject;

public class FusionBomb extends Block implements IFusionObject {

public static final String name = "fusion_bomb";

public FusionBomb() {
	super(Material.tnt);
	setHarvestLevel(null, 0);
	setStepSound(Block.soundTypeMetal);
	setHardness(2F);
	setLightLevel(1F);
	setCreativeTab(Fusion.tabFusion);
	setUnlocalizedName(name);
}

@Override
public void onBlockDestroyedByExplosion(World w, BlockPos p, Explosion e) {
	explode(w, p);
}

@Override
public IBlockState onBlockPlaced(World w, BlockPos p, EnumFacing f, float hitx, float hity, float hitz, int meta, EntityLivingBase e) {
	Fusion.info(w.getClass().getSimpleName());
	if (w.isBlockIndirectlyGettingPowered(p) > 0) {
		Fusion.info("Passing: " + w.getClass().getSimpleName());
		explode(w, p);
		w.notifyNeighborsOfStateChange(p, this);
		return Blocks.air.getDefaultState();
	}
	return super.onBlockPlaced(w, p, f, hitx, hity, hitz, meta, e);
}

@Override
public void onNeighborBlockChange(World w, BlockPos p, IBlockState s, Block b) {
	Fusion.info(w.getClass().getSimpleName());
	if (w.isBlockIndirectlyGettingPowered(p) > 0) {
		Fusion.info("Passing: " + w.getClass().getSimpleName());
		explode(w, p);
		w.notifyNeighborsOfStateChange(p, this);
	}
}

public static void explode(World w, BlockPos p) {
	Fusion.createFusionExplosion(w, p.getX(), p.getY(), p.getZ(), 6F, true, true, true);
}

@Override
public void preinit() {
	GameRegistry.registerBlock(this, name);
	GameRegistry.addShapedRecipe(new ItemStack(this), "RAR", "FTF", "RAR", 'F', Fusion.getItemFromId("fusion_ingot"), 'A', Fusion.getItemFromId("active_fusion_ingot"), 'T', Blocks.tnt, 'R', Items.redstone);
	GameRegistry.addShapedRecipe(new ItemStack(this), "RFR", "ATA", "RFR", 'F', Fusion.getItemFromId("fusion_ingot"), 'A', Fusion.getItemFromId("active_fusion_ingot"), 'T', Blocks.tnt, 'R', Items.redstone);
}

@Override
public void init() {
	if (Fusion.SIDE == Side.CLIENT)
		Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(GameRegistry.findItem(Fusion.MODID, name), 0, new ModelResourceLocation(Fusion.MODID + ":" + name, "inventory"));
}
}

 

You can see I have a couple methods that call explode(). I have 2 of them set to tell me what world was being passed in. In onBlockPlaced, I noticed that it says:

[09:18:24] [Client thread/INFO] [FML]: [Fusion] WorldClient
[09:18:24] [Client thread/INFO] [FML]: [Fusion] Passing: WorldClient
[09:18:24] [server thread/INFO] [FML]: [Fusion] WorldServer
[09:18:24] [server thread/INFO] [FML]: [Fusion] Passing: WorldServer

 

If I place a redstone torch THEN my custom block, it works perfectly and the explosion particles are clearly visible! However, you can see onNeighborBlockChange which displays:

 

[09:18:59] [Client thread/INFO] [FML]: [Fusion] WorldClient
[09:18:59] [server thread/INFO] [FML]: [Fusion] WorldServer
[09:19:00] [server thread/INFO] [FML]: [Fusion] WorldServer
[09:19:00] [server thread/INFO] [FML]: [Fusion] Passing: WorldServer
[09:19:00] [server thread/INFO] [FML]: [Fusion] WorldServer
[09:19:00] [server thread/INFO] [FML]: [Fusion] Passing: WorldServer
[09:19:00] [server thread/INFO] [FML]: [Fusion] WorldServer
[09:19:00] [server thread/INFO] [FML]: [Fusion] WorldServer

 

Which clearly does not seem to work properly. Only WorldServer is getting passed in for some reason, but the calls that the method makes is nearly identical to that of onBlockPlaced... hmm.....

~DonkeyCore

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I create my mod pack,yesterday my mod pack is fine but i add one mod and error. I'm delete this mmod but minecraft is still stop on CONFIG_LOAD then I tried to delete config and restart it but again. If you can pleace help me. https://imgur.com/ngZBzuv
    • game crashes before even opening (log:https://mclo.gs/M8xvX7c)
    • I have created a custom entity that extends "TamableAnimal", but I am wanting to have it spawn in the ocean. I have it spawning right now, but it spawns way too frequently even with weight set to 1. I am guessing it is because it is rolling in the spawn pool of land animals since TameableAnimal extends Animal and is different than WaterAnimal, and since no land animals spawn in the ocean it just fills every inch up with my custom entity. I have followed basic tutorials for spawning entities with Forge, but I feel like I am missing something about how to change what spawn pool this custom entity ends up in. Is it possible to change that or do I need to refactor it to be based off of WaterAnimal to get those spawn? My biome modifier JSON file: { "type": "forge:add_spawns", "biomes": "#minecraft:is_ocean", "spawners": { "type": "darwinsmysticalmounts:water_wyvern", "weight": 20, "minCount": 1, "maxCount": 1 } } My client event: event.register(ModEntityTypes.WATER_WYVERN.get(), SpawnPlacements.Type.NO_RESTRICTIONS, Heightmap.Types.MOTION_BLOCKING_NO_LEAVES, WaterWyvernEntity::checkWaterWyvernSpawnRules, SpawnPlacementRegisterEvent.Operation.REPLACE); And the actual custom spawn rule that makes it spawn in the water: public static boolean checkWaterWyvernSpawnRules(EntityType<WaterWyvernEntity> pAnimal, LevelAccessor pLevel, MobSpawnType pSpawnType, BlockPos pPos, RandomSource pRandom) { return pPos.getY() > pLevel.getSeaLevel() - 16 && pLevel.getFluidState(pPos.below()).is(FluidTags.WATER); }  
    • Starting today, I am unable to load my modded minecraft world. Forge crash log initially said it was a specific mod called Doggy Talents, which I disabled. Then it blamed JEI, and when that was disabled it blamed another mod so I assume it's something more than a specific mod. Minecraft launcher log claims "Exit Code 1". Nothing had changed since last night when it was working fine Forge Log: https://pastebin.com/S1GiBGVJ Client Log: https://pastebin.com/aLwuGUNL  
    • I am using AMD, yes. I downloaded the website's drivers and am still having the issue. I also used the Cleanup Utility just in case. 
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.