Advertisement
Creepinson

Untitled

Mar 27th, 2017
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.65 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 {
  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. this.isBlockContainer = true;
  32. }
  33. @Override
  34. public boolean hasTileEntity() {
  35.  
  36. return true;
  37. }
  38. @Override
  39. public TileEntity createTileEntity(World world, IBlockState state) {
  40.  
  41. return new TileEntityPedastal_Magic();
  42. }
  43.  
  44. @Override
  45. public void harvestBlock(World world, EntityPlayer player, BlockPos pos, IBlockState state, TileEntity te,
  46. ItemStack stack) {
  47.  
  48. if(!world.isRemote){
  49.  
  50. TileEntity te2 = world.getTileEntity(pos);
  51. EntityItem itemDropped = new EntityItem(world, pos.getX(), pos.getY() + 1, pos.getZ(), stack);
  52. world.spawnEntity(itemDropped);
  53. stack.setCount(0);
  54. super.harvestBlock(world, player, pos, state, te, stack);
  55.  
  56. }
  57. }
  58.  
  59.  
  60.  
  61. @SideOnly(Side.CLIENT)
  62. public void initModel() {
  63. ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(this), 0, new ModelResourceLocation(getRegistryName(), "inventory"));
  64. // Bind our TESR to our tile entity
  65. ClientRegistry.bindTileEntitySpecialRenderer(TileEntityPedastal_Magic.class, new TESRPedastal_Magic());
  66. }
  67.  
  68.  
  69.  
  70. @Override
  71. @SideOnly(Side.CLIENT)
  72. public boolean shouldSideBeRendered(IBlockState blockState, IBlockAccess worldIn, BlockPos pos, EnumFacing side) {
  73. return false;
  74. }
  75.  
  76. @Override
  77. public boolean isBlockNormalCube(IBlockState blockState) {
  78. return false;
  79. }
  80.  
  81. @Override
  82. public boolean isOpaqueCube(IBlockState blockState) {
  83. return false;
  84. }
  85.  
  86. private TileEntityPedastal_Magic getTE(World world, BlockPos pos) {
  87. return (TileEntityPedastal_Magic) world.getTileEntity(pos);
  88. }
  89. @Override
  90. public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player,
  91.  
  92.  
  93.  
  94. EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
  95. if (!world.isRemote) {
  96. TileEntityPedastal_Magic te = getTE(world, pos);
  97. if (te.getStack().isEmpty()) {
  98. if (!player.getHeldItem(hand).isEmpty()) {
  99. // There is no item in the pedestal and the player is holding an item. We move that item
  100. // to the pedestal
  101. te.setStack(player.getHeldItem(hand));
  102. player.inventory.setInventorySlotContents(player.inventory.currentItem, te.getStack());
  103. // Make sure the client knows about the changes in the player inventory
  104. player.openContainer.detectAndSendChanges();
  105. }
  106.  
  107. } else {
  108. // There is a stack in the pedestal. In this case we remove it and try to put it in the
  109. // players inventory if there is room
  110. ItemStack stack = te.getStack();
  111. te.setStack(ItemStack.EMPTY);
  112. if (!player.inventory.addItemStackToInventory(stack)) {
  113. // Not possible. Throw item in the world
  114. EntityItem entityItem = new EntityItem(world, pos.getX(), pos.getY()+1, pos.getZ(), stack);
  115. world.spawnEntity(entityItem);
  116. } else {
  117. player.openContainer.detectAndSendChanges();
  118. }
  119. }
  120. }
  121.  
  122. // Return true also on the client to make sure that MC knows we handled this and will not try to place
  123. // a block on the client
  124. return true;
  125. }
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement