From 71928e0909e6e1449c176710afee684b937865bb Mon Sep 17 00:00:00 2001 From: Robert Sosnitzka Date: Sun, 12 Jun 2016 15:14:27 +0200 Subject: [PATCH] Custom Explosion seems to work... idk how! --- .../sosnitzka/ztic_addon/util/ZExplosion.java | 117 ++---------------- .../ztic_addon/util/traits/TraitInstable.java | 9 -- 2 files changed, 11 insertions(+), 115 deletions(-) diff --git a/src/main/java/com/sosnitzka/ztic_addon/util/ZExplosion.java b/src/main/java/com/sosnitzka/ztic_addon/util/ZExplosion.java index 07a3788..8241288 100644 --- a/src/main/java/com/sosnitzka/ztic_addon/util/ZExplosion.java +++ b/src/main/java/com/sosnitzka/ztic_addon/util/ZExplosion.java @@ -2,17 +2,9 @@ package com.sosnitzka.ztic_addon.util; import com.google.common.collect.Lists; import com.google.common.collect.Maps; -import com.google.common.collect.Sets; -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.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.util.DamageSource; -import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Vec3d; import net.minecraft.world.Explosion; import net.minecraft.world.World; @@ -22,7 +14,6 @@ import net.minecraftforge.fml.relauncher.SideOnly; import java.util.List; import java.util.Map; import java.util.Random; -import java.util.Set; public class ZExplosion extends Explosion { @@ -45,6 +36,17 @@ public class ZExplosion extends Explosion { private final Map playerKnockbackMap; private final Vec3d position; + @SideOnly(Side.CLIENT) + public ZExplosion(World worldIn, Entity entityIn, double x, double y, double z, float size, List affectedPositions) { + this(worldIn, entityIn, x, y, z, size, false, true, affectedPositions); + } + + @SideOnly(Side.CLIENT) + public ZExplosion(World worldIn, Entity entityIn, double x, double y, double z, float size, boolean flaming, boolean smoking, List affectedPositions) { + this(worldIn, entityIn, x, y, z, size, flaming, smoking); + this.affectedBlockPositions.addAll(affectedPositions); + } + @SideOnly(Side.CLIENT) public ZExplosion(World worldIn, Entity entityIn, double x, double y, double z, float size, boolean flaming, boolean smoking) { super(worldIn, entityIn, x, y, z, size, flaming, smoking); @@ -63,101 +65,4 @@ public class ZExplosion extends Explosion { this.position = new Vec3d(explosionX, explosionY, explosionZ); } - @Override - public void doExplosionA() { - Set set = Sets.newHashSet(); - int i = 16; - - for (int j = 0; j < 16; ++j) { - for (int k = 0; k < 16; ++k) { - for (int l = 0; l < 16; ++l) { - if (j == 0 || j == 15 || k == 0 || k == 15 || l == 0 || l == 15) { - double d0 = (double) ((float) j / 15.0F * 2.0F - 1.0F); - double d1 = (double) ((float) k / 15.0F * 2.0F - 1.0F); - double d2 = (double) ((float) l / 15.0F * 2.0F - 1.0F); - double d3 = Math.sqrt(d0 * d0 + d1 * d1 + d2 * d2); - d0 = d0 / d3; - d1 = d1 / d3; - d2 = d2 / d3; - float f = this.explosionSize * (0.7F + this.worldObj.rand.nextFloat() * 0.6F); - double d4 = this.explosionX; - double d6 = this.explosionY; - double d8 = this.explosionZ; - - for (float f1 = 0.3F; f > 0.0F; f -= 0.22500001F) { - BlockPos blockpos = new BlockPos(d4, d6, d8); - IBlockState iblockstate = this.worldObj.getBlockState(blockpos); - - if (iblockstate.getMaterial() != Material.AIR) { - float f2 = this.exploder != null ? this.exploder.getExplosionResistance(this, this.worldObj, blockpos, iblockstate) : iblockstate.getBlock().getExplosionResistance(worldObj, blockpos, (Entity) null, this); - f -= (f2 + 0.3F) * 0.3F; - } - - if (f > 0.0F && (this.exploder == null || this.exploder.verifyExplosion(this, this.worldObj, blockpos, iblockstate, f))) { - set.add(blockpos); - } - - d4 += d0 * 0.30000001192092896D; - d6 += d1 * 0.30000001192092896D; - d8 += d2 * 0.30000001192092896D; - } - } - } - } - } - - this.affectedBlockPositions.addAll(set); - float f3 = this.explosionSize * 2.0F; - int k1 = MathHelper.floor_double(this.explosionX - (double) f3 - 1.0D); - int l1 = MathHelper.floor_double(this.explosionX + (double) f3 + 1.0D); - int i2 = MathHelper.floor_double(this.explosionY - (double) f3 - 1.0D); - int i1 = MathHelper.floor_double(this.explosionY + (double) f3 + 1.0D); - int j2 = MathHelper.floor_double(this.explosionZ - (double) f3 - 1.0D); - int j1 = MathHelper.floor_double(this.explosionZ + (double) f3 + 1.0D); - List list = this.worldObj.getEntitiesWithinAABBExcludingEntity(this.exploder, new AxisAlignedBB((double) k1, (double) i2, (double) j2, (double) l1, (double) i1, (double) j1)); - net.minecraftforge.event.ForgeEventFactory.onExplosionDetonate(this.worldObj, this, list, f3); - Vec3d vec3d = new Vec3d(this.explosionX, this.explosionY, this.explosionZ); - - for (int k2 = 0; k2 < list.size(); ++k2) { - Entity entity = (Entity) list.get(k2); - - if (!entity.isImmuneToExplosions()) { - double d12 = entity.getDistance(this.explosionX, this.explosionY, this.explosionZ) / (double) f3; - - if (d12 <= 1.0D) { - double d5 = entity.posX - this.explosionX; - double d7 = entity.posY + (double) entity.getEyeHeight() - this.explosionY; - double d9 = entity.posZ - this.explosionZ; - double d13 = (double) MathHelper.sqrt_double(d5 * d5 + d7 * d7 + d9 * d9); - - if (d13 != 0.0D) { - d5 = d5 / d13; - d7 = d7 / d13; - d9 = d9 / d13; - double d14 = (double) this.worldObj.getBlockDensity(vec3d, entity.getEntityBoundingBox()); - double d10 = (1.0D - d12) * d14; - entity.attackEntityFrom(DamageSource.causeExplosionDamage(this), (float) ((int) ((d10 * d10 + d10) / 2.0D * 7.0D * (double) f3 + 1.0D))); - double d11 = 1.0D; - - if (entity instanceof EntityLivingBase) { - d11 = EnchantmentProtection.getBlastDamageReduction((EntityLivingBase) entity, d10); - } - - entity.motionX += d5 * d11; - entity.motionY += d7 * d11; - entity.motionZ += d9 * d11; - - if (entity instanceof EntityPlayer) { - EntityPlayer entityplayer = (EntityPlayer) entity; - - if (!entityplayer.isSpectator() && (!entityplayer.isCreative() || !entityplayer.capabilities.isFlying)) { - this.playerKnockbackMap.put(entityplayer, new Vec3d(d5 * d10, d7 * d10, d9 * d10)); - } - } - } - } - } - } - } - } \ No newline at end of file diff --git a/src/main/java/com/sosnitzka/ztic_addon/util/traits/TraitInstable.java b/src/main/java/com/sosnitzka/ztic_addon/util/traits/TraitInstable.java index 4b15dc3..5d4cd1c 100644 --- a/src/main/java/com/sosnitzka/ztic_addon/util/traits/TraitInstable.java +++ b/src/main/java/com/sosnitzka/ztic_addon/util/traits/TraitInstable.java @@ -41,15 +41,6 @@ public class TraitInstable extends AbstractTrait { } } - /* @SubscribeEvent - public void onInstableExplosionDamage(LivingHurtEvent e){ - if(e.getEntityLiving() instanceof EntityPlayer){ - EntityPlayer p = (EntityPlayer) e.getEntityLiving(); - p.addChatComponentMessage(new TextComponentString("E: " + e.getSource().getEntity() + " D: " + e.getSource().getDamageType() + " C: " + e.getSource().getSourceOfDamage())); - - } - } */ - private ZExplosion newZExplosion(Entity entityIn, double x, double y, double z, float strength, boolean isFlaming, boolean isSmoking) { ZExplosion explosion = new ZExplosion(entityIn.worldObj, entityIn, x, y, z, strength, isFlaming, isSmoking); if (net.minecraftforge.event.ForgeEventFactory.onExplosionStart(entityIn.worldObj, explosion)) return explosion;