mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-01-25 10:32:49 +00:00
227 lines
6.7 KiB
Java
227 lines
6.7 KiB
Java
package com.hbm.entity.projectile;
|
|
|
|
import com.hbm.blocks.ModBlocks;
|
|
import com.hbm.config.WorldConfig;
|
|
import com.hbm.explosion.ExplosionLarge;
|
|
import com.hbm.main.MainRegistry;
|
|
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.client.Minecraft;
|
|
import net.minecraft.entity.Entity;
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
import net.minecraft.init.Blocks;
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
import net.minecraft.world.World;
|
|
import com.hbm.sound.AudioWrapper;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
public class EntityMeteor extends Entity {
|
|
|
|
public boolean safe = false;
|
|
private AudioWrapper audioFly;
|
|
|
|
public EntityMeteor(World p_i1582_1_) {
|
|
super(p_i1582_1_);
|
|
this.ignoreFrustumCheck = true;
|
|
this.isImmuneToFire = true;
|
|
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 boolean damageOrDestroyBlock(World world, int blockX, int blockY, int blockZ)
|
|
{
|
|
if(safe) return true;
|
|
|
|
// Get current block info
|
|
Block block = world.getBlock(blockX, blockY, blockZ);
|
|
if (block == null) return false;
|
|
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.3F) {
|
|
// Destroy the block
|
|
world.setBlockToAir(blockX, blockY, blockZ);
|
|
}
|
|
else {
|
|
// Found solid block
|
|
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);
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public boolean clearMeteorPath(World world, int x, int y, int z) {
|
|
boolean foundSolidBlock = false;
|
|
|
|
for (int[] blockPos : getBlocksInRadius(world, x, y, z, 5))
|
|
{
|
|
if(damageOrDestroyBlock(worldObj, blockPos[0], blockPos[1], blockPos[2])) {
|
|
foundSolidBlock = true;
|
|
}
|
|
}
|
|
|
|
return foundSolidBlock;
|
|
}
|
|
|
|
public void decorateCrater(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
|
|
public void onUpdate() {
|
|
if(!worldObj.isRemote && !WorldConfig.enableMeteorStrikes) {
|
|
this.setDead();
|
|
return;
|
|
}
|
|
|
|
this.prevPosX = this.posX;
|
|
this.prevPosY = this.posY;
|
|
this.prevPosZ = this.posZ;
|
|
|
|
this.motionY -= 0.03;
|
|
if(motionY < -2.5)
|
|
motionY = -2.5;
|
|
|
|
this.moveEntity(motionX, motionY, motionZ);
|
|
|
|
if(!this.worldObj.isRemote && this.posY < 260) {
|
|
if(clearMeteorPath(worldObj, (int)this.posX, (int)this.posY, (int)this.posZ) && this.onGround) {
|
|
worldObj.createExplosion(this, this.posX, this.posY, this.posZ, 5 + rand.nextFloat(), !safe);
|
|
|
|
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 - 5, posY, posZ, 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 * 5)));
|
|
int spawnPosY = (int) Math.round(this.posY - (safe ? 0 : 4));
|
|
int spawnPosZ = (int) (Math.round(this.posZ - 0.5D) + (safe ? 0 : (this.motionZ * 5)));
|
|
|
|
(new Meteorite()).generate(worldObj, rand, spawnPosX, spawnPosY, spawnPosZ, safe, true, true);
|
|
decorateCrater(worldObj, spawnPosX, spawnPosY, spawnPosZ);
|
|
|
|
// Sound
|
|
if(this.audioFly != null) this.audioFly.stopSound();
|
|
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.audioFly.isPlaying()) {
|
|
// Update sound
|
|
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) {
|
|
|
|
NBTTagCompound data = new NBTTagCompound();
|
|
data.setString("type", "exhaust");
|
|
data.setString("mode", "meteor");
|
|
data.setInteger("count", 10);
|
|
data.setDouble("width", 1);
|
|
data.setDouble("posX", posX - motionX);
|
|
data.setDouble("posY", posY - motionY);
|
|
data.setDouble("posZ", posZ - motionZ);
|
|
|
|
MainRegistry.proxy.effectNT(data);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
@SideOnly(Side.CLIENT)
|
|
public boolean isInRangeToRenderDist(double distance) {
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
@SideOnly(Side.CLIENT)
|
|
public int getBrightnessForRender(float p_70070_1_) {
|
|
return 15728880;
|
|
}
|
|
|
|
@Override
|
|
public float getBrightness(float p_70013_1_) {
|
|
return 1.0F;
|
|
}
|
|
|
|
@Override
|
|
protected void entityInit() { }
|
|
|
|
@Override
|
|
protected void readEntityFromNBT(NBTTagCompound nbt) {
|
|
this.safe = nbt.getBoolean("safe");
|
|
}
|
|
|
|
@Override
|
|
protected void writeEntityToNBT(NBTTagCompound nbt) {
|
|
nbt.setBoolean("safe", safe);
|
|
}
|
|
}
|