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,12 +7,14 @@ import com.hbm.world.feature.Meteorite;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.init.Blocks;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
public class EntityMeteor extends Entity {
public boolean safe = false;
public EntityMeteor(World p_i1582_1_) {
@ -22,9 +24,40 @@ public class EntityMeteor extends Entity {
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
public void onUpdate() {
if(!worldObj.isRemote && !WorldConfig.enableMeteorStrikes) {
this.setDead();
return;
@ -37,23 +70,24 @@ public class EntityMeteor extends Entity {
this.motionY -= 0.03;
if(motionY < -2.5)
motionY = -2.5;
this.moveEntity(motionX, motionY, motionZ);
if(!this.worldObj.isRemote && this.onGround && this.posY < 260) {
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);
}
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);
}
(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();
(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) {

View File

@ -23,19 +23,19 @@ import net.minecraft.world.World;
@Spaghetti("why")
public class Meteorite {
public static boolean safeMode = false;
public void generate(World world, Random rand, int x, int y, int z, boolean safe, boolean allowSpecials, boolean damagingImpact) {
safeMode = safe;
if(replacables.isEmpty()) {
generateReplacables();
}
if(damagingImpact) {
List<Entity> list = (List<Entity>) world.getEntitiesWithinAABBExcludingEntity(null, AxisAlignedBB.getBoundingBox(x - 7.5, y - 7.5, z - 7.5, x + 7.5, y + 7.5, z + 7.5));
for(Entity e : list) {
e.attackEntityFrom(ModDamageSource.meteorite, 1000);
}
@ -135,11 +135,14 @@ public class Meteorite {
switch(rand.nextInt(3)) {
case 0:
generateLarge(world, rand, x, y, z);
world.createExplosion(null, x + 0.5, y + 1.5, z + 0.5, 9F, !safe);
break;
case 1:
world.createExplosion(null, x + 0.5, y + 1.5, z + 0.5, 6F, !safe);
generateMedium(world, rand, x, y, z);
break;
case 2:
world.createExplosion(null, x + 0.5, y + 1.5, z + 0.5, 5F, !safe);
generateSmall(world, rand, x, y, z);
break;
}
@ -693,21 +696,21 @@ public class Meteorite {
for(EnumMeteorType num : EnumMeteorType.values()) ores.add(DictFrame.fromOne(ModBlocks.ore_meteor, num));
return ores;
}
private void setBlock(World world, int x, int y, int z, Block b, int meta, int flag) {
Block target = world.getBlock(x, y, z);
if(safeMode) {
if(!target.isReplaceable(world, x, y, z) && !replacables.contains(target)) return;
if(!target.isReplaceable(world, x, y, z) && !replacables.contains(target)) return;
}
float hardness = target.getBlockHardness(world, x, y, z);
if(hardness != -1 && hardness < 10_000)
world.setBlock(x, y, z, b, meta, flag);
}
public static HashSet<Block> replacables = new HashSet();
public static void generateReplacables() {
replacables.add(ModBlocks.block_meteor);
replacables.add(ModBlocks.block_meteor_broken);