Advertisement
HalestormXV

Untitled

Sep 1st, 2017
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.01 KB | None | 0 0
  1. package halestormxv.eAngelus.blocks;
  2.  
  3. import halestormxv.eAngelus.gui.DualFurnaceGuiHandler;
  4. import halestormxv.eAngelus.main.Reference;
  5. import halestormxv.eAngelus.main.init.eAngelusBlocks;
  6. import halestormxv.eAngelus.tileentity.TileEntityDualFurnace;
  7. import net.minecraft.block.Block;
  8. import net.minecraft.block.BlockHorizontal;
  9. import net.minecraft.block.ITileEntityProvider;
  10. import net.minecraft.block.material.MapColor;
  11. import net.minecraft.block.material.Material;
  12. import net.minecraft.block.properties.IProperty;
  13. import net.minecraft.block.properties.PropertyBool;
  14. import net.minecraft.block.properties.PropertyDirection;
  15. import net.minecraft.block.state.BlockStateContainer;
  16. import net.minecraft.block.state.IBlockState;
  17. import net.minecraft.entity.EntityLivingBase;
  18. import net.minecraft.entity.player.EntityPlayer;
  19. import net.minecraft.init.SoundEvents;
  20. import net.minecraft.inventory.InventoryHelper;
  21. import net.minecraft.item.Item;
  22. import net.minecraft.item.ItemStack;
  23. import net.minecraft.tileentity.TileEntity;
  24. import net.minecraft.util.*;
  25. import net.minecraft.util.math.BlockPos;
  26. import net.minecraft.world.IBlockAccess;
  27. import net.minecraft.world.World;
  28. import net.minecraftforge.fml.relauncher.Side;
  29. import net.minecraftforge.fml.relauncher.SideOnly;
  30.  
  31. import javax.annotation.Nullable;
  32. import java.util.Random;
  33.  
  34. /**
  35.  * Created by Blaze on 8/27/2017.
  36.  */
  37. public class DualFurance extends Block implements ITileEntityProvider
  38. {
  39.     public static final PropertyDirection FACING = BlockHorizontal.FACING;
  40.     public static final PropertyBool BURNING = PropertyBool.create("burning");
  41.  
  42.     public DualFurance()
  43.     {
  44.         super(Material.ROCK, MapColor.CYAN);
  45.         setUnlocalizedName("dual_furnace");
  46.         setRegistryName("blockdualfurnace");
  47.         setCreativeTab(Reference.eaCreativeTab);
  48.         this.setHardness(2.8F);
  49.         this.setResistance(3.2F);
  50.         this.setHarvestLevel("pickaxe", 2);
  51.         this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH).withProperty(BURNING, false));
  52.     }
  53.  
  54.     @Override
  55.     public Item getItemDropped(IBlockState state, Random rand, int fortune)
  56.     {
  57.         //return Item.getItemFromBlock(eAngelusBlocks.dual_furnace);
  58.         return Item.getItemFromBlock(this);
  59.     }
  60.  
  61.     @Override
  62.     public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state) {
  63.         this.setDefaultFacing(worldIn, pos, state);
  64.     }
  65.  
  66.     private void setDefaultFacing(World worldIn, BlockPos pos, IBlockState state)
  67.     {
  68.         if(!worldIn.isRemote)
  69.         {
  70.             IBlockState north = worldIn.getBlockState(pos.north());
  71.             IBlockState south = worldIn.getBlockState(pos.south());
  72.             IBlockState west = worldIn.getBlockState(pos.west());
  73.             IBlockState east = worldIn.getBlockState(pos.east());
  74.             EnumFacing face = (EnumFacing)state.getValue(FACING);
  75.  
  76.             if(face == EnumFacing.NORTH && north.isFullBlock() && !south.isFullBlock())
  77.                 face = EnumFacing.SOUTH;
  78.             else if(face == EnumFacing.SOUTH && south.isFullBlock() && !north.isFullBlock())
  79.                 face = EnumFacing.NORTH;
  80.             else if(face == EnumFacing.WEST && west.isFullBlock() && !east.isFullBlock())
  81.                 face = EnumFacing.EAST;
  82.             else if(face == EnumFacing.EAST && east.isFullBlock() && !west.isFullBlock())
  83.                 face = EnumFacing.WEST;
  84.             worldIn.setBlockState(pos, state.withProperty(FACING, face), 2);
  85.         }
  86.     }
  87.  
  88.     @Override
  89.     public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
  90.         if(!worldIn.isRemote)
  91.             playerIn.openGui(Reference.MODID, DualFurnaceGuiHandler.DUAL_FURNACE_GUI, worldIn, pos.getX(), pos.getY(), pos.getZ());
  92.         return true;
  93.     }
  94.  
  95.     public static void setState(boolean active, World worldIn, BlockPos pos)
  96.     {
  97.         IBlockState state = worldIn.getBlockState(pos);
  98.         TileEntity tileEntity = worldIn.getTileEntity(pos);
  99.  
  100.         if(active) {
  101.             worldIn.setBlockState(pos, eAngelusBlocks.dual_furnace.getDefaultState().withProperty(FACING, state.getValue(FACING)).withProperty(BURNING, true), 3);
  102.         } else {
  103.             worldIn.setBlockState(pos, eAngelusBlocks.dual_furnace.getDefaultState().withProperty(FACING, state.getValue(FACING)).withProperty(BURNING, false), 3);
  104.         }
  105.  
  106.         if(tileEntity != null)
  107.         {
  108.             tileEntity.validate();
  109.             worldIn.setTileEntity(pos, tileEntity);
  110.         }
  111.     }
  112.  
  113.     @Nullable
  114.     @Override
  115.     public TileEntity createNewTileEntity(World worldIn, int meta)
  116.     {
  117.         return new TileEntityDualFurnace();
  118.     }
  119.  
  120.     @Override
  121.     public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack)
  122.     {
  123.         worldIn.setBlockState(pos, state.withProperty(FACING, placer.getHorizontalFacing().getOpposite()), 2);
  124.     }
  125.  
  126.     @Override
  127.     public void breakBlock(World worldIn, BlockPos pos, IBlockState state) {
  128.         TileEntityDualFurnace tileEntity = (TileEntityDualFurnace)worldIn.getTileEntity(pos);
  129.         InventoryHelper.dropInventoryItems(worldIn, pos, tileEntity);
  130.         super.breakBlock(worldIn, pos, state);
  131.     }
  132.  
  133.     @Override
  134.     public ItemStack getItem(World worldIn, BlockPos pos, IBlockState state)
  135.     {
  136.         return new ItemStack(eAngelusBlocks.dual_furnace);
  137.     }
  138.  
  139.     @Override
  140.     public EnumBlockRenderType getRenderType(IBlockState state)
  141.     {
  142.         return EnumBlockRenderType.MODEL;
  143.     }
  144.  
  145.     @Override
  146.     public IBlockState getStateFromMeta(int meta)
  147.     {
  148.         boolean blockIsActive = (meta & 7) > 2;
  149.  
  150.         EnumFacing facing = EnumFacing.getFront(meta);
  151.         if(facing.getAxis() == EnumFacing.Axis.Y)
  152.             facing = EnumFacing.NORTH;
  153.  
  154.         return this.getDefaultState().withProperty(FACING, facing).withProperty(BURNING, blockIsActive);
  155.     }
  156.  
  157.     @Override
  158.     public int getMetaFromState(IBlockState state)
  159.     {
  160.         int blockIsActive = (state.getValue(BURNING) ? 1 : 0) << 2;
  161.         int facingDirection = ((EnumFacing)state.getValue(FACING)).getIndex();
  162.         return blockIsActive | facingDirection;
  163.     }
  164.  
  165.     @Override
  166.     public IBlockState withRotation(IBlockState state, Rotation rot)
  167.     {
  168.         return state.withProperty(FACING, rot.rotate((EnumFacing)state.getValue(FACING)));
  169.     }
  170.  
  171.     @Override
  172.     public IBlockState withMirror(IBlockState state, Mirror mirrorIn)
  173.     {
  174.         return state.withRotation(mirrorIn.toRotation((EnumFacing)state.getValue(FACING)));
  175.     }
  176.  
  177.     @Override
  178.     protected BlockStateContainer createBlockState()
  179.     {
  180.         return new BlockStateContainer(this, new IProperty[] {BURNING, FACING});
  181.     }
  182.  
  183.     @Override
  184.     public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos) {
  185.         return super.getActualState(state, worldIn, pos);
  186.     }
  187. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement