Advertisement
Creepinson

2

May 12th, 2017
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.58 KB | None | 0 0
  1. package me.creepinson.blocks;
  2.  
  3. import me.creepinson.entities.tileentity.TESRPedastal_Magic;
  4. import me.creepinson.entities.tileentity.TileEntityPedastal_Magic;
  5. import net.minecraft.block.ITileEntityProvider;
  6. import net.minecraft.block.material.Material;
  7. import net.minecraft.block.state.IBlockState;
  8. import net.minecraft.client.renderer.block.model.ModelResourceLocation;
  9. import net.minecraft.creativetab.CreativeTabs;
  10. import net.minecraft.entity.item.EntityItem;
  11. import net.minecraft.entity.player.EntityPlayer;
  12. import net.minecraft.item.Item;
  13. import net.minecraft.item.ItemStack;
  14. import net.minecraft.potion.Potion;
  15. import net.minecraft.potion.PotionEffect;
  16. import net.minecraft.tileentity.TileEntity;
  17. import net.minecraft.util.EnumFacing;
  18. import net.minecraft.util.EnumHand;
  19. import net.minecraft.util.math.BlockPos;
  20. import net.minecraft.world.IBlockAccess;
  21. import net.minecraft.world.World;
  22. import net.minecraftforge.client.model.ModelLoader;
  23. import net.minecraftforge.fml.client.registry.ClientRegistry;
  24. import net.minecraftforge.fml.relauncher.Side;
  25. import net.minecraftforge.fml.relauncher.SideOnly;
  26.  
  27. public class Pedastal_Magic extends ModBlocks implements ITileEntityProvider {
  28.  
  29. public Pedastal_Magic(Material mat, String name, CreativeTabs tab, float hardness, float resistance, int harvest, String tool) {
  30. super(mat, name, tab, hardness, resistance, harvest, tool);
  31. }
  32.  
  33. @Override
  34. public TileEntity createNewTileEntity(World worldIn, int meta) {
  35.  
  36. return new TileEntityPedastal_Magic();
  37. }
  38. @Override
  39. public void harvestBlock(World world, EntityPlayer player, BlockPos pos, IBlockState state, TileEntity te,
  40. ItemStack stack) {
  41.  
  42. if(!world.isRemote){
  43.  
  44. TileEntity te2 = world.getTileEntity(pos);
  45. EntityItem itemDropped = new EntityItem(world, pos.getX(), pos.getY() + 1, pos.getZ(), stack);
  46. world.spawnEntity(itemDropped);
  47. stack.setCount(0);
  48. super.harvestBlock(world, player, pos, state, te, stack);
  49.  
  50. }
  51. }
  52.  
  53.  
  54.  
  55. @SideOnly(Side.CLIENT)
  56. public void initModel() {
  57. ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(this), 0, new ModelResourceLocation(getRegistryName(), "inventory"));
  58. // Bind our TESR to our tile entity
  59. ClientRegistry.bindTileEntitySpecialRenderer(TileEntityPedastal_Magic.class, new TESRPedastal_Magic());
  60. }
  61.  
  62.  
  63.  
  64. @Override
  65. @SideOnly(Side.CLIENT)
  66. public boolean shouldSideBeRendered(IBlockState blockState, IBlockAccess worldIn, BlockPos pos, EnumFacing side) {
  67. return false;
  68. }
  69.  
  70. @Override
  71. public boolean isBlockNormalCube(IBlockState blockState) {
  72. return false;
  73. }
  74.  
  75. @Override
  76. public boolean isOpaqueCube(IBlockState blockState) {
  77. return false;
  78. }
  79.  
  80. private TileEntityPedastal_Magic getTE(World world, BlockPos pos) {
  81. return (TileEntityPedastal_Magic) world.getTileEntity(pos);
  82. }
  83. @Override
  84. public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player,
  85.  
  86.  
  87.  
  88. EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
  89. if (!world.isRemote) {
  90. TileEntityPedastal_Magic te = getTE(world, pos);
  91. if (te.getStack() == null) {
  92. if (player.getHeldItem(hand) != ItemStack.EMPTY) {
  93. // There is no item in the pedestal and the player is holding an item. We move that item
  94. // to the pedestal
  95. te.setStack(player.getHeldItem(hand));
  96. player.inventory.setInventorySlotContents(player.inventory.currentItem, te.getStack());
  97. // Make sure the client knows about the changes in the player inventory
  98. player.openContainer.detectAndSendChanges();
  99. }
  100.  
  101. } else {
  102. // There is a stack in the pedestal. In this case we remove it and try to put it in the
  103. // players inventory if there is room
  104. ItemStack stack = te.getStack();
  105. te.setStack(ItemStack.EMPTY);
  106. if (!player.inventory.addItemStackToInventory(stack)) {
  107. // Not possible. Throw item in the world
  108. EntityItem entityItem = new EntityItem(world, pos.getX(), pos.getY()+1, pos.getZ(), stack);
  109. world.spawnEntity(entityItem);
  110. } else {
  111. player.openContainer.detectAndSendChanges();
  112. }
  113. }
  114. }
  115.  
  116. // Return true also on the client to make sure that MC knows we handled this and will not try to place
  117. // a block on the client
  118. return true;
  119. }
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement