Advertisement
Creepinson

Untitled

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