diff --git a/src/main/java/api/hbm/block/IFuckingExplode.java b/src/main/java/api/hbm/block/IFuckingExplode.java new file mode 100644 index 000000000..95f128e20 --- /dev/null +++ b/src/main/java/api/hbm/block/IFuckingExplode.java @@ -0,0 +1,15 @@ +package api.hbm.block; + +import com.hbm.entity.item.EntityTNTPrimedBase; + +import net.minecraft.world.World; + +public interface IFuckingExplode { + + // Anything that can be detonated by another explosion should implement this and spawn an EntityTNTPrimedBase when hit by an explosion + // This prevents chained explosions causing a stack overflow + // Note that the block can still safely immediately explode, as long as the source isn't another explosion + + public void explodeEntity(World world, double x, double y, double z, EntityTNTPrimedBase entity); + +} diff --git a/src/main/java/com/hbm/blocks/ModBlocks.java b/src/main/java/com/hbm/blocks/ModBlocks.java index da8088dd5..d44a23b03 100644 --- a/src/main/java/com/hbm/blocks/ModBlocks.java +++ b/src/main/java/com/hbm/blocks/ModBlocks.java @@ -1723,12 +1723,12 @@ public class ModBlocks { det_charge = new ExplosiveCharge(Material.iron).setBlockName("det_charge").setCreativeTab(MainRegistry.nukeTab).setHardness(0.1F).setResistance(0.0F).setBlockTextureName(RefStrings.MODID + ":det_charge"); det_nuke = new ExplosiveCharge(Material.iron).setBlockName("det_nuke").setCreativeTab(MainRegistry.nukeTab).setHardness(0.1F).setResistance(0.0F).setBlockTextureName(RefStrings.MODID + ":det_nuke"); det_miner = new DetMiner(Material.iron, RefStrings.MODID + ":det_miner_top").setBlockName("det_miner").setCreativeTab(MainRegistry.nukeTab).setHardness(0.1F).setResistance(0.0F).setBlockTextureName(RefStrings.MODID + ":det_miner_side"); - red_barrel = new RedBarrel(Material.iron).setBlockName("red_barrel").setCreativeTab(MainRegistry.nukeTab).setHardness(0.5F).setResistance(2.5F).setBlockTextureName(RefStrings.MODID + ":barrel_red"); - pink_barrel = new RedBarrel(Material.iron).setBlockName("pink_barrel").setCreativeTab(MainRegistry.nukeTab).setHardness(0.5F).setResistance(2.5F).setBlockTextureName(RefStrings.MODID + ":barrel_pink"); + red_barrel = new RedBarrel(Material.iron, true).setBlockName("red_barrel").setCreativeTab(MainRegistry.nukeTab).setHardness(0.5F).setResistance(2.5F).setBlockTextureName(RefStrings.MODID + ":barrel_red"); + pink_barrel = new RedBarrel(Material.iron, true).setBlockName("pink_barrel").setCreativeTab(MainRegistry.nukeTab).setHardness(0.5F).setResistance(2.5F).setBlockTextureName(RefStrings.MODID + ":barrel_pink"); yellow_barrel = new YellowBarrel(Material.iron).setBlockName("yellow_barrel").setCreativeTab(MainRegistry.nukeTab).setHardness(0.5F).setResistance(2.5F).setBlockTextureName(RefStrings.MODID + ":barrel_yellow"); vitrified_barrel = new YellowBarrel(Material.iron).setBlockName("vitrified_barrel").setCreativeTab(MainRegistry.nukeTab).setHardness(0.5F).setResistance(2.5F).setBlockTextureName(RefStrings.MODID + ":barrel_vitrified"); - lox_barrel = new RedBarrel(Material.iron).setBlockName("lox_barrel").setCreativeTab(MainRegistry.nukeTab).setHardness(0.5F).setResistance(2.5F).setBlockTextureName(RefStrings.MODID + ":barrel_lox"); - taint_barrel = new RedBarrel(Material.iron).setBlockName("taint_barrel").setCreativeTab(MainRegistry.nukeTab).setHardness(0.5F).setResistance(2.5F).setBlockTextureName(RefStrings.MODID + ":barrel_taint"); + lox_barrel = new RedBarrel(Material.iron, false).setBlockName("lox_barrel").setCreativeTab(MainRegistry.nukeTab).setHardness(0.5F).setResistance(2.5F).setBlockTextureName(RefStrings.MODID + ":barrel_lox"); + taint_barrel = new RedBarrel(Material.iron, false).setBlockName("taint_barrel").setCreativeTab(MainRegistry.nukeTab).setHardness(0.5F).setResistance(2.5F).setBlockTextureName(RefStrings.MODID + ":barrel_taint"); crashed_balefire = new BlockCrashedBomb(Material.iron).setBlockName("crashed_bomb").setCreativeTab(MainRegistry.nukeTab).setBlockUnbreakable().setResistance(6000.0F).setBlockTextureName(RefStrings.MODID + ":crashed_balefire"); fireworks = new BlockFireworks(Material.iron).setBlockName("fireworks").setCreativeTab(MainRegistry.nukeTab).setResistance(5.0F); charge_dynamite = new BlockChargeDynamite().setBlockName("charge_dynamite").setCreativeTab(MainRegistry.nukeTab).setResistance(1.0F); diff --git a/src/main/java/com/hbm/blocks/bomb/BlockChargeBase.java b/src/main/java/com/hbm/blocks/bomb/BlockChargeBase.java index 2002773fe..6419fe459 100644 --- a/src/main/java/com/hbm/blocks/bomb/BlockChargeBase.java +++ b/src/main/java/com/hbm/blocks/bomb/BlockChargeBase.java @@ -12,10 +12,13 @@ import java.util.Random; import com.hbm.blocks.BlockContainerBase; import com.hbm.blocks.ITooltipProvider; +import com.hbm.entity.item.EntityTNTPrimedBase; import com.hbm.interfaces.IBomb; import com.hbm.tileentity.bomb.TileEntityCharge; +import api.hbm.block.IFuckingExplode; import api.hbm.block.IToolable; +import codechicken.lib.math.MathHelper; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.entity.player.EntityPlayer; @@ -29,7 +32,7 @@ import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; -public abstract class BlockChargeBase extends BlockContainerBase implements IBomb, IToolable, ITooltipProvider { +public abstract class BlockChargeBase extends BlockContainerBase implements IBomb, IToolable, ITooltipProvider, IFuckingExplode { public static boolean safe = false; @@ -134,8 +137,18 @@ public abstract class BlockChargeBase extends BlockContainerBase implements IBom } @Override - public void onBlockDestroyedByExplosion(World world, int x, int y, int z, Explosion p_149723_5_) { - this.explode(world, x, y, z); + public void onBlockDestroyedByExplosion(World world, int x, int y, int z, Explosion explosion) { + if(!world.isRemote) { + EntityTNTPrimedBase tntPrimed = new EntityTNTPrimedBase(world, x + 0.5D, y + 0.5D, z + 0.5D, explosion != null ? explosion.getExplosivePlacedBy() : null, this); + tntPrimed.fuse = 0; + tntPrimed.detonateOnCollision = false; + world.spawnEntityInWorld(tntPrimed); + } + } + + @Override + public void explodeEntity(World world, double x, double y, double z, EntityTNTPrimedBase entity) { + explode(world, MathHelper.floor_double(x), MathHelper.floor_double(y), MathHelper.floor_double(z)); } @Override diff --git a/src/main/java/com/hbm/blocks/bomb/BlockDetonatable.java b/src/main/java/com/hbm/blocks/bomb/BlockDetonatable.java new file mode 100644 index 000000000..ceae92120 --- /dev/null +++ b/src/main/java/com/hbm/blocks/bomb/BlockDetonatable.java @@ -0,0 +1,55 @@ +package com.hbm.blocks.bomb; + +import com.hbm.blocks.generic.BlockFlammable; +import com.hbm.entity.item.EntityTNTPrimedBase; + +import api.hbm.block.IFuckingExplode; +import net.minecraft.block.Block; +import net.minecraft.block.material.Material; +import net.minecraft.world.Explosion; +import net.minecraft.world.World; + +public abstract class BlockDetonatable extends BlockFlammable implements IFuckingExplode { + + protected int popFuse; // A shorter fuse for when this explosive is dinked by another + protected boolean detonateOnCollision; + protected boolean detonateOnShot; + + public BlockDetonatable(Material mat, int en, int flam, int popFuse, boolean detonateOnCollision, boolean detonateOnShot) { + super(mat, en, flam); + this.popFuse = popFuse; + this.detonateOnCollision = detonateOnCollision; + this.detonateOnShot = detonateOnShot; + } + + @Override + public void onBlockDestroyedByExplosion(World world, int x, int y, int z, Explosion explosion) { + if(!world.isRemote) { + EntityTNTPrimedBase tntPrimed = new EntityTNTPrimedBase(world, x + 0.5D, y + 0.5D, z + 0.5D, explosion != null ? explosion.getExplosivePlacedBy() : null, this); + tntPrimed.fuse = popFuse <= 0 ? 0 : world.rand.nextInt(popFuse) + popFuse / 2; + tntPrimed.detonateOnCollision = detonateOnCollision; + world.spawnEntityInWorld(tntPrimed); + } + } + + @Override + public boolean canDropFromExplosion(Explosion explosion) { + return false; + } + + @Override + public void onNeighborBlockChange(World world, int x, int y, int z, Block block) { + if(!world.isRemote && shouldIgnite(world, x, y, z)) { + world.setBlockToAir(x, y, z); + onBlockDestroyedByExplosion(world, x, y, z, null); + } + } + + public void onShot(World world, int x, int y, int z) { + if (!detonateOnShot) return; + + world.setBlockToAir(x, y, z); + explodeEntity(world, x, y, z, null); // insta-explod + } + +} diff --git a/src/main/java/com/hbm/blocks/bomb/BlockPlasticExplosive.java b/src/main/java/com/hbm/blocks/bomb/BlockPlasticExplosive.java index b07b65821..b67d4d595 100644 --- a/src/main/java/com/hbm/blocks/bomb/BlockPlasticExplosive.java +++ b/src/main/java/com/hbm/blocks/bomb/BlockPlasticExplosive.java @@ -1,5 +1,6 @@ package com.hbm.blocks.bomb; +import com.hbm.entity.item.EntityTNTPrimedBase; import com.hbm.explosion.ExplosionLarge; import com.hbm.explosion.ExplosionNT; import com.hbm.interfaces.IBomb; @@ -13,17 +14,16 @@ import net.minecraft.entity.EntityLivingBase; import net.minecraft.item.ItemStack; import net.minecraft.util.IIcon; import net.minecraft.util.MathHelper; -import net.minecraft.world.Explosion; import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; -public class BlockPlasticExplosive extends Block implements IBomb { +public class BlockPlasticExplosive extends BlockDetonatable implements IBomb { @SideOnly(Side.CLIENT) private IIcon topIcon; public BlockPlasticExplosive(Material mat) { - super(mat); + super(mat, 0, 0, 0, false, false); } @SideOnly(Side.CLIENT) @@ -68,12 +68,7 @@ public class BlockPlasticExplosive extends Block implements IBomb { } @Override - public void onBlockDestroyedByExplosion(World world, int x, int y, int z, Explosion explosion) { - this.explode(world, x, y, z); - } - - @Override - public void onNeighborBlockChange(World world, int x, int y, int z, Block p_149695_5_) { + public void onNeighborBlockChange(World world, int x, int y, int z, Block block) { if(world.isBlockIndirectlyGettingPowered(x, y, z)) { this.explode(world, x, y, z); } @@ -89,4 +84,9 @@ public class BlockPlasticExplosive extends Block implements IBomb { return BombReturnCode.DETONATED; } + + @Override + public void explodeEntity(World world, double x, double y, double z, EntityTNTPrimedBase entity) { + explode(world, MathHelper.floor_double(x), MathHelper.floor_double(y), MathHelper.floor_double(z)); + } } diff --git a/src/main/java/com/hbm/blocks/bomb/BlockTNTBase.java b/src/main/java/com/hbm/blocks/bomb/BlockTNTBase.java index 680ea9030..bcc3543b4 100644 --- a/src/main/java/com/hbm/blocks/bomb/BlockTNTBase.java +++ b/src/main/java/com/hbm/blocks/bomb/BlockTNTBase.java @@ -2,7 +2,6 @@ package com.hbm.blocks.bomb; import java.util.Random; -import com.hbm.blocks.generic.BlockFlammable; import com.hbm.entity.item.EntityTNTPrimedBase; import com.hbm.util.ChatBuilder; @@ -16,21 +15,18 @@ import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.projectile.EntityArrow; -import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.IIcon; -import net.minecraft.world.Explosion; import net.minecraft.world.World; -import net.minecraftforge.common.util.ForgeDirection; -public abstract class BlockTNTBase extends BlockFlammable implements IToolable { +public abstract class BlockTNTBase extends BlockDetonatable implements IToolable { @SideOnly(Side.CLIENT) private IIcon topIcon; @SideOnly(Side.CLIENT) private IIcon bottomIcon; public BlockTNTBase() { - super(Material.tnt, 15, 100); + super(Material.tnt, 15, 100, 20, false, false); } @Override @@ -62,13 +58,9 @@ public abstract class BlockTNTBase extends BlockFlammable implements IToolable { } public void checkAndIgnite(World world, int x, int y, int z) { - - for(ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) { - if(world.getBlock(x + dir.offsetX, y + dir.offsetY, z + dir.offsetZ) == Blocks.fire) { - this.onBlockDestroyedByPlayer(world, x, y, z, 1); - world.setBlockToAir(x, y, z); - return; - } + if (shouldIgnite(world, x, y, z)) { + this.onBlockDestroyedByPlayer(world, x, y, z, 1); + world.setBlockToAir(x, y, z); } } @@ -77,15 +69,6 @@ public abstract class BlockTNTBase extends BlockFlammable implements IToolable { return 1; } - @Override - public void onBlockDestroyedByExplosion(World world, int x, int y, int z, Explosion explosion) { - if(!world.isRemote) { - EntityTNTPrimedBase entitytntprimed = new EntityTNTPrimedBase(world, x + 0.5D, y + 0.5D, z + 0.5D, explosion.getExplosivePlacedBy(), this); - entitytntprimed.fuse = world.rand.nextInt(entitytntprimed.fuse / 4) + entitytntprimed.fuse / 8; - world.spawnEntityInWorld(entitytntprimed); - } - } - @Override public void onBlockDestroyedByPlayer(World world, int x, int y, int z, int meta) { this.prime(world, x, y, z, meta, (EntityLivingBase) null); @@ -125,19 +108,12 @@ public abstract class BlockTNTBase extends BlockFlammable implements IToolable { } } - @Override - public boolean canDropFromExplosion(Explosion explosion) { - return false; - } - - public abstract void explodeEntity(World world, double x, double y, double z, EntityTNTPrimedBase entity); - @Override @SideOnly(Side.CLIENT) - public void registerBlockIcons(IIconRegister p_149651_1_) { - this.blockIcon = p_149651_1_.registerIcon(this.getTextureName() + "_side"); - this.topIcon = p_149651_1_.registerIcon(this.getTextureName() + "_top"); - this.bottomIcon = p_149651_1_.registerIcon(this.getTextureName() + "_bottom"); + public void registerBlockIcons(IIconRegister iconRegister) { + this.blockIcon = iconRegister.registerIcon(this.getTextureName() + "_side"); + this.topIcon = iconRegister.registerIcon(this.getTextureName() + "_top"); + this.bottomIcon = iconRegister.registerIcon(this.getTextureName() + "_bottom"); } @Override diff --git a/src/main/java/com/hbm/blocks/bomb/DetCord.java b/src/main/java/com/hbm/blocks/bomb/DetCord.java index 4c0017c5b..326a0c801 100644 --- a/src/main/java/com/hbm/blocks/bomb/DetCord.java +++ b/src/main/java/com/hbm/blocks/bomb/DetCord.java @@ -1,16 +1,18 @@ package com.hbm.blocks.bomb; +import com.hbm.entity.item.EntityTNTPrimedBase; + +import codechicken.lib.math.MathHelper; import cpw.mods.fml.client.registry.RenderingRegistry; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.init.Blocks; -import net.minecraft.world.Explosion; import net.minecraft.world.World; -public class DetCord extends Block implements IDetConnectible { +public class DetCord extends BlockDetonatable implements IDetConnectible { - public DetCord(Material p_i45394_1_) { - super(p_i45394_1_); + public DetCord(Material material) { + super(material, 0, 0, 0, false, false); } public static int renderID = RenderingRegistry.getNextAvailableRenderId(); @@ -30,16 +32,6 @@ public class DetCord extends Block implements IDetConnectible { return false; } - @Override - public void onBlockDestroyedByExplosion(World world, int x, int y, int z, Explosion p_149723_5_) { - this.explode(world, x, y, z); - } - - @Override - public boolean canDropFromExplosion(Explosion explosion) { - return false; - } - @Override public void onNeighborBlockChange(World world, int x, int y, int z, Block p_149695_5_) { if(world.isBlockIndirectlyGettingPowered(x, y, z)) { @@ -48,10 +40,14 @@ public class DetCord extends Block implements IDetConnectible { } public void explode(World world, int x, int y, int z) { - if(!world.isRemote) { world.setBlock(x, y, z, Blocks.air); world.createExplosion(null, x + 0.5, y + 0.5, z + 0.5, 1.5F, true); } } + + @Override + public void explodeEntity(World world, double x, double y, double z, EntityTNTPrimedBase entity) { + explode(world, MathHelper.floor_double(x), MathHelper.floor_double(y), MathHelper.floor_double(z)); + } } diff --git a/src/main/java/com/hbm/blocks/bomb/DetMiner.java b/src/main/java/com/hbm/blocks/bomb/DetMiner.java index baa130baa..f8b0ffcaa 100644 --- a/src/main/java/com/hbm/blocks/bomb/DetMiner.java +++ b/src/main/java/com/hbm/blocks/bomb/DetMiner.java @@ -3,18 +3,21 @@ package com.hbm.blocks.bomb; import java.util.Random; import com.hbm.blocks.machine.BlockPillar; +import com.hbm.entity.item.EntityTNTPrimedBase; import com.hbm.explosion.ExplosionLarge; import com.hbm.explosion.ExplosionNT; import com.hbm.explosion.ExplosionNT.ExAttrib; import com.hbm.interfaces.IBomb; +import api.hbm.block.IFuckingExplode; +import codechicken.lib.math.MathHelper; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.item.Item; import net.minecraft.world.Explosion; import net.minecraft.world.World; -public class DetMiner extends BlockPillar implements IBomb { +public class DetMiner extends BlockPillar implements IBomb, IFuckingExplode { public DetMiner(Material mat, String top) { super(mat, top); @@ -44,8 +47,13 @@ public class DetMiner extends BlockPillar implements IBomb { } @Override - public void onBlockDestroyedByExplosion(World world, int x, int y, int z, Explosion p_149723_5_) { - this.explode(world, x, y, z); + public void onBlockDestroyedByExplosion(World world, int x, int y, int z, Explosion explosion) { + if(!world.isRemote) { + EntityTNTPrimedBase tntPrimed = new EntityTNTPrimedBase(world, x + 0.5D, y + 0.5D, z + 0.5D, explosion != null ? explosion.getExplosivePlacedBy() : null, this); + tntPrimed.fuse = 0; + tntPrimed.detonateOnCollision = false; + world.spawnEntityInWorld(tntPrimed); + } } @Override @@ -54,4 +62,9 @@ public class DetMiner extends BlockPillar implements IBomb { this.explode(world, x, y, z); } } + + @Override + public void explodeEntity(World world, double x, double y, double z, EntityTNTPrimedBase entity) { + explode(world, MathHelper.floor_double(x), MathHelper.floor_double(y), MathHelper.floor_double(z)); + } } diff --git a/src/main/java/com/hbm/blocks/bomb/ExplosiveCharge.java b/src/main/java/com/hbm/blocks/bomb/ExplosiveCharge.java index 262f4be36..f1b92756b 100644 --- a/src/main/java/com/hbm/blocks/bomb/ExplosiveCharge.java +++ b/src/main/java/com/hbm/blocks/bomb/ExplosiveCharge.java @@ -3,12 +3,14 @@ package com.hbm.blocks.bomb; import com.hbm.blocks.ModBlocks; import com.hbm.config.BombConfig; import com.hbm.entity.effect.EntityNukeTorex; +import com.hbm.entity.item.EntityTNTPrimedBase; import com.hbm.entity.logic.EntityNukeExplosionMK5; import com.hbm.explosion.ExplosionLarge; import com.hbm.explosion.ExplosionNT; import com.hbm.interfaces.IBomb; import com.hbm.lib.RefStrings; +import codechicken.lib.math.MathHelper; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.block.Block; @@ -16,16 +18,15 @@ import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.init.Blocks; import net.minecraft.util.IIcon; -import net.minecraft.world.Explosion; import net.minecraft.world.World; -public class ExplosiveCharge extends Block implements IBomb, IDetConnectible { +public class ExplosiveCharge extends BlockDetonatable implements IBomb, IDetConnectible { @SideOnly(Side.CLIENT) private IIcon iconTop; - public ExplosiveCharge(Material p_i45394_1_) { - super(p_i45394_1_); + public ExplosiveCharge(Material material) { + super(material, 0, 0, 0, false, false); } @Override @@ -47,16 +48,6 @@ public class ExplosiveCharge extends Block implements IBomb, IDetConnectible { return side == 1 ? this.iconTop : (side == 0 ? this.iconTop : this.blockIcon); } - @Override - public void onBlockDestroyedByExplosion(World world, int x, int y, int z, Explosion p_149723_5_) { - this.explode(world, x, y, z); - } - - @Override - public boolean canDropFromExplosion(Explosion explosion) { - return false; - } - @Override public void onNeighborBlockChange(World world, int x, int y, int z, Block p_149695_5_) { if(world.isBlockIndirectlyGettingPowered(x, y, z)) { @@ -85,4 +76,9 @@ public class ExplosiveCharge extends Block implements IBomb, IDetConnectible { return BombReturnCode.DETONATED; } + @Override + public void explodeEntity(World world, double x, double y, double z, EntityTNTPrimedBase entity) { + explode(world, MathHelper.floor_double(x), MathHelper.floor_double(y), MathHelper.floor_double(z)); + } + } diff --git a/src/main/java/com/hbm/blocks/generic/BlockFlammable.java b/src/main/java/com/hbm/blocks/generic/BlockFlammable.java index 9a43b0bf1..023476012 100644 --- a/src/main/java/com/hbm/blocks/generic/BlockFlammable.java +++ b/src/main/java/com/hbm/blocks/generic/BlockFlammable.java @@ -3,7 +3,9 @@ package com.hbm.blocks.generic; import com.hbm.blocks.BlockBase; import net.minecraft.block.material.Material; +import net.minecraft.init.Blocks; import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; public class BlockFlammable extends BlockBase { @@ -26,4 +28,17 @@ public class BlockFlammable extends BlockBase { public int getFireSpreadSpeed(IBlockAccess world, int x, int y, int z, ForgeDirection face) { return encouragement; } + + public boolean shouldIgnite(World world, int x, int y, int z) { + if(flammability == 0) return false; + + for(ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) { + if(world.getBlock(x + dir.offsetX, y + dir.offsetY, z + dir.offsetZ) == Blocks.fire) { + return true; + } + } + + return false; + } + } diff --git a/src/main/java/com/hbm/blocks/generic/RedBarrel.java b/src/main/java/com/hbm/blocks/generic/RedBarrel.java index 6e330979e..857cb7b55 100644 --- a/src/main/java/com/hbm/blocks/generic/RedBarrel.java +++ b/src/main/java/com/hbm/blocks/generic/RedBarrel.java @@ -3,65 +3,23 @@ package com.hbm.blocks.generic; import java.util.Random; import com.hbm.blocks.ModBlocks; +import com.hbm.blocks.bomb.BlockDetonatable; import com.hbm.blocks.bomb.BlockTaint; import com.hbm.blocks.machine.BlockFluidBarrel; +import com.hbm.entity.item.EntityTNTPrimedBase; import com.hbm.explosion.ExplosionThermo; -import net.minecraft.block.Block; + import net.minecraft.block.material.Material; -import net.minecraft.entity.Entity; -import net.minecraft.init.Blocks; import net.minecraft.util.AxisAlignedBB; -import net.minecraft.world.Explosion; +import net.minecraft.util.MathHelper; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; -public class RedBarrel extends Block { +public class RedBarrel extends BlockDetonatable { - public RedBarrel(Material p_i45394_1_) { - super(p_i45394_1_); - } - - @Override - public void onBlockDestroyedByExplosion(World p_149723_1_, int p_149723_2_, int p_149723_3_, int p_149723_4_, Explosion p_149723_5_) { - if(!p_149723_1_.isRemote) { - explode(p_149723_1_, p_149723_2_, p_149723_3_, p_149723_4_); - } - } - - @Override - public void onNeighborBlockChange(World p_149695_1_, int x, int y, int z, Block p_149695_5_) { - if((this == ModBlocks.red_barrel || this == ModBlocks.pink_barrel) && p_149695_1_.getBlock(x + 1, y, z) == Blocks.fire || p_149695_1_.getBlock(x - 1, y, z) == Blocks.fire || p_149695_1_.getBlock(x, y + 1, z) == Blocks.fire || p_149695_1_.getBlock(x, y - 1, z) == Blocks.fire || p_149695_1_.getBlock(x, y, z + 1) == Blocks.fire || p_149695_1_.getBlock(x, y, z - 1) == Blocks.fire) { - if(!p_149695_1_.isRemote) - explode(p_149695_1_, x, y, z); - } - } - - public void explode(World p_149695_1_, int x, int y, int z) { - - if(this == ModBlocks.red_barrel || this == ModBlocks.pink_barrel) - p_149695_1_.newExplosion((Entity) null, x + 0.5F, y + 0.5F, z + 0.5F, 2.5F, true, true); - - if(this == ModBlocks.lox_barrel) { - - p_149695_1_.newExplosion(null, x + 0.5F, y + 0.5F, z + 0.5F, 1F, false, false); - - ExplosionThermo.freeze(p_149695_1_, x, y, z, 7); - } - - if(this == ModBlocks.taint_barrel) { - - p_149695_1_.newExplosion(null, x + 0.5F, y + 0.5F, z + 0.5F, 1F, false, false); - - Random rand = p_149695_1_.rand; - for(int i = 0; i < 100; i++) { - int a = rand.nextInt(9) - 4 + x; - int b = rand.nextInt(9) - 4 + y; - int c = rand.nextInt(9) - 4 + z; - if(p_149695_1_.getBlock(a, b, c).isReplaceable(p_149695_1_, a, b, c) && BlockTaint.hasPosNeightbour(p_149695_1_, a, b, c)) { - p_149695_1_.setBlock(a, b, c, ModBlocks.taint, rand.nextInt(3) + 4, 2); - } - } - } + // Flammable barrels also explode when shot + public RedBarrel(Material material, boolean flammable) { + super(material, flammable ? 2 : 0, flammable ? 15 : 0, 100, true, flammable); } @Override @@ -80,7 +38,7 @@ public class RedBarrel extends Block { } @Override - public void setBlockBoundsBasedOnState(IBlockAccess p_149719_1_, int p_149719_2_, int p_149719_3_, int p_149719_4_) { + public void setBlockBoundsBasedOnState(IBlockAccess access, int x, int y, int z) { float f = 0.0625F; this.setBlockBounds(2 * f, 0.0F, 2 * f, 14 * f, 1.0F, 14 * f); } @@ -93,8 +51,28 @@ public class RedBarrel extends Block { } @Override - public boolean canDropFromExplosion(Explosion p_149659_1_) { - return false; + public void explodeEntity(World world, double x, double y, double z, EntityTNTPrimedBase entity) { + int ix = MathHelper.floor_double(x), iy = MathHelper.floor_double(y), iz = MathHelper.floor_double(z); + + if(this == ModBlocks.red_barrel || this == ModBlocks.pink_barrel) { + world.newExplosion(entity, x, y, z, 2.5F, true, true); + } else if(this == ModBlocks.lox_barrel) { + world.newExplosion(entity, x, y, z, 1F, false, false); + + ExplosionThermo.freeze(world, ix, iy, iz, 7); + } else if(this == ModBlocks.taint_barrel) { + world.newExplosion(entity, x, y, z, 1F, false, false); + + Random rand = world.rand; + for(int i = 0; i < 100; i++) { + int a = rand.nextInt(9) - 4 + ix; + int b = rand.nextInt(9) - 4 + iy; + int c = rand.nextInt(9) - 4 + iz; + if(world.getBlock(a, b, c).isReplaceable(world, a, b, c) && BlockTaint.hasPosNeightbour(world, a, b, c)) { + world.setBlock(a, b, c, ModBlocks.taint, rand.nextInt(3) + 4, 2); + } + } + } } } diff --git a/src/main/java/com/hbm/blocks/generic/YellowBarrel.java b/src/main/java/com/hbm/blocks/generic/YellowBarrel.java index 7824939da..17895777c 100644 --- a/src/main/java/com/hbm/blocks/generic/YellowBarrel.java +++ b/src/main/java/com/hbm/blocks/generic/YellowBarrel.java @@ -3,12 +3,15 @@ package com.hbm.blocks.generic; import java.util.Random; import com.hbm.blocks.ModBlocks; +import com.hbm.blocks.bomb.BlockDetonatable; import com.hbm.blocks.machine.BlockFluidBarrel; +import com.hbm.entity.item.EntityTNTPrimedBase; import com.hbm.explosion.ExplosionNukeGeneric; import com.hbm.handler.radiation.ChunkRadiationManager; + +import codechicken.lib.math.MathHelper; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.init.Blocks; import net.minecraft.util.AxisAlignedBB; @@ -16,40 +19,18 @@ import net.minecraft.world.Explosion; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; -public class YellowBarrel extends Block { +public class YellowBarrel extends BlockDetonatable { Random rand = new Random(); - public YellowBarrel(Material p_i45386_1_) { - super(p_i45386_1_); + public YellowBarrel(Material material) { + super(material, 0, 0, 100, true, false); } @Override - public void onBlockDestroyedByExplosion(World p_149723_1_, int p_149723_2_, int p_149723_3_, int p_149723_4_, Explosion p_149723_5_) { - if(!p_149723_1_.isRemote && this == ModBlocks.yellow_barrel) { - explode(p_149723_1_, p_149723_2_, p_149723_3_, p_149723_4_); - } - } - - public void explode(World world, int x, int y, int z) { - - if(rand.nextInt(3) == 0) { - world.setBlock(x, y, z, ModBlocks.toxic_block); - } else { - world.createExplosion(null, x, y, z, 18.0F, true); - } - ExplosionNukeGeneric.waste(world, x, y, z, 35); - - for(int i = -5; i <= 5; i++) { - for(int j = -5; j <= 5; j++) { - for(int k = -5; k <= 5; k++) { - - if(world.rand.nextInt(5) == 0 && world.getBlock(x + i, y + j, z + k) == Blocks.air) - world.setBlock(x + i, y + j, z + k, ModBlocks.gas_radon_dense); - } - } - } - ChunkRadiationManager.proxy.incrementRad(world, x, y, z, 35); + public void onBlockDestroyedByExplosion(World world, int x, int y, int z, Explosion explosion) { + if (this != ModBlocks.yellow_barrel) return; + super.onBlockDestroyedByExplosion(world, x, y, z, explosion); } @Override @@ -80,17 +61,12 @@ public class YellowBarrel extends Block { return AxisAlignedBB.getBoundingBox(x + this.minX, y + this.minY, z + this.minZ, x + this.maxX, y + this.maxY, z + this.maxZ); } - @Override - public boolean canDropFromExplosion(Explosion p_149659_1_) { - return false; - } - @Override @SideOnly(Side.CLIENT) - public void randomDisplayTick(World p_149734_1_, int p_149734_2_, int p_149734_3_, int p_149734_4_, Random p_149734_5_) { - super.randomDisplayTick(p_149734_1_, p_149734_2_, p_149734_3_, p_149734_4_, p_149734_5_); + public void randomDisplayTick(World world, int x, int y, int z, Random rand) { + super.randomDisplayTick(world, x, y, z, rand); - p_149734_1_.spawnParticle("townaura", p_149734_2_ + p_149734_5_.nextFloat() * 0.5F + 0.25F, p_149734_3_ + 1.1F, p_149734_4_ + p_149734_5_.nextFloat() * 0.5F + 0.25F, 0.0D, 0.0D, 0.0D); + world.spawnParticle("townaura", x + rand.nextFloat() * 0.5F + 0.25F, y + 1.1F, z + rand.nextFloat() * 0.5F + 0.25F, 0.0D, 0.0D, 0.0D); } @Override @@ -115,4 +91,27 @@ public class YellowBarrel extends Block { world.scheduleBlockUpdate(x, y, z, this, this.tickRate(world)); } + @Override + public void explodeEntity(World world, double x, double y, double z, EntityTNTPrimedBase entity) { + int ix = MathHelper.floor_double(x), iy = MathHelper.floor_double(y), iz = MathHelper.floor_double(z); + + if(rand.nextInt(3) == 0) { + world.setBlock(ix, iy, iz, ModBlocks.toxic_block); + } else { + world.createExplosion(entity, x, y, z, 12.0F, true); + } + ExplosionNukeGeneric.waste(world, ix, iy, iz, 35); + + for(int i = -5; i <= 5; i++) { + for(int j = -5; j <= 5; j++) { + for(int k = -5; k <= 5; k++) { + + if(world.rand.nextInt(5) == 0 && world.getBlock(ix + i, iy + j, iz + k) == Blocks.air) + world.setBlock(ix + i, iy + j, iz + k, ModBlocks.gas_radon_dense); + } + } + } + ChunkRadiationManager.proxy.incrementRad(world, ix, iy, iz, 35); + } + } diff --git a/src/main/java/com/hbm/entity/item/EntityTNTPrimedBase.java b/src/main/java/com/hbm/entity/item/EntityTNTPrimedBase.java index ec93278b9..ee75627f8 100644 --- a/src/main/java/com/hbm/entity/item/EntityTNTPrimedBase.java +++ b/src/main/java/com/hbm/entity/item/EntityTNTPrimedBase.java @@ -1,7 +1,6 @@ package com.hbm.entity.item; -import com.hbm.blocks.bomb.BlockTNTBase; - +import api.hbm.block.IFuckingExplode; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.block.Block; @@ -12,6 +11,7 @@ import net.minecraft.world.World; public class EntityTNTPrimedBase extends Entity { + public boolean detonateOnCollision; public int fuse; private EntityLivingBase tntPlacedBy; @@ -21,9 +21,10 @@ public class EntityTNTPrimedBase extends Entity { this.setSize(0.98F, 0.98F); this.yOffset = this.height / 2.0F; this.fuse = 80; + this.detonateOnCollision = false; } - public EntityTNTPrimedBase(World world, double x, double y, double z, EntityLivingBase entity, BlockTNTBase bomb) { + public EntityTNTPrimedBase(World world, double x, double y, double z, EntityLivingBase entity, Block bomb) { this(world); this.setPosition(x, y, z); float f = (float) (Math.random() * Math.PI * 2.0D); @@ -69,8 +70,8 @@ public class EntityTNTPrimedBase extends Entity { this.motionZ *= 0.7D; this.motionY *= -0.5D; } - - if(this.fuse-- <= 0) { + + if(this.fuse-- <= 0 || (this.detonateOnCollision && this.isCollided)) { this.setDead(); if(!this.worldObj.isRemote) { @@ -85,8 +86,12 @@ public class EntityTNTPrimedBase extends Entity { this.getBomb().explodeEntity(worldObj, posX, posY, posZ, this); } - public BlockTNTBase getBomb() { - return (BlockTNTBase) Block.getBlockById(this.dataWatcher.getWatchableObjectInt(12)); + public IFuckingExplode getBomb() { + return (IFuckingExplode) getBlock(); + } + + public Block getBlock() { + return Block.getBlockById(this.dataWatcher.getWatchableObjectInt(12)); } @Override diff --git a/src/main/java/com/hbm/entity/projectile/EntityBullet.java b/src/main/java/com/hbm/entity/projectile/EntityBullet.java index 3bbf98b02..6924b0f3a 100644 --- a/src/main/java/com/hbm/entity/projectile/EntityBullet.java +++ b/src/main/java/com/hbm/entity/projectile/EntityBullet.java @@ -29,8 +29,7 @@ import net.minecraft.util.MovingObjectPosition; import net.minecraft.util.Vec3; import net.minecraft.world.World; -import com.hbm.blocks.ModBlocks; -import com.hbm.blocks.generic.RedBarrel; +import com.hbm.blocks.bomb.BlockDetonatable; import com.hbm.entity.grenade.EntityGrenadeTau; import com.hbm.entity.mob.EntityCreeperNuclear; import com.hbm.entity.particle.EntityBSmokeFX; @@ -43,9 +42,9 @@ import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; public class EntityBullet extends Entity implements IProjectile { - private int field_145791_d = -1; - private int field_145792_e = -1; - private int field_145789_f = -1; + private int tileX = -1; + private int tileY = -1; + private int tileZ = -1; public double gravity = 0.0D; private Block field_145790_g; private int inData; @@ -340,28 +339,28 @@ public class EntityBullet extends Entity implements IProjectile { // (float)(Math.atan2(this.motionY, (double)f) * 180.0D / Math.PI); } - Block block = this.worldObj.getBlock(this.field_145791_d, this.field_145792_e, this.field_145789_f); + Block block = this.worldObj.getBlock(this.tileX, this.tileY, this.tileZ); if (block.getMaterial() != Material.air) { - block.setBlockBoundsBasedOnState(this.worldObj, this.field_145791_d, this.field_145792_e, - this.field_145789_f); - AxisAlignedBB axisalignedbb = block.getCollisionBoundingBoxFromPool(this.worldObj, this.field_145791_d, - this.field_145792_e, this.field_145789_f); + block.setBlockBoundsBasedOnState(this.worldObj, this.tileX, this.tileY, + this.tileZ); + AxisAlignedBB axisalignedbb = block.getCollisionBoundingBoxFromPool(this.worldObj, this.tileX, + this.tileY, this.tileZ); if (axisalignedbb != null && axisalignedbb.isVecInside(Vec3.createVectorHelper(this.posX, this.posY, this.posZ)) && !this.getIsCritical()) { this.inGround = true; } - - if (block == ModBlocks.red_barrel) { - ((RedBarrel) block).explode(worldObj, this.field_145791_d, this.field_145792_e, this.field_145789_f); + + if(block instanceof BlockDetonatable) { + ((BlockDetonatable) block).onShot(worldObj, this.tileX, this.tileY, this.tileZ); } if (block == Blocks.glass || block == Blocks.stained_glass || block == Blocks.glass_pane || block == Blocks.stained_glass_pane) { - this.worldObj.setBlock(this.field_145791_d, this.field_145792_e, this.field_145789_f, Blocks.air); - this.worldObj.playSound(this.field_145791_d, this.field_145792_e, this.field_145789_f, "dig.glass", + this.worldObj.setBlock(this.tileX, this.tileY, this.tileZ, Blocks.air); + this.worldObj.playSound(this.tileX, this.tileY, this.tileZ, "dig.glass", 1.0F, 1.0F, true); } } @@ -609,13 +608,13 @@ public class EntityBullet extends Entity implements IProjectile { this.setDead(); } } else if (!this.getIsCritical()) { - this.field_145791_d = movingobjectposition.blockX; - this.field_145792_e = movingobjectposition.blockY; - this.field_145789_f = movingobjectposition.blockZ; - this.field_145790_g = this.worldObj.getBlock(this.field_145791_d, this.field_145792_e, - this.field_145789_f); - this.inData = this.worldObj.getBlockMetadata(this.field_145791_d, this.field_145792_e, - this.field_145789_f); + this.tileX = movingobjectposition.blockX; + this.tileY = movingobjectposition.blockY; + this.tileZ = movingobjectposition.blockZ; + this.field_145790_g = this.worldObj.getBlock(this.tileX, this.tileY, + this.tileZ); + this.inData = this.worldObj.getBlockMetadata(this.tileX, this.tileY, + this.tileZ); this.motionX = ((float) (movingobjectposition.hitVec.xCoord - this.posX)); this.motionY = ((float) (movingobjectposition.hitVec.yCoord - this.posY)); this.motionZ = ((float) (movingobjectposition.hitVec.zCoord - this.posZ)); @@ -628,8 +627,8 @@ public class EntityBullet extends Entity implements IProjectile { this.arrowShake = 7; if (this.field_145790_g.getMaterial() != Material.air) { - this.field_145790_g.onEntityCollidedWithBlock(this.worldObj, this.field_145791_d, - this.field_145792_e, this.field_145789_f, this); + this.field_145790_g.onEntityCollidedWithBlock(this.worldObj, this.tileX, + this.tileY, this.tileZ, this); } } } @@ -712,9 +711,9 @@ public class EntityBullet extends Entity implements IProjectile { */ @Override public void writeEntityToNBT(NBTTagCompound p_70014_1_) { - p_70014_1_.setShort("xTile", (short) this.field_145791_d); - p_70014_1_.setShort("yTile", (short) this.field_145792_e); - p_70014_1_.setShort("zTile", (short) this.field_145789_f); + p_70014_1_.setShort("xTile", (short) this.tileX); + p_70014_1_.setShort("yTile", (short) this.tileY); + p_70014_1_.setShort("zTile", (short) this.tileZ); p_70014_1_.setShort("life", (short) this.ticksInGround); p_70014_1_.setByte("inTile", (byte) Block.getIdFromBlock(this.field_145790_g)); p_70014_1_.setByte("inData", (byte) this.inData); @@ -729,9 +728,9 @@ public class EntityBullet extends Entity implements IProjectile { */ @Override public void readEntityFromNBT(NBTTagCompound p_70037_1_) { - this.field_145791_d = p_70037_1_.getShort("xTile"); - this.field_145792_e = p_70037_1_.getShort("yTile"); - this.field_145789_f = p_70037_1_.getShort("zTile"); + this.tileX = p_70037_1_.getShort("xTile"); + this.tileY = p_70037_1_.getShort("yTile"); + this.tileZ = p_70037_1_.getShort("zTile"); this.ticksInGround = p_70037_1_.getShort("life"); this.field_145790_g = Block.getBlockById(p_70037_1_.getByte("inTile") & 255); this.inData = p_70037_1_.getByte("inData") & 255; @@ -857,20 +856,18 @@ public class EntityBullet extends Entity implements IProjectile { @Override @SideOnly(Side.CLIENT) - public int getBrightnessForRender(float p_70070_1_) - { + public int getBrightnessForRender(float p_70070_1_) { if(this.getIsCritical() || this.getIsChopper()) return 15728880; else return super.getBrightnessForRender(p_70070_1_); - } + } - @Override - public float getBrightness(float p_70013_1_) - { + @Override + public float getBrightness(float p_70013_1_) { if(this.getIsCritical() || this.getIsChopper()) return 1.0F; else return super.getBrightness(p_70013_1_); - } + } } diff --git a/src/main/java/com/hbm/entity/projectile/EntityBulletBaseNT.java b/src/main/java/com/hbm/entity/projectile/EntityBulletBaseNT.java index 20bff21ba..2e44faf9f 100644 --- a/src/main/java/com/hbm/entity/projectile/EntityBulletBaseNT.java +++ b/src/main/java/com/hbm/entity/projectile/EntityBulletBaseNT.java @@ -4,8 +4,7 @@ import java.lang.reflect.Field; import java.util.ArrayList; import java.util.List; -import com.hbm.blocks.ModBlocks; -import com.hbm.blocks.generic.RedBarrel; +import com.hbm.blocks.bomb.BlockDetonatable; import com.hbm.entity.effect.EntityCloudFleijaRainbow; import com.hbm.entity.effect.EntityEMPBlast; import com.hbm.entity.logic.EntityNukeExplosionMK3; @@ -47,6 +46,7 @@ import net.minecraft.util.DamageSource; import net.minecraft.util.MathHelper; import net.minecraft.util.MovingObjectPosition; import net.minecraft.util.Vec3; +import net.minecraft.util.MovingObjectPosition.MovingObjectType; import net.minecraft.world.World; /** @@ -73,7 +73,7 @@ public class EntityBulletBaseNT extends EntityThrowableInterp implements IBullet public double prevRenderX; public double prevRenderY; public double prevRenderZ; - public final List> trailNodes = new ArrayList(); + public final List> trailNodes = new ArrayList>(); public BulletConfiguration getConfig() { return config; @@ -201,7 +201,7 @@ public class EntityBulletBaseNT extends EntityThrowableInterp implements IBullet return; } - if(worldObj.isRemote && config.style == config.STYLE_TAU) { + if(worldObj.isRemote && config.style == BulletConfiguration.STYLE_TAU) { if(trailNodes.isEmpty()) { this.ignoreFrustumCheck = true; trailNodes.add(new Pair(Vec3.createVectorHelper(-motionX * 2, -motionY * 2, -motionZ * 2), 0D)); @@ -265,7 +265,7 @@ public class EntityBulletBaseNT extends EntityThrowableInterp implements IBullet @Override protected void onImpact(MovingObjectPosition mop) { - if(mop.typeOfHit == mop.typeOfHit.BLOCK) { + if(mop.typeOfHit == MovingObjectType.BLOCK) { boolean hRic = rand.nextInt(100) < config.HBRC; boolean doesRic = config.doesRicochet && hRic; @@ -393,6 +393,7 @@ public class EntityBulletBaseNT extends EntityThrowableInterp implements IBullet //for when a bullet dies by hitting a block private void onBlockImpact(int bX, int bY, int bZ, int sideHit) { + Block block = worldObj.getBlock(bX, bY, bZ); if(config.bntImpact != null) config.bntImpact.behaveBlockHit(this, bX, bY, bZ, sideHit); @@ -418,17 +419,17 @@ public class EntityBulletBaseNT extends EntityThrowableInterp implements IBullet if(config.emp > 3) { if (!this.worldObj.isRemote) { - EntityEMPBlast cloud = new EntityEMPBlast(this.worldObj, config.emp); - cloud.posX = this.posX; - cloud.posY = this.posY + 0.5F; - cloud.posZ = this.posZ; - + EntityEMPBlast cloud = new EntityEMPBlast(this.worldObj, config.emp); + cloud.posX = this.posX; + cloud.posY = this.posY + 0.5F; + cloud.posZ = this.posZ; + this.worldObj.spawnEntityInWorld(cloud); } } if(config.jolt > 0 && !worldObj.isRemote) - ExplosionLarge.jolt(worldObj, posX, posY, posZ, config.jolt, 150, 0.25); + ExplosionLarge.jolt(worldObj, posX, posY, posZ, config.jolt, 150, 0.25); if(config.explosive > 0 && !worldObj.isRemote) { //worldObj.newExplosion(this.thrower, posX, posY, posZ, config.explosive, config.incendiary > 0, config.blockDamage); @@ -447,7 +448,7 @@ public class EntityBulletBaseNT extends EntityThrowableInterp implements IBullet if(config.chlorine > 0 && !worldObj.isRemote) { ExplosionChaos.spawnChlorine(worldObj, posX, posY, posZ, config.chlorine, 1.5, 0); - worldObj.playSoundEffect((double)(posX + 0.5F), (double)(posY + 0.5F), (double)(posZ + 0.5F), "random.fizz", 5.0F, 2.6F + (rand.nextFloat() - rand.nextFloat()) * 0.8F); + worldObj.playSoundEffect((double)(posX + 0.5F), (double)(posY + 0.5F), (double)(posZ + 0.5F), "random.fizz", 5.0F, 2.6F + (rand.nextFloat() - rand.nextFloat()) * 0.8F); } if(config.rainbow > 0 && !worldObj.isRemote) { @@ -465,7 +466,7 @@ public class EntityBulletBaseNT extends EntityThrowableInterp implements IBullet } if(config.nuke > 0 && !worldObj.isRemote) { - worldObj.spawnEntityInWorld(EntityNukeExplosionMK5.statFac(worldObj, config.nuke, posX, posY, posZ)); + worldObj.spawnEntityInWorld(EntityNukeExplosionMK5.statFac(worldObj, config.nuke, posX, posY, posZ)); NBTTagCompound data = new NBTTagCompound(); data.setString("type", "muke"); if(MainRegistry.polaroidID == 11 || rand.nextInt(100) == 0) data.setBoolean("balefire", true); @@ -474,17 +475,15 @@ public class EntityBulletBaseNT extends EntityThrowableInterp implements IBullet } if(config.destroysBlocks && !worldObj.isRemote) { - if(worldObj.getBlock(bX, bY, bZ).getBlockHardness(worldObj, bX, bY, bZ) <= 120) - worldObj.func_147480_a(bX, bY, bZ, false); + if(block.getBlockHardness(worldObj, bX, bY, bZ) <= 120) + worldObj.func_147480_a(bX, bY, bZ, false); } else if(config.doesBreakGlass && !worldObj.isRemote) { - if(worldObj.getBlock(bX, bY, bZ) == Blocks.glass || - worldObj.getBlock(bX, bY, bZ) == Blocks.glass_pane || - worldObj.getBlock(bX, bY, bZ) == Blocks.stained_glass || - worldObj.getBlock(bX, bY, bZ) == Blocks.stained_glass_pane) + if(block == Blocks.glass || block == Blocks.glass_pane || block == Blocks.stained_glass || block == Blocks.stained_glass_pane) worldObj.func_147480_a(bX, bY, bZ, false); - if(worldObj.getBlock(bX, bY, bZ) == ModBlocks.red_barrel) - ((RedBarrel) ModBlocks.red_barrel).explode(worldObj, bX, bY, bZ); + if(block instanceof BlockDetonatable) { + ((BlockDetonatable) block).onShot(worldObj, bX, bY, bZ); + } } } diff --git a/src/main/java/com/hbm/handler/guncfg/GunOSIPRFactory.java b/src/main/java/com/hbm/handler/guncfg/GunOSIPRFactory.java index 47c3e698c..deb53436a 100644 --- a/src/main/java/com/hbm/handler/guncfg/GunOSIPRFactory.java +++ b/src/main/java/com/hbm/handler/guncfg/GunOSIPRFactory.java @@ -2,7 +2,7 @@ package com.hbm.handler.guncfg; import java.util.ArrayList; -import com.hbm.blocks.generic.RedBarrel; +import com.hbm.blocks.bomb.BlockDetonatable; import com.hbm.handler.BulletConfigSyncingUtil; import com.hbm.handler.BulletConfiguration; import com.hbm.handler.GunConfiguration; @@ -122,16 +122,16 @@ public class GunOSIPRFactory { bullet.bntRicochet = (ball, x, y, z) -> { Block block = ball.worldObj.getBlock(x, y, z); - if(block instanceof RedBarrel) - ((RedBarrel) block).explode(ball.worldObj, x, y, z); - + if(block instanceof BlockDetonatable) { + ((BlockDetonatable) block).onShot(ball.worldObj, x, y, z); + } }; bullet.bntImpact = (ball, x, y, z, sideHit) -> { - final Block block = ball.worldObj.getBlock(x, y, z); - if(block instanceof RedBarrel) - ((RedBarrel) block).explode(ball.worldObj, x, y, z); - + Block block = ball.worldObj.getBlock(x, y, z); + if(block instanceof BlockDetonatable) { + ((BlockDetonatable) block).onShot(ball.worldObj, x, y, z); + } }; return bullet; diff --git a/src/main/java/com/hbm/inventory/gui/GUIScreenWikiRender.java b/src/main/java/com/hbm/inventory/gui/GUIScreenWikiRender.java index 85e9b2ee6..900e4e9b6 100644 --- a/src/main/java/com/hbm/inventory/gui/GUIScreenWikiRender.java +++ b/src/main/java/com/hbm/inventory/gui/GUIScreenWikiRender.java @@ -3,6 +3,7 @@ package com.hbm.inventory.gui; import java.awt.image.BufferedImage; import java.io.File; import java.nio.IntBuffer; +import java.util.function.Function; import javax.imageio.ImageIO; @@ -31,9 +32,24 @@ public class GUIScreenWikiRender extends GuiScreen { protected static final ResourceLocation texture = new ResourceLocation(RefStrings.MODID + ":textures/gui/nei/gui_nei.png"); protected ItemStack[] preview; protected int index = 0; + protected int scale = 1; + protected String saveLocation = "wiki-screenshots"; + protected String prefix = ""; - public GUIScreenWikiRender(ItemStack[] stacks) { + protected Function getStackName = (stack) -> { + return stack.getDisplayName(); + }; + + public GUIScreenWikiRender(ItemStack[] stacks, String prefix, String directory, int scale) { this.preview = stacks; + this.prefix = prefix; + this.saveLocation = directory; + this.scale = scale; + } + + public GUIScreenWikiRender(ItemStack[] stacks, String prefix, String directory, int scale, Function getStackName) { + this(stacks, prefix, directory, scale); + this.getStackName = getStackName; } @Override @@ -54,11 +70,14 @@ public class GUIScreenWikiRender extends GuiScreen { GL11.glDisable(GL11.GL_LIGHTING); this.drawGuiContainerForegroundLayer(preview[index]); GL11.glEnable(GL11.GL_LIGHTING); + + ScaledResolution res = new ScaledResolution(this.mc, this.mc.displayWidth, this.mc.displayHeight); + int zoom = scale * res.getScaleFactor(); try { - String slotName = preview[index].getDisplayName().replaceAll("§.", "").replaceAll("[^\\w ().-]+", ""); + String slotName = getStackName.apply(preview[index]).replaceAll("§.", "").replaceAll("[^\\w ().-]+", ""); if(!slotName.endsWith(".name")) { - saveScreenshot(Minecraft.getMinecraft().mcDataDir, "Slot " + slotName + ".png", 2, 2, 32, 32, 0xFF8B8B8B); + saveScreenshot(Minecraft.getMinecraft().mcDataDir, saveLocation, prefix + slotName + ".png", zoom, zoom, zoom * 16, zoom * 16, 0xFF8B8B8B); } } catch (Exception ex) { // Just skip any failures caused by display name or rendering @@ -72,7 +91,8 @@ public class GUIScreenWikiRender extends GuiScreen { GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); this.mc.getTextureManager().bindTexture(texture); ScaledResolution res = new ScaledResolution(this.mc, this.mc.displayWidth, this.mc.displayHeight); - this.drawTexturedModalRect(0, res.getScaledHeight_double() - 18D, 5, 87, 18, 18); + GL11.glScaled(scale, scale, scale); + this.drawTexturedModalRect(0, res.getScaledHeight_double() / scale - 18D, 5, 87, 18, 18); GL11.glPopMatrix(); } @@ -100,8 +120,10 @@ public class GUIScreenWikiRender extends GuiScreen { GL11.glEnable(GL11.GL_LIGHTING); GL11.glEnable(GL11.GL_DEPTH_TEST); + GL11.glScaled(scale, scale, scale); + ScaledResolution res = new ScaledResolution(this.mc, this.mc.displayWidth, this.mc.displayHeight); - GL11.glTranslated(9D, res.getScaledHeight_double() - 9D, -200); + GL11.glTranslated(9D, res.getScaledHeight_double() / scale - 9D, -200); this.zLevel = 200.0F; itemRender.zLevel = 200.0F; @@ -122,9 +144,9 @@ public class GUIScreenWikiRender extends GuiScreen { // This implementation is based directly on ScreenShotHelper.saveScreenshot() // But allows for defining a rect where you want to sample pixels from - private static void saveScreenshot(File dataDir, String fileName, int x, int y, int width, int height, int transparentColor) { + private static void saveScreenshot(File dataDir, String ssDir, String fileName, int x, int y, int width, int height, int transparentColor) { try { - File screenshotDirectory = new File(dataDir, "wiki-screenshots"); + File screenshotDirectory = new File(dataDir, ssDir); screenshotDirectory.mkdir(); int bufferSize = width * height; diff --git a/src/main/java/com/hbm/main/ModEventHandlerClient.java b/src/main/java/com/hbm/main/ModEventHandlerClient.java index 86a0f3e26..cb9787e5c 100644 --- a/src/main/java/com/hbm/main/ModEventHandlerClient.java +++ b/src/main/java/com/hbm/main/ModEventHandlerClient.java @@ -998,7 +998,6 @@ public class ModEventHandlerClient { ModItems.crucible_template, ModItems.chemistry_template, ModItems.chemistry_icon, - ModItems.fluid_icon, ModItems.achievement_icon, Items.spawn_egg, Item.getItemFromBlock(Blocks.mob_spawner) @@ -1021,7 +1020,7 @@ public class ModEventHandlerClient { } } - FMLCommonHandler.instance().showGuiScreen(new GUIScreenWikiRender(stacks.toArray(new ItemStack[0]))); + FMLCommonHandler.instance().showGuiScreen(new GUIScreenWikiRender(stacks.toArray(new ItemStack[0]), "Block ", "wiki-block-renders-256", 8)); } } else { isRenderingItems = false; diff --git a/src/main/java/com/hbm/main/ResourceManager.java b/src/main/java/com/hbm/main/ResourceManager.java index bc2017527..fa6578bf5 100644 --- a/src/main/java/com/hbm/main/ResourceManager.java +++ b/src/main/java/com/hbm/main/ResourceManager.java @@ -1465,12 +1465,15 @@ public class ResourceManager { public static final IModelCustom deco_computer = AdvancedModelLoader.loadModel(new ResourceLocation(RefStrings.MODID, "models/blocks/puter.obj")); + // Some RBMK elements are loaded twice due to VBOs not supporting tessellation public static final IModelCustom rbmk_element = AdvancedModelLoader.loadModel(new ResourceLocation(RefStrings.MODID, "models/rbmk/rbmk_element.obj")); + public static final IModelCustom rbmk_element_vbo = new HFRWavefrontObject(new ResourceLocation(RefStrings.MODID, "models/rbmk/rbmk_element.obj")).asVBO(); public static final IModelCustom rbmk_reflector = AdvancedModelLoader.loadModel(new ResourceLocation(RefStrings.MODID, "models/rbmk/rbmk_reflector.obj")); public static final IModelCustom rbmk_rods = AdvancedModelLoader.loadModel(new ResourceLocation(RefStrings.MODID, "models/rbmk/rbmk_rods.obj")); - public static final IModelCustom rbmk_crane_console = new HFRWavefrontObject(new ResourceLocation(RefStrings.MODID, "models/rbmk/crane_console.obj")); - public static final IModelCustom rbmk_crane = new HFRWavefrontObject(new ResourceLocation(RefStrings.MODID, "models/rbmk/crane.obj")); - public static final IModelCustom rbmk_console = new HFRWavefrontObject(new ResourceLocation(RefStrings.MODID, "models/rbmk/rbmk_console.obj")); + public static final IModelCustom rbmk_rods_vbo = new HFRWavefrontObject(new ResourceLocation(RefStrings.MODID, "models/rbmk/rbmk_rods.obj")).asVBO(); + public static final IModelCustom rbmk_crane_console = new HFRWavefrontObject(new ResourceLocation(RefStrings.MODID, "models/rbmk/crane_console.obj")).asVBO(); + public static final IModelCustom rbmk_crane = new HFRWavefrontObject(new ResourceLocation(RefStrings.MODID, "models/rbmk/crane.obj")).asVBO(); + public static final IModelCustom rbmk_console = new HFRWavefrontObject(new ResourceLocation(RefStrings.MODID, "models/rbmk/rbmk_console.obj")).asVBO(); public static final IModelCustom rbmk_debris = AdvancedModelLoader.loadModel(new ResourceLocation(RefStrings.MODID, "models/rbmk/debris.obj")); public static final ResourceLocation rbmk_crane_console_tex = new ResourceLocation(RefStrings.MODID, "textures/models/machines/crane_console.png"); public static final ResourceLocation rbmk_crane_tex = new ResourceLocation(RefStrings.MODID, "textures/models/machines/rbmk_crane.png"); diff --git a/src/main/java/com/hbm/render/block/RenderFoundryBasin.java b/src/main/java/com/hbm/render/block/RenderFoundryBasin.java index 342ec7838..17917603a 100644 --- a/src/main/java/com/hbm/render/block/RenderFoundryBasin.java +++ b/src/main/java/com/hbm/render/block/RenderFoundryBasin.java @@ -23,8 +23,6 @@ public class RenderFoundryBasin implements ISimpleBlockRenderingHandler { double z = 0; GL11.glTranslatef(-0.5F, -0.5F, -0.5F); - - basin.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F); tessellator.startDrawingQuads(); tessellator.setNormal(0F, 1F, 0F); diff --git a/src/main/java/com/hbm/render/block/RenderFoundryMold.java b/src/main/java/com/hbm/render/block/RenderFoundryMold.java index 5958ba8e5..8d266227a 100644 --- a/src/main/java/com/hbm/render/block/RenderFoundryMold.java +++ b/src/main/java/com/hbm/render/block/RenderFoundryMold.java @@ -24,7 +24,7 @@ public class RenderFoundryMold implements ISimpleBlockRenderingHandler { GL11.glTranslatef(-0.5F, -0.5F, -0.5F); - basin.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.5F, 1.0F); + renderer.setRenderBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.5F, 1.0F); tessellator.startDrawingQuads(); tessellator.setNormal(0F, 1F, 0F); diff --git a/src/main/java/com/hbm/render/entity/item/RenderTNTPrimedBase.java b/src/main/java/com/hbm/render/entity/item/RenderTNTPrimedBase.java index 7c121733c..118074dd7 100644 --- a/src/main/java/com/hbm/render/entity/item/RenderTNTPrimedBase.java +++ b/src/main/java/com/hbm/render/entity/item/RenderTNTPrimedBase.java @@ -44,7 +44,7 @@ public class RenderTNTPrimedBase extends Render { f2 = (1.0F - ((float) tnt.fuse - f1 + 1.0F) / 100.0F) * 0.8F; this.bindEntityTexture(tnt); - this.blockRenderer.renderBlockAsItem(tnt.getBomb(), 0, tnt.getBrightness(f1)); + this.blockRenderer.renderBlockAsItem(tnt.getBlock(), 0, tnt.getBrightness(f1)); if(tnt.fuse / 5 % 2 == 0) { @@ -56,7 +56,7 @@ public class RenderTNTPrimedBase extends Render { GL11.glColor4f(1.0F, 1.0F, 1.0F, f2); boolean prev = this.blockRenderer.useInventoryTint; this.blockRenderer.useInventoryTint = false; - this.blockRenderer.renderBlockAsItem(tnt.getBomb(), 0, 1.0F); + this.blockRenderer.renderBlockAsItem(tnt.getBlock(), 0, 1.0F); this.blockRenderer.useInventoryTint = prev; GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); GL11.glDisable(GL11.GL_BLEND); diff --git a/src/main/java/com/hbm/render/tileentity/RenderRBMKControlRod.java b/src/main/java/com/hbm/render/tileentity/RenderRBMKControlRod.java index 0420f0ecb..2c19afce5 100644 --- a/src/main/java/com/hbm/render/tileentity/RenderRBMKControlRod.java +++ b/src/main/java/com/hbm/render/tileentity/RenderRBMKControlRod.java @@ -48,7 +48,7 @@ public class RenderRBMKControlRod extends TileEntitySpecialRenderer { double level = control.lastLevel + (control.level - control.lastLevel) * i; GL11.glTranslated(0, level, 0); - ResourceManager.rbmk_rods.renderPart("Lid"); + ResourceManager.rbmk_rods_vbo.renderPart("Lid"); GL11.glPopMatrix(); } diff --git a/src/main/java/com/hbm/render/tileentity/RenderRBMKLid.java b/src/main/java/com/hbm/render/tileentity/RenderRBMKLid.java index 465c33e67..2783e8508 100644 --- a/src/main/java/com/hbm/render/tileentity/RenderRBMKLid.java +++ b/src/main/java/com/hbm/render/tileentity/RenderRBMKLid.java @@ -71,36 +71,37 @@ public class RenderRBMKLid extends TileEntitySpecialRenderer { if(meta == RBMKBase.DIR_GLASS_LID.ordinal()) { bindTexture(texture_glass); } else { - if(control.getBlockType() instanceof RBMKBase) { bindTexture(((RBMKBase)control.getBlockType()).coverTexture); } else { bindTexture(texture); } + cherenkov = false; } - if((control instanceof TileEntityRBMKBoiler || control instanceof TileEntityRBMKHeater) && meta != RBMKBase.DIR_GLASS_LID.ordinal()) - ResourceManager.rbmk_rods.renderPart("Lid"); - ResourceManager.rbmk_element.renderPart("Lid"); + if((control instanceof TileEntityRBMKBoiler || control instanceof TileEntityRBMKHeater) && meta != RBMKBase.DIR_GLASS_LID.ordinal()) { + ResourceManager.rbmk_rods_vbo.renderPart("Lid"); + } else { + ResourceManager.rbmk_element_vbo.renderPart("Lid"); + } + GL11.glPopMatrix(); } if(hasRod) { - GL11.glPushMatrix(); bindTexture(texture_rods); for(int j = 0; j <= offset; j++) { - - ResourceManager.rbmk_element.renderPart("Rods"); + ResourceManager.rbmk_element_vbo.renderPart("Rods"); GL11.glTranslated(0, 1, 0); } + GL11.glPopMatrix(); } if(cherenkov) { - GL11.glTranslated(0, 0.75, 0); GL11.glDisable(GL11.GL_CULL_FACE);