Guest User

Untitled

a guest
Jun 16th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.29 KB | None | 0 0
  1. package me.ferdz.placeableitems.block;
  2.  
  3. import me.ferdz.placeableitems.block.state.EnumArrowType;
  4. import me.ferdz.placeableitems.tileentity.TEArrow;
  5. import net.minecraft.block.ITileEntityProvider;
  6. import net.minecraft.block.material.Material;
  7. import net.minecraft.block.properties.IProperty;
  8. import net.minecraft.block.properties.PropertyEnum;
  9. import net.minecraft.block.state.BlockStateContainer;
  10. import net.minecraft.block.state.IBlockState;
  11. import net.minecraft.entity.EntityLivingBase;
  12. import net.minecraft.init.Items;
  13. import net.minecraft.item.ItemStack;
  14. import net.minecraft.tileentity.TileEntity;
  15. import net.minecraft.util.math.BlockPos;
  16. import net.minecraft.world.IBlockAccess;
  17. import net.minecraft.world.World;
  18.  
  19. public class BlockArrow extends BlockPlaceableItems implements ITileEntityProvider {
  20.  
  21.     public static final PropertyEnum<EnumArrowType> TYPE = PropertyEnum.create("type", EnumArrowType.class);
  22.    
  23.     public BlockArrow(String name) {
  24.         super(Material.WOOD, name);
  25.        
  26.         this.isBlockContainer = true;
  27.     }
  28.  
  29.     @Override
  30.     public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) {
  31.         TileEntity te = worldIn.getTileEntity(pos);
  32.         if(te instanceof TEArrow) {
  33.             ItemStack is = stack.copy();
  34.             is.stackSize = 1;
  35.             ((TEArrow)te).setType(is);
  36.         }
  37.         worldIn.getTileEntity(pos).markDirty();
  38.     }
  39.  
  40.     @Override
  41.     public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos) {
  42.         TEArrow te = (TEArrow)worldIn.getTileEntity(pos);
  43.         if(te.getType().getItem().equals(Items.ARROW)) {
  44.             return state.withProperty(TYPE, EnumArrowType.NORMAL);
  45.         } else if (te.getType().getItem().equals(Items.TIPPED_ARROW)) {
  46.             String type = te.getType().getTagCompound().getString("Potion").substring(10).toUpperCase();
  47.             EnumArrowType arrowType = null;
  48.             if(type.contains("FIRE_RESISTANCE"))
  49.                 arrowType = EnumArrowType.FIRE_RESISTANCE;
  50.             else if (type.contains("HEALING"))
  51.                 arrowType = EnumArrowType.HEALING;
  52.             else if (type.contains("INVISIBILITY"))
  53.                 arrowType = EnumArrowType.INVISIBILITY;
  54.             else if (type.contains("LEAPING"))
  55.                 arrowType = EnumArrowType.LEAPING;
  56.             else if (type.contains("NIGHT_VISION"))
  57.                 arrowType = EnumArrowType.NIGHT_VISION;
  58.             else if (type.contains("POISON"))
  59.                 arrowType = EnumArrowType.POISON;
  60.             else if (type.contains("REGENERATION"))
  61.                 arrowType = EnumArrowType.REGENERATION;
  62.             else if (type.contains("SLOWNESS"))
  63.                 arrowType = EnumArrowType.SLOWNESS;
  64.             else if (type.contains("STRENGTH"))
  65.                 arrowType = EnumArrowType.STRENGTH;
  66.             else if (type.contains("SWIFTNESS"))
  67.                 arrowType = EnumArrowType.SWIFTNESS;
  68.             else if (type.contains("WATER_BREATHING"))
  69.                 arrowType = EnumArrowType.WATER_BREATHING;
  70.             else if (type.contains("WEAKNESS"))
  71.                 arrowType = EnumArrowType.WEAKNESS;
  72.             return state.withProperty(TYPE, arrowType);
  73.         } else if (te.getType().getItem().equals(Items.SPECTRAL_ARROW)) {
  74.             return state.withProperty(TYPE, EnumArrowType.SPECTRAL);
  75.         } else {
  76.             return state;
  77.         }
  78.     }
  79.    
  80.     @Override
  81.     protected BlockStateContainer createBlockState() {
  82.         return new BlockStateContainer(this, new IProperty[]{ TYPE, FACING });
  83.     }
  84.    
  85.     @Override
  86.     public TileEntity createNewTileEntity(World worldIn, int meta) {
  87.         return new TEArrow();
  88.     }
  89. }
Add Comment
Please, Sign In to add comment