2017-02-23 13:29:43 +01:00
|
|
|
/*
|
|
|
|
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
|
|
|
*
|
|
|
|
* Copyright (c) 2017 TechReborn
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in all
|
|
|
|
* copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2016-03-13 12:50:46 +01:00
|
|
|
package techreborn.blocks;
|
|
|
|
|
|
|
|
import me.modmuss50.jsonDestroyer.api.ITexturedBlock;
|
2016-03-16 16:52:27 +01:00
|
|
|
import net.minecraft.block.Block;
|
|
|
|
import net.minecraft.block.material.Material;
|
|
|
|
import net.minecraft.block.properties.PropertyBool;
|
2016-03-16 17:26:44 +01:00
|
|
|
import net.minecraft.block.state.BlockStateContainer;
|
2016-03-13 12:50:46 +01:00
|
|
|
import net.minecraft.block.state.IBlockState;
|
2016-03-16 16:52:27 +01:00
|
|
|
import net.minecraft.entity.Entity;
|
2016-03-13 12:50:46 +01:00
|
|
|
import net.minecraft.entity.EntityLivingBase;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2016-03-24 01:41:47 +01:00
|
|
|
import net.minecraft.entity.projectile.EntityArrow;
|
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;
|
2016-03-16 16:52:27 +01:00
|
|
|
import reborncore.common.BaseBlock;
|
2016-03-13 12:50:46 +01:00
|
|
|
import techreborn.client.TechRebornCreativeTabMisc;
|
2017-06-11 22:22:07 +02:00
|
|
|
import techreborn.entities.EntityNukePrimed;
|
2016-03-13 12:50:46 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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-11-19 15:41:00 +01:00
|
|
|
worldIn.spawnEntity(entitynukeprimed);
|
2016-03-25 10:47:34 +01:00
|
|
|
// 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;
|
2016-11-19 15:41:00 +01:00
|
|
|
worldIn.spawnEntity(entitynukeprimed);
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
*/
|
2017-01-26 22:44:18 +01:00
|
|
|
@Override
|
|
|
|
public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos p_189540_5_) {
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn,
|
2016-11-19 15:41:00 +01:00
|
|
|
EnumHand hand, 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-11-28 14:05:11 +01:00
|
|
|
return "techreborn:blocks/nuke_front";
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
2016-11-28 14:05:11 +01:00
|
|
|
if (enumFacing == EnumFacing.UP || enumFacing == EnumFacing.DOWN) {
|
|
|
|
return "techreborn:blocks/nuke_top";
|
|
|
|
}
|
|
|
|
return "techreborn:blocks/nuke_side";
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@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) {
|
2016-04-03 15:34:39 +02:00
|
|
|
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-16 16:52:27 +01:00
|
|
|
|
2016-03-13 12:50:46 +01:00
|
|
|
}
|