Merge pull request #2483 from DangerousMilk/Meteorite-Tweaks

Meteor Improvements
This commit is contained in:
HbmMods 2025-10-23 11:55:37 +02:00 committed by GitHub
commit b3aa9ab637
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 204 additions and 93 deletions

View File

@ -1,5 +1,6 @@
package com.hbm.entity.projectile; package com.hbm.entity.projectile;
import com.hbm.blocks.ModBlocks;
import com.hbm.config.WorldConfig; import com.hbm.config.WorldConfig;
import com.hbm.explosion.ExplosionLarge; import com.hbm.explosion.ExplosionLarge;
import com.hbm.main.MainRegistry; import com.hbm.main.MainRegistry;
@ -7,24 +8,97 @@ 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.client.Minecraft;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
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;
import com.hbm.sound.AudioWrapper;
import java.util.ArrayList;
import java.util.List;
public class EntityMeteor extends Entity { public class EntityMeteor extends Entity {
public boolean safe = false; public boolean safe = false;
private AudioWrapper audioFly;
public EntityMeteor(World p_i1582_1_) { public EntityMeteor(World p_i1582_1_) {
super(p_i1582_1_); super(p_i1582_1_);
this.ignoreFrustumCheck = true; this.ignoreFrustumCheck = true;
this.isImmuneToFire = true; this.isImmuneToFire = true;
this.setSize(4F, 4F); this.setSize(4F, 4F);
if(worldObj.isRemote) this.audioFly = MainRegistry.proxy.getLoopedSound("hbm:entity.meteoriteFallingLoop", 0, 0, 0, 1F, 100F, 0.9F + this.rand.nextFloat() * 0.2F, 0);
}
public List<int[]> getBlocksInRadius(World world, int x, int y, int z, int radius) {
List<int[]> foundBlocks = new ArrayList<>();
int rSq = radius * radius;
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) {
foundBlocks.add(new int[]{x + dx, y + dy, z + dz});
}
}
}
}
return foundBlocks;
}
public void damageOrDestroyBlock(World world, int blockX, int blockY, int blockZ)
{
if(safe) return;
// Get current block info
Block block = world.getBlock(blockX, blockY, blockZ);
if (block == null) return;
float hardness = block.getBlockHardness(world, blockX, blockY, blockZ);
// Check if the block is weak and can be destroyed
if (block == Blocks.leaves || block == Blocks.log || (hardness >= 0 && hardness <= 0.3F)) {
// Destroy the block
world.setBlockToAir(blockX, blockY, blockZ);
}
else {
// Found solid block
if(hardness < 0 || hardness > 5F) return;
if(rand.nextInt(6) == 1){
// Turn blocks into damaged variants
if(block == Blocks.dirt) {
world.setBlock(blockX, blockY, blockZ, ModBlocks.dirt_dead);
}
else if(block == Blocks.sand) {
if(rand.nextInt(2) == 1) {
world.setBlock(blockX, blockY, blockZ, Blocks.sandstone);
}
else {
world.setBlock(blockX, blockY, blockZ, Blocks.glass);
}
}
else if(block == Blocks.stone) {
world.setBlock(blockX, blockY, blockZ, Blocks.cobblestone);
}
else if(block == Blocks.grass) {
world.setBlock(blockX, blockY, blockZ, ModBlocks.waste_earth);
}
}
}
}
public void clearMeteorPath(World world, int x, int y, int z) {
for (int[] blockPos : getBlocksInRadius(world, x, y, z, 5))
{
damageOrDestroyBlock(worldObj, blockPos[0], blockPos[1], blockPos[2]);
}
} }
@Override @Override
public void onUpdate() { public void onUpdate() {
if(!worldObj.isRemote && !WorldConfig.enableMeteorStrikes) { if(!worldObj.isRemote && !WorldConfig.enableMeteorStrikes) {
this.setDead(); this.setDead();
return; return;
@ -40,20 +114,56 @@ 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) {
clearMeteorPath(worldObj, (int)this.posX, (int)this.posY, (int)this.posZ);
if(this.onGround) {
worldObj.createExplosion(this, this.posX, this.posY, this.posZ, 5 + rand.nextFloat(), !safe);
worldObj.createExplosion(this, this.posX, this.posY, this.posZ, 5 + rand.nextFloat(), !safe); if(WorldConfig.enableMeteorTails) {
if(WorldConfig.enableMeteorTails) { ExplosionLarge.spawnRubble(worldObj, this.posX, this.posY, this.posZ, 25);
ExplosionLarge.spawnParticles(worldObj, posX, posY + 5, posZ, 75);
ExplosionLarge.spawnParticles(worldObj, posX + 5, posY, posZ, 75); 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 - 5, posY, posZ, 75);
ExplosionLarge.spawnParticles(worldObj, posX, posY, posZ - 5, 75); ExplosionLarge.spawnParticles(worldObj, posX, posY, posZ + 5, 75);
ExplosionLarge.spawnParticles(worldObj, posX, posY, posZ - 5, 75);
}
// Bury the meteor into the ground
int spawnPosX = (int) (Math.round(this.posX - 0.5D) + (safe ? 0 : (this.motionZ * 4)));
int spawnPosY = (int) Math.round(this.posY - (safe ? 0 : 4));
int spawnPosZ = (int) (Math.round(this.posZ - 0.5D) + (safe ? 0 : (this.motionZ * 4)));
(new Meteorite()).generate(worldObj, rand, spawnPosX, spawnPosY, spawnPosZ, safe, true, true);
clearMeteorPath(worldObj, spawnPosX, spawnPosY, spawnPosZ);
this.worldObj.playSoundEffect(this.posX, this.posY, this.posZ, "hbm:entity.oldExplosion", 10000.0F, 0.5F + this.rand.nextFloat() * 0.1F);
this.setDead();
}
}
// Sound
if(worldObj.isRemote){
if(this.isDead) {
if(this.audioFly != null) this.audioFly.stopSound();
} }
(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(this.audioFly.isPlaying()) {
this.worldObj.playSoundEffect(this.posX, this.posY, this.posZ, "hbm:entity.oldExplosion", 10000.0F, 0.5F + this.rand.nextFloat() * 0.1F); // Update sound
this.setDead(); this.audioFly.keepAlive();
this.audioFly.updateVolume(1F);
this.audioFly.updatePosition((int)this.posX, (int)this.posY, (int)this.posZ);
}
else
{
// Start playing the sound
EntityPlayer player = Minecraft.getMinecraft().thePlayer;
double distance = player.getDistanceSq(this.posX, this.posY, this.posZ);
if (distance < 110 * 110) {
this.audioFly.startSound();
}
}
} }
if(WorldConfig.enableMeteorTails && worldObj.isRemote) { if(WorldConfig.enableMeteorTails && worldObj.isRemote) {

View File

@ -328,8 +328,9 @@
"entity.siegeIdle": {"category": "hostile", "sounds": ["entity/siegeIdle1"]}, "entity.siegeIdle": {"category": "hostile", "sounds": ["entity/siegeIdle1"]},
"entity.siegeHurt": {"category": "hostile", "sounds": ["entity/siegeHurt1", "entity/siegeHurt2"]}, "entity.siegeHurt": {"category": "hostile", "sounds": ["entity/siegeHurt1", "entity/siegeHurt2"]},
"entity.siegeDeath": {"category": "hostile", "sounds": ["entity/siegeDeath1", "entity/siegeDeath2", "entity/siegeDeath3"]}, "entity.siegeDeath": {"category": "hostile", "sounds": ["entity/siegeDeath1", "entity/siegeDeath2", "entity/siegeDeath3"]},
"entity.meteoriteFallingLoop": {"category": "block", "sounds": [{"name": "entity/meteoriteFallingLoop", "stream": false}]},
"step.metal": {"category": "player", "sounds": [{"name": "footsteps/metal", "stream": false}]}, "step.metal": {"category": "player", "sounds": [{"name": "footsteps/metal", "stream": false}]},
"step.iron_jump": {"category": "player", "sounds": [{"name": "footsteps/iron_jump", "stream": false}]}, "step.iron_jump": {"category": "player", "sounds": [{"name": "footsteps/iron_jump", "stream": false}]},
"step.iron_land": {"category": "player", "sounds": [{"name": "footsteps/iron_land", "stream": false}]}, "step.iron_land": {"category": "player", "sounds": [{"name": "footsteps/iron_land", "stream": false}]},
"step.iron": {"category": "player", "sounds": ["footsteps/iron1", "footsteps/iron2", "footsteps/iron3", "footsteps/iron4"]}, "step.iron": {"category": "player", "sounds": ["footsteps/iron1", "footsteps/iron2", "footsteps/iron3", "footsteps/iron4"]},