Meteorites now break leaves and logs before landing. Made explosions fit the meteor size more.

This commit is contained in:
DangerousMilk 2025-10-13 22:36:56 +02:00
parent 72957ef167
commit bd8ed4920d
2 changed files with 62 additions and 25 deletions

View File

@ -7,7 +7,9 @@ import com.hbm.world.feature.Meteorite;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.init.Blocks;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World; import net.minecraft.world.World;
@ -22,6 +24,37 @@ public class EntityMeteor extends Entity {
this.setSize(4F, 4F); this.setSize(4F, 4F);
} }
public boolean destroyWeakBlocks(World world, int x, int y, int z, int radius) {
int rSq = radius * radius;
boolean foundSolidBlock = false;
for (int dx = -radius; dx <= radius; dx++) {
for (int dy = -radius; dy <= radius; dy++) {
for (int dz = -radius; dz <= radius; dz++) {
// Check if point (dx, dy, dz) lies inside the sphere
if (dx * dx + dy * dy + dz * dz <= rSq) {
int blockX = x + dx;
int blockY = y + dy;
int blockZ = z + dz;
Block block = world.getBlock(blockX, blockY, blockZ);
if (block == null) continue;
float hardness = block.getBlockHardness(world, blockX, blockY, blockZ);
if (block == Blocks.leaves || block == Blocks.log || hardness <= 0.3F || block == Blocks.water) {
world.setBlockToAir(blockX, blockY, blockZ);
} else {
foundSolidBlock = true;
}
}
}
}
}
return foundSolidBlock;
}
@Override @Override
public void onUpdate() { public void onUpdate() {
@ -40,20 +73,21 @@ public class EntityMeteor extends Entity {
this.moveEntity(motionX, motionY, motionZ); this.moveEntity(motionX, motionY, motionZ);
if(!this.worldObj.isRemote && this.onGround && this.posY < 260) { if(!this.worldObj.isRemote && this.posY < 260) {
if(destroyWeakBlocks(worldObj, (int)this.posX, (int)this.posY, (int)this.posZ, 6) && this.onGround) {
//worldObj.createExplosion(this, this.posX, this.posY, this.posZ, 5 + rand.nextFloat(), !safe);
if(WorldConfig.enableMeteorTails) {
ExplosionLarge.spawnParticles(worldObj, posX, posY + 5, posZ, 75);
ExplosionLarge.spawnParticles(worldObj, posX + 5, posY, posZ, 75);
ExplosionLarge.spawnParticles(worldObj, posX - 5, posY, posZ, 75);
ExplosionLarge.spawnParticles(worldObj, posX, posY, posZ + 5, 75);
ExplosionLarge.spawnParticles(worldObj, posX, posY, posZ - 5, 75);
}
worldObj.createExplosion(this, this.posX, this.posY, this.posZ, 5 + rand.nextFloat(), !safe); (new Meteorite()).generate(worldObj, rand, (int) Math.round(this.posX - 0.5D), (int) Math.round(this.posY - 0.5D), (int) Math.round(this.posZ - 0.5D), safe, true, true);
if(WorldConfig.enableMeteorTails) { this.worldObj.playSoundEffect(this.posX, this.posY, this.posZ, "hbm:entity.oldExplosion", 10000.0F, 0.5F + this.rand.nextFloat() * 0.1F);
ExplosionLarge.spawnParticles(worldObj, posX, posY + 5, posZ, 75); this.setDead();
ExplosionLarge.spawnParticles(worldObj, posX + 5, posY, posZ, 75);
ExplosionLarge.spawnParticles(worldObj, posX - 5, posY, posZ, 75);
ExplosionLarge.spawnParticles(worldObj, posX, posY, posZ + 5, 75);
ExplosionLarge.spawnParticles(worldObj, posX, posY, posZ - 5, 75);
} }
(new Meteorite()).generate(worldObj, rand, (int) Math.round(this.posX - 0.5D), (int) Math.round(this.posY - 0.5D), (int) Math.round(this.posZ - 0.5D), safe, true, true);
this.worldObj.playSoundEffect(this.posX, this.posY, this.posZ, "hbm:entity.oldExplosion", 10000.0F, 0.5F + this.rand.nextFloat() * 0.1F);
this.setDead();
} }
if(WorldConfig.enableMeteorTails && worldObj.isRemote) { if(WorldConfig.enableMeteorTails && worldObj.isRemote) {

View File

@ -135,11 +135,14 @@ public class Meteorite {
switch(rand.nextInt(3)) { switch(rand.nextInt(3)) {
case 0: case 0:
generateLarge(world, rand, x, y, z); generateLarge(world, rand, x, y, z);
world.createExplosion(null, x + 0.5, y + 1.5, z + 0.5, 9F, !safe);
break; break;
case 1: case 1:
world.createExplosion(null, x + 0.5, y + 1.5, z + 0.5, 6F, !safe);
generateMedium(world, rand, x, y, z); generateMedium(world, rand, x, y, z);
break; break;
case 2: case 2:
world.createExplosion(null, x + 0.5, y + 1.5, z + 0.5, 5F, !safe);
generateSmall(world, rand, x, y, z); generateSmall(world, rand, x, y, z);
break; break;
} }