forked from TAIGA/TAIGA
Fixing Explosions in TraitInstable
This commit is contained in:
@@ -1,68 +0,0 @@
|
||||
package com.sosnitzka.ztic_addon.util;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.Explosion;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
public class ZExplosion extends Explosion {
|
||||
|
||||
/**
|
||||
* whether or not the explosion sets fire to blocks around it
|
||||
*/
|
||||
private final boolean isFlaming;
|
||||
/**
|
||||
* whether or not this explosion spawns smoke particles
|
||||
*/
|
||||
private final boolean isSmoking;
|
||||
private final Random explosionRNG;
|
||||
private final World worldObj;
|
||||
private final double explosionX;
|
||||
private final double explosionY;
|
||||
private final double explosionZ;
|
||||
private final Entity exploder;
|
||||
private final float explosionSize;
|
||||
private final List<BlockPos> affectedBlockPositions;
|
||||
private final Map<EntityPlayer, Vec3d> playerKnockbackMap;
|
||||
private final Vec3d position;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public ZExplosion(World worldIn, Entity entityIn, double x, double y, double z, float size, List<BlockPos> 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<BlockPos> 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);
|
||||
|
||||
this.explosionRNG = new Random();
|
||||
this.affectedBlockPositions = Lists.<BlockPos>newArrayList();
|
||||
this.playerKnockbackMap = Maps.<EntityPlayer, Vec3d>newHashMap();
|
||||
this.worldObj = entityIn.getEntityWorld();
|
||||
this.exploder = entityIn;
|
||||
this.explosionSize = size;
|
||||
this.explosionX = x;
|
||||
this.explosionY = y;
|
||||
this.explosionZ = z;
|
||||
this.isFlaming = flaming;
|
||||
this.isSmoking = smoking;
|
||||
this.position = new Vec3d(explosionX, explosionY, explosionZ);
|
||||
}
|
||||
|
||||
}
|
@@ -1,8 +1,6 @@
|
||||
package com.sosnitzka.ztic_addon.util.traits;
|
||||
|
||||
import com.sosnitzka.ztic_addon.util.ZExplosion;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
@@ -11,6 +9,7 @@ import net.minecraft.util.text.TextFormatting;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import slimeknights.tconstruct.library.traits.AbstractTrait;
|
||||
import slimeknights.tconstruct.library.utils.ToolHelper;
|
||||
|
||||
/**
|
||||
* Created by Robert on 14.05.2016.
|
||||
@@ -26,29 +25,30 @@ public class TraitInstable extends AbstractTrait {
|
||||
@Override
|
||||
public void afterBlockBreak(ItemStack tool, World world, IBlockState state, BlockPos pos, EntityLivingBase player, boolean wasEffective) {
|
||||
if (MathHelper.getRandomIntegerInRange(random, 0, 100) > 2) {
|
||||
if (!world.isRemote)
|
||||
|
||||
newZExplosion(player, pos.getX(), pos.getY(), pos.getZ(), 2f, true, true);
|
||||
|
||||
if (!world.isRemote) {
|
||||
if (random.nextBoolean()) {
|
||||
Explode(player, pos.getX(), pos.getY(), pos.getZ());
|
||||
} else Explode(null, pos.getX(), pos.getY(), pos.getZ());
|
||||
}
|
||||
ToolHelper.damageTool(tool, 11 + random.nextInt(10), null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterHit(ItemStack tool, EntityLivingBase player, EntityLivingBase target, float damage, boolean wasCritical, boolean wasHit) {
|
||||
BlockPos pos = target.getPosition();
|
||||
if (MathHelper.getRandomIntegerInRange(random, 0, 100) < 2) {
|
||||
newZExplosion(target, pos.getX(), pos.getY(), pos.getZ(), 2f, true, true);
|
||||
if (MathHelper.getRandomIntegerInRange(random, 0, 100) > 2) {
|
||||
if (!player.getEntityWorld().isRemote) {
|
||||
if (random.nextBoolean()) {
|
||||
Explode(player, pos.getX(), pos.getY(), pos.getZ());
|
||||
} else Explode(target, pos.getX(), pos.getY(), pos.getZ());
|
||||
}
|
||||
ToolHelper.damageTool(tool, 3 + random.nextInt(18), null);
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
explosion.doExplosionA();
|
||||
explosion.doExplosionB(true);
|
||||
return explosion;
|
||||
private void Explode(EntityLivingBase e, double x, double y, double z) {
|
||||
e.getEntityWorld().newExplosion(e, x, y, z, 1.2f + random.nextFloat() * 5, random.nextBoolean(), true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user