TechReborn/src/main/java/techreborn/blocks/BlockNuke.java

120 lines
4.1 KiB
Java
Raw Normal View History

2016-03-13 12:50:46 +01:00
package techreborn.blocks;
import me.modmuss50.jsonDestroyer.api.ITexturedBlock;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.state.BlockStateContainer;
2016-03-13 12:50:46 +01:00
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
2016-03-13 12:50:46 +01:00
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityArrow;
2016-03-25 10:47:34 +01:00
import net.minecraft.item.ItemStack;
2016-03-15 09:13:05 +01:00
import net.minecraft.util.EnumFacing;
2016-03-13 17:08:30 +01:00
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
2016-03-13 12:50:46 +01:00
import net.minecraft.world.Explosion;
import net.minecraft.world.World;
import reborncore.RebornCore;
import reborncore.common.BaseBlock;
2016-03-13 12:50:46 +01:00
import techreborn.client.TechRebornCreativeTabMisc;
import techreborn.entitys.EntityNukePrimed;
/**
* Created by Mark on 13/03/2016.
*/
2016-10-08 21:46:16 +02:00
public class BlockNuke extends BaseBlock implements ITexturedBlock {
2016-03-25 10:47:34 +01:00
public static final PropertyBool OVERLAY = PropertyBool.create("overlay");
2016-10-08 21:46:16 +02:00
public BlockNuke() {
2016-05-06 23:13:24 +02:00
super(Material.TNT);
2016-03-25 10:47:34 +01:00
setUnlocalizedName("techreborn.nuke");
setCreativeTab(TechRebornCreativeTabMisc.instance);
RebornCore.jsonDestroyer.registerObject(this);
this.setDefaultState(this.blockState.getBaseState().withProperty(OVERLAY, false));
}
2016-10-08 21:46:16 +02:00
public void explode(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase igniter) {
if (!worldIn.isRemote) {
2016-03-25 10:47:34 +01:00
EntityNukePrimed entitynukeprimed = new EntityNukePrimed(worldIn, (double) ((float) pos.getX() + 0.5F),
2016-10-08 21:46:16 +02:00
(double) pos.getY(), (double) ((float) pos.getZ() + 0.5F), igniter);
2016-03-25 10:47:34 +01:00
worldIn.spawnEntityInWorld(entitynukeprimed);
// worldIn.playSoundAtEntity(entitynukeprimed, "game.tnt.primed",
// 1.0F, 1.0F);
}
}
@Override
2016-10-08 21:46:16 +02:00
public void onBlockDestroyedByExplosion(World worldIn, BlockPos pos, Explosion explosionIn) {
if (!worldIn.isRemote) {
2016-03-25 10:47:34 +01:00
EntityNukePrimed entitynukeprimed = new EntityNukePrimed(worldIn, (double) ((float) pos.getX() + 0.5F),
2016-10-08 21:46:16 +02:00
(double) pos.getY(), (double) ((float) pos.getZ() + 0.5F), explosionIn.getExplosivePlacedBy());
2016-03-25 10:47:34 +01:00
entitynukeprimed.fuse = worldIn.rand.nextInt(entitynukeprimed.fuse / 4) + entitynukeprimed.fuse / 8;
worldIn.spawnEntityInWorld(entitynukeprimed);
}
}
2016-10-08 21:46:16 +02:00
public void onEntityCollidedWithBlock(World worldIn, BlockPos pos, IBlockState state, Entity entityIn) {
if (!worldIn.isRemote && entityIn instanceof EntityArrow) {
2016-03-25 10:47:34 +01:00
EntityArrow entityarrow = (EntityArrow) entityIn;
2016-10-08 21:46:16 +02:00
if (entityarrow.isBurning()) {
2016-03-25 10:47:34 +01:00
this.explode(worldIn, pos, state, entityarrow.shootingEntity instanceof EntityLivingBase
2016-10-08 21:46:16 +02:00
? (EntityLivingBase) entityarrow.shootingEntity : null);
2016-03-25 10:47:34 +01:00
worldIn.setBlockToAir(pos);
}
}
}
2016-10-08 21:46:16 +02:00
public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state) {
2016-03-25 10:47:34 +01:00
super.onBlockAdded(worldIn, pos, state);
2016-10-08 21:46:16 +02:00
if (worldIn.isBlockPowered(pos)) {
2016-03-25 10:47:34 +01:00
this.explode(worldIn, pos, state, null);
worldIn.setBlockToAir(pos);
}
}
/**
* Called when a neighboring block changes.
*/
2016-10-08 21:46:16 +02:00
public void onNeighborBlockChange(World worldIn, BlockPos pos, IBlockState state, Block neighborBlock) {
if (worldIn.isBlockPowered(pos)) {
2016-03-25 10:47:34 +01:00
this.explode(worldIn, pos, state, null);
worldIn.setBlockToAir(pos);
}
}
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn,
2016-10-08 21:46:16 +02:00
EnumHand hand, ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) {
2016-03-25 10:47:34 +01:00
return false;
}
@Override
2016-10-08 21:46:16 +02:00
public String getTextureNameFromState(IBlockState iBlockState, EnumFacing enumFacing) {
if (iBlockState.getValue(OVERLAY)) {
2016-03-25 10:47:34 +01:00
return "techreborn:blocks/nuke_overlay";
}
return "techreborn:blocks/nuke";
}
@Override
2016-10-08 21:46:16 +02:00
public int amountOfStates() {
2016-03-25 10:47:34 +01:00
return 2;
}
2016-10-08 21:46:16 +02:00
public int getMetaFromState(IBlockState state) {
2016-03-25 10:47:34 +01:00
return state.getValue(OVERLAY) ? 1 : 0;
}
2016-10-08 21:46:16 +02:00
public IBlockState getStateFromMeta(int meta) {
return this.getDefaultState().withProperty(OVERLAY, (meta & 1) > 0);
2016-03-25 10:47:34 +01:00
}
2016-10-08 21:46:16 +02:00
protected BlockStateContainer createBlockState() {
2016-03-25 10:47:34 +01:00
return new BlockStateContainer(this, OVERLAY);
}
2016-03-13 12:50:46 +01:00
}