Advertisement
Guest User

Untitled

a guest
May 28th, 2016
67
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package tiffit.talecraft.blocks.world;
  2.  
  3. import org.apache.logging.log4j.LogManager;
  4. import org.apache.logging.log4j.Logger;
  5.  
  6. import de.longor.talecraft.TaleCraft;
  7. import de.longor.talecraft.TaleCraftItems;
  8. import de.longor.talecraft.TaleCraftTabs;
  9. import de.longor.talecraft.blocks.TCBlock;
  10. import net.minecraft.block.BlockAnvil;
  11. import net.minecraft.block.BlockFlower;
  12. import net.minecraft.block.BlockGlass;
  13. import net.minecraft.block.BlockGrass;
  14. import net.minecraft.block.ITileEntityProvider;
  15. import net.minecraft.block.properties.IProperty;
  16. import net.minecraft.block.properties.PropertyBool;
  17. import net.minecraft.block.properties.PropertyDirection;
  18. import net.minecraft.block.properties.PropertyEnum;
  19. import net.minecraft.block.state.BlockStateContainer;
  20. import net.minecraft.block.state.IBlockState;
  21. import net.minecraft.entity.EntityLivingBase;
  22. import net.minecraft.entity.player.EntityPlayer;
  23. import net.minecraft.init.SoundEvents;
  24. import net.minecraft.item.ItemStack;
  25. import net.minecraft.tileentity.TileEntity;
  26. import net.minecraft.util.EnumFacing;
  27. import net.minecraft.util.EnumHand;
  28. import net.minecraft.util.IStringSerializable;
  29. import net.minecraft.util.SoundCategory;
  30. import net.minecraft.util.math.AxisAlignedBB;
  31. import net.minecraft.util.math.BlockPos;
  32. import net.minecraft.util.text.TextComponentString;
  33. import net.minecraft.util.text.TextComponentTranslation;
  34. import net.minecraft.util.text.TextFormatting;
  35. import net.minecraft.world.World;
  36. import net.minecraftforge.fml.common.FMLCommonHandler;
  37. import tiffit.talecraft.items.world.KeyItem;
  38. import tiffit.talecraft.packet.DoorPacket;
  39. import tiffit.talecraft.tileentity.LockedDoorTileEntity;
  40. import tiffit.talecraft.tileentity.LockedDoorTileEntity.DoorCorner;
  41.  
  42. public class SpikeBlock extends TCBlock{
  43.  
  44. public static final PropertyDirection FACING = PropertyDirection.create("facing");
  45. public static final PropertyBool ACTIVE = PropertyBool.create("active");
  46. private static final Logger LOGGER = LogManager.getLogger();
  47.  
  48. public SpikeBlock(){
  49. super();
  50. this.setCreativeTab(TaleCraftTabs.tab_TaleCraftWorldTab);
  51. this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.UP).withProperty(ACTIVE, false));
  52. }
  53.  
  54. public IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer){
  55. EnumFacing enumfacing = placer.getHorizontalFacing();
  56. if(hitY == 0f) enumfacing = EnumFacing.UP;
  57. else if(hitY == 1f) enumfacing = EnumFacing.DOWN;
  58. try{
  59. return super.onBlockPlaced(worldIn, pos, facing, hitX, hitY, hitZ, meta, placer).withProperty(FACING, enumfacing).withProperty(ACTIVE, false);
  60. }
  61. catch (IllegalArgumentException var11){
  62. if (!worldIn.isRemote){
  63. LOGGER.warn(String.format("Invalid spike block data @ " + pos.toString() + " in " + worldIn.provider.getDimension()));
  64.  
  65. if (placer instanceof EntityPlayer){
  66. ((EntityPlayer)placer).addChatMessage(new TextComponentString("Invalid spike block data!"));
  67. }
  68. }
  69.  
  70. return super.onBlockPlaced(worldIn, pos, facing, hitX, hitY, hitZ, 0, placer).withProperty(FACING, EnumFacing.UP).withProperty(ACTIVE, false);
  71. }
  72. }
  73.  
  74. @Override
  75. protected BlockStateContainer createBlockState() {
  76. return new BlockStateContainer(this, new IProperty[] { ACTIVE, FACING });
  77. }
  78.  
  79. @Override
  80. public IBlockState getStateFromMeta(int meta) {
  81. int altmeta = meta;
  82. BlockAnvil e;
  83. if(meta > 6) altmeta =- 6;
  84. EnumFacing direction = EnumFacing.values()[altmeta];
  85. boolean active = meta < 6;
  86. return getDefaultState().withProperty(FACING, direction).withProperty(ACTIVE, active);
  87. }
  88.  
  89. @Override
  90. public int getMetaFromState(IBlockState state) {
  91. EnumFacing facing = state.getValue(FACING);
  92. int meta = facing.ordinal();
  93. if(state.getValue(ACTIVE)) meta *=2;
  94.  
  95. return meta;
  96. }
  97.  
  98. @Override
  99. public int damageDropped(IBlockState state) {
  100. return getMetaFromState(state);
  101. }
  102.  
  103. @Override
  104. public boolean isOpaqueCube(IBlockState state){
  105. return false;
  106. }
  107.  
  108. @Override
  109. public boolean isFullCube(IBlockState state){
  110. return false;
  111. }
  112. }
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement