Advertisement
HalestormXV

Untitled

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