Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package halestormxv.eAngelus.blocks;
- import halestormxv.eAngelus.gui.DualFurnaceGuiHandler;
- import halestormxv.eAngelus.main.Reference;
- import halestormxv.eAngelus.main.init.eAngelusBlocks;
- import halestormxv.eAngelus.tileentity.TileEntityDualFurnace;
- import net.minecraft.block.Block;
- import net.minecraft.block.BlockHorizontal;
- import net.minecraft.block.ITileEntityProvider;
- import net.minecraft.block.material.MapColor;
- import net.minecraft.block.material.Material;
- import net.minecraft.block.properties.IProperty;
- import net.minecraft.block.properties.PropertyBool;
- import net.minecraft.block.properties.PropertyDirection;
- import net.minecraft.block.state.BlockStateContainer;
- import net.minecraft.block.state.IBlockState;
- import net.minecraft.entity.EntityLivingBase;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.init.SoundEvents;
- import net.minecraft.inventory.InventoryHelper;
- import net.minecraft.item.Item;
- import net.minecraft.item.ItemStack;
- import net.minecraft.tileentity.TileEntity;
- import net.minecraft.util.*;
- import net.minecraft.util.math.BlockPos;
- import net.minecraft.world.IBlockAccess;
- import net.minecraft.world.World;
- import net.minecraftforge.fml.relauncher.Side;
- import net.minecraftforge.fml.relauncher.SideOnly;
- import javax.annotation.Nullable;
- import java.util.Random;
- /**
- * Created by Blaze on 8/27/2017.
- */
- public class DualFurance extends Block implements ITileEntityProvider
- {
- public static final PropertyDirection FACING = BlockHorizontal.FACING;
- public static final PropertyBool BURNING = PropertyBool.create("burning");
- public DualFurance()
- {
- super(Material.ROCK, MapColor.CYAN);
- setUnlocalizedName("dual_furnace");
- setRegistryName("blockdualfurnace");
- setCreativeTab(Reference.eaCreativeTab);
- this.setHardness(2.8F);
- this.setResistance(3.2F);
- this.setHarvestLevel("pickaxe", 2);
- this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH).withProperty(BURNING, false));
- }
- @Override
- public Item getItemDropped(IBlockState state, Random rand, int fortune)
- {
- //return Item.getItemFromBlock(eAngelusBlocks.dual_furnace);
- return Item.getItemFromBlock(this);
- }
- @Override
- public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state) {
- this.setDefaultFacing(worldIn, pos, state);
- }
- private void setDefaultFacing(World worldIn, BlockPos pos, IBlockState state)
- {
- if(!worldIn.isRemote)
- {
- IBlockState north = worldIn.getBlockState(pos.north());
- IBlockState south = worldIn.getBlockState(pos.south());
- IBlockState west = worldIn.getBlockState(pos.west());
- IBlockState east = worldIn.getBlockState(pos.east());
- EnumFacing face = (EnumFacing)state.getValue(FACING);
- if(face == EnumFacing.NORTH && north.isFullBlock() && !south.isFullBlock())
- face = EnumFacing.SOUTH;
- else if(face == EnumFacing.SOUTH && south.isFullBlock() && !north.isFullBlock())
- face = EnumFacing.NORTH;
- else if(face == EnumFacing.WEST && west.isFullBlock() && !east.isFullBlock())
- face = EnumFacing.EAST;
- else if(face == EnumFacing.EAST && east.isFullBlock() && !west.isFullBlock())
- face = EnumFacing.WEST;
- worldIn.setBlockState(pos, state.withProperty(FACING, face), 2);
- }
- }
- @Override
- public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
- if(!worldIn.isRemote)
- playerIn.openGui(Reference.MODID, DualFurnaceGuiHandler.DUAL_FURNACE_GUI, worldIn, pos.getX(), pos.getY(), pos.getZ());
- return true;
- }
- public static void setState(boolean active, World worldIn, BlockPos pos)
- {
- IBlockState state = worldIn.getBlockState(pos);
- TileEntity tileEntity = worldIn.getTileEntity(pos);
- if(active) {
- worldIn.setBlockState(pos, eAngelusBlocks.dual_furnace.getDefaultState().withProperty(FACING, state.getValue(FACING)).withProperty(BURNING, true), 3);
- } else {
- worldIn.setBlockState(pos, eAngelusBlocks.dual_furnace.getDefaultState().withProperty(FACING, state.getValue(FACING)).withProperty(BURNING, false), 3);
- }
- if(tileEntity != null)
- {
- tileEntity.validate();
- worldIn.setTileEntity(pos, tileEntity);
- }
- }
- @Nullable
- @Override
- public TileEntity createNewTileEntity(World worldIn, int meta)
- {
- return new TileEntityDualFurnace();
- }
- @Override
- public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack)
- {
- worldIn.setBlockState(pos, state.withProperty(FACING, placer.getHorizontalFacing().getOpposite()), 2);
- }
- @Override
- public void breakBlock(World worldIn, BlockPos pos, IBlockState state) {
- TileEntityDualFurnace tileEntity = (TileEntityDualFurnace)worldIn.getTileEntity(pos);
- InventoryHelper.dropInventoryItems(worldIn, pos, tileEntity);
- super.breakBlock(worldIn, pos, state);
- }
- @Override
- public ItemStack getItem(World worldIn, BlockPos pos, IBlockState state)
- {
- return new ItemStack(eAngelusBlocks.dual_furnace);
- }
- @Override
- public EnumBlockRenderType getRenderType(IBlockState state)
- {
- return EnumBlockRenderType.MODEL;
- }
- @Override
- public IBlockState getStateFromMeta(int meta)
- {
- boolean blockIsActive = (meta & 7) > 2;
- EnumFacing facing = EnumFacing.getFront(meta);
- if(facing.getAxis() == EnumFacing.Axis.Y)
- facing = EnumFacing.NORTH;
- return this.getDefaultState().withProperty(FACING, facing).withProperty(BURNING, blockIsActive);
- }
- @Override
- public int getMetaFromState(IBlockState state)
- {
- int blockIsActive = (state.getValue(BURNING) ? 1 : 0) << 2;
- int facingDirection = ((EnumFacing)state.getValue(FACING)).getIndex();
- return blockIsActive | facingDirection;
- }
- @Override
- public IBlockState withRotation(IBlockState state, Rotation rot)
- {
- return state.withProperty(FACING, rot.rotate((EnumFacing)state.getValue(FACING)));
- }
- @Override
- public IBlockState withMirror(IBlockState state, Mirror mirrorIn)
- {
- return state.withRotation(mirrorIn.toRotation((EnumFacing)state.getValue(FACING)));
- }
- @Override
- protected BlockStateContainer createBlockState()
- {
- return new BlockStateContainer(this, new IProperty[] {BURNING, FACING});
- }
- @Override
- public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos) {
- return super.getActualState(state, worldIn, pos);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement