Advertisement
HalestormXV

Untitled

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