Guest User

Untitled

a guest
May 16th, 2015
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.33 KB | None | 0 0
  1. package com.looke81.biowarfare.blocks;
  2.  
  3. import java.util.Random;
  4.  
  5. import net.minecraft.block.Block;
  6. import net.minecraft.block.BlockContainer;
  7. import net.minecraft.block.material.Material;
  8. import net.minecraft.block.properties.IProperty;
  9. import net.minecraft.block.properties.PropertyDirection;
  10. import net.minecraft.block.state.BlockState;
  11. import net.minecraft.block.state.IBlockState;
  12. import net.minecraft.entity.EntityLivingBase;
  13. import net.minecraft.entity.player.EntityPlayer;
  14. import net.minecraft.init.Blocks;
  15. import net.minecraft.item.Item;
  16. import net.minecraft.item.ItemStack;
  17. import net.minecraft.tileentity.TileEntity;
  18. import net.minecraft.tileentity.TileEntityFurnace;
  19. import net.minecraft.util.BlockPos;
  20. import net.minecraft.util.ChatComponentTranslation;
  21. import net.minecraft.util.EnumFacing;
  22. import net.minecraft.util.EnumWorldBlockLayer;
  23. import net.minecraft.util.MathHelper;
  24. import net.minecraft.world.World;
  25. import net.minecraftforge.fml.common.network.internal.FMLNetworkHandler;
  26. import net.minecraftforge.fml.relauncher.Side;
  27. import net.minecraftforge.fml.relauncher.SideOnly;
  28.  
  29. import com.looke81.biowarfare.BioWarfare;
  30. import com.looke81.biowarfare.Reference;
  31. import com.looke81.biowarfare.container.ContainerMicrobeExtractor;
  32. import com.looke81.biowarfare.init.BioWarfareBlocks;
  33. import com.looke81.biowarfare.tileentity.TileEntityMicrobeExtractor;
  34.  
  35. public class MicrobeExtractor extends BlockContainer {
  36.  
  37. public static final PropertyDirection FACING = PropertyDirection.create("facing", EnumFacing.Plane.HORIZONTAL);
  38. private final boolean isActive;
  39. private static boolean keepInventory;
  40. public MicrobeExtractor(boolean isActive) {
  41. super(Material.iron);
  42. this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH));
  43. this.isActive = isActive;
  44.  
  45. this.setHardness(5.0F);
  46.  
  47. }
  48. public static void setState(World worldIn, BlockPos pos, Block setter)
  49. {
  50. IBlockState iblockstate = worldIn.getBlockState(pos);
  51. TileEntity tileentity = worldIn.getTileEntity(pos);
  52. keepInventory = true;
  53.  
  54. worldIn.setBlockState(pos, setter.getDefaultState().withProperty(MicrobeExtractor.FACING, iblockstate.getValue(MicrobeExtractor.FACING)), 3);
  55. worldIn.setBlockState(pos, setter.getDefaultState().withProperty(MicrobeExtractor.FACING, iblockstate.getValue(MicrobeExtractor.FACING)), 3);
  56.  
  57. keepInventory = false;
  58.  
  59. if (tileentity != null)
  60. {
  61. tileentity.validate();
  62. worldIn.setTileEntity(pos, tileentity);
  63. }
  64. worldIn.markBlockForUpdate(pos);
  65. }
  66.  
  67. @Override
  68. @SideOnly(Side.CLIENT)
  69. public IBlockState getStateForEntityRender(IBlockState state) {
  70. return this.getDefaultState().withProperty(FACING, EnumFacing.SOUTH);
  71. }
  72.  
  73. @Override
  74. public IBlockState getStateFromMeta(int meta) {
  75. EnumFacing enumFacing = EnumFacing.getFront(meta);
  76.  
  77. if (enumFacing.getAxis() == EnumFacing.Axis.Y) {
  78. enumFacing = EnumFacing.NORTH;
  79. }
  80.  
  81. return this.getDefaultState().withProperty(FACING, enumFacing);
  82. }
  83.  
  84. @Override
  85. public int getMetaFromState(IBlockState state) {
  86. return ((EnumFacing) state.getValue(FACING)).getIndex();
  87. }
  88.  
  89. @Override
  90. protected BlockState createBlockState() {
  91. return new BlockState(this, new IProperty[] { FACING });
  92. }
  93.  
  94. @Override
  95. public IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) {
  96.  
  97. return this.getDefaultState().withProperty(FACING, placer.getHorizontalFacing().getOpposite());
  98. }
  99.  
  100.  
  101. public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumFacing side, float hitX, float hitY, float hitZ) {
  102. if (!world.isRemote) {
  103. FMLNetworkHandler.openGui(player, BioWarfare.instance, 0, world, pos.getX(), pos.getY(), pos.getZ());
  104.  
  105. }
  106. return true;
  107. }
  108.  
  109. public int getRenderType() {
  110. return 3;
  111. }
  112.  
  113. public Item getItemDropped(int i, Random random, int j) {
  114. return Item.getItemFromBlock(BioWarfareBlocks.block_MicrobeExtractorIdle);
  115. }
  116.  
  117. public Item getItem(World world, int x, int y, int z) {
  118. return Item.getItemFromBlock(BioWarfareBlocks.block_MicrobeExtractorIdle);
  119. }
  120.  
  121. @Override
  122. public TileEntity createNewTileEntity(World worldIn, int meta) {
  123. return new TileEntityMicrobeExtractor();
  124. }
Advertisement
Add Comment
Please, Sign In to add comment