Creepinson

Untitled

May 18th, 2017
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.97 KB | None | 0 0
  1.  
  2. package me.creepinson.blocks.pedestal;
  3.  
  4. import me.creepinson.blocks.base.ModBlocks;
  5. import me.creepinson.entities.tileentity.TESRPedastal_Magic;
  6. import me.creepinson.entities.tileentity.TileEntityPedastal_Magic;
  7. import me.creepinson.handlers.ItemHandler;
  8. import net.minecraft.block.ITileEntityProvider;
  9. import net.minecraft.block.material.Material;
  10. import net.minecraft.block.state.IBlockState;
  11. import net.minecraft.client.renderer.block.model.ModelResourceLocation;
  12. import net.minecraft.creativetab.CreativeTabs;
  13. import net.minecraft.entity.item.EntityItem;
  14. import net.minecraft.entity.player.EntityPlayer;
  15. import net.minecraft.init.Items;
  16. import net.minecraft.item.Item;
  17. import net.minecraft.item.ItemStack;
  18. import net.minecraft.nbt.NBTTagCompound;
  19. import net.minecraft.potion.Potion;
  20. import net.minecraft.potion.PotionEffect;
  21. import net.minecraft.tileentity.TileEntity;
  22. import net.minecraft.util.EnumFacing;
  23. import net.minecraft.util.EnumHand;
  24. import net.minecraft.util.math.BlockPos;
  25. import net.minecraft.util.text.TextComponentTranslation;
  26. import net.minecraft.util.text.TextFormatting;
  27. import net.minecraft.world.IBlockAccess;
  28. import net.minecraft.world.World;
  29. import net.minecraftforge.client.model.ModelLoader;
  30. import net.minecraftforge.fml.client.registry.ClientRegistry;
  31. import net.minecraftforge.fml.relauncher.Side;
  32. import net.minecraftforge.fml.relauncher.SideOnly;
  33.  
  34. public class Pedastal_Magic extends ModBlocks implements ITileEntityProvider{
  35. public Pedastal_Magic(Material mat, String name, CreativeTabs tab, float hardness, float resistance, int harvest, String tool) {
  36. super(mat, name, tab, hardness, resistance, harvest, tool);
  37. }
  38.  
  39. @Override
  40. public TileEntity createNewTileEntity(World worldIn, int meta) {
  41.  
  42. return new TileEntityPedastal_Magic();
  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. TileEntityPedastal_Magic teCv = (TileEntityPedastal_Magic)te;
  51. if(te instanceof TileEntityPedastal_Magic){
  52. EntityItem itemDropped = new EntityItem(world, pos.getX(), pos.getY() + 1, pos.getZ());
  53. itemDropped.setEntityItemStack(((TileEntityPedastal_Magic) te).getStack());
  54. world.spawnEntity(itemDropped);
  55. ((TileEntityPedastal_Magic) te).getStack().setCount(0);
  56. super.harvestBlock(world, player, pos, state, te, stack);
  57. }
  58. }
  59. }
  60.  
  61.  
  62.  
  63. @SideOnly(Side.CLIENT)
  64. public void initModel() {
  65. ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(this), 0, new ModelResourceLocation(getRegistryName(), "inventory"));
  66. // Bind our TESR to our tile entity
  67. ClientRegistry.bindTileEntitySpecialRenderer(TileEntityPedastal_Magic.class, new TESRPedastal_Magic());
  68. }
  69.  
  70.  
  71.  
  72. @Override
  73. @SideOnly(Side.CLIENT)
  74. public boolean shouldSideBeRendered(IBlockState blockState, IBlockAccess worldIn, BlockPos pos, EnumFacing side) {
  75. return false;
  76. }
  77.  
  78. @Override
  79. public boolean isBlockNormalCube(IBlockState blockState) {
  80. return false;
  81. }
  82.  
  83. @Override
  84. public boolean isOpaqueCube(IBlockState blockState) {
  85. return false;
  86. }
  87.  
  88. private TileEntityPedastal_Magic getTE(World world, BlockPos pos) {
  89. return (TileEntityPedastal_Magic) world.getTileEntity(pos);
  90. }
  91. @Override
  92. public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
  93. if (world.isRemote) {
  94.  
  95.  
  96.  
  97. TileEntityPedastal_Magic te = getTE(world, pos);
  98.  
  99.  
  100.  
  101. if(ItemStack.areItemStacksEqual(player.getHeldItem(hand), new ItemStack(ItemHandler.key, player.getHeldItem(hand).getCount(), 0))){
  102. if(!te.isLockable()){
  103. player.sendMessage(new TextComponentTranslation(TextFormatting.AQUA + "[EssencePlus] Block Update>" + TextFormatting.DARK_RED + "This pedestal does not have a locking upgrade applied, therefore you cannot lock it!"));
  104. }
  105. else{
  106. if(!te.isLocked()){
  107. te.setLocked(true);
  108. player.sendMessage(new TextComponentTranslation(TextFormatting.AQUA + "[EssencePlus] Security> " + TextFormatting.DARK_RED + "This pedestal has been locked!"));
  109. }
  110. else {
  111. player.sendMessage(new TextComponentTranslation(TextFormatting.AQUA + "[EssencePlus] Security> " + TextFormatting.DARK_GREEN + "This pedestal has been unlocked!"));
  112. te.setLocked(false);
  113. }
  114. }
  115. }
  116. else if (ItemStack.areItemStacksEqual(player.getHeldItem(hand), new ItemStack(ItemHandler.upgrade, player.getHeldItem(hand).getCount(), 0))){
  117.  
  118.  
  119. if(!te.isLockable()){
  120. player.sendMessage(new TextComponentTranslation(TextFormatting.AQUA + "[EssencePlus] Block Update>" + TextFormatting.DARK_GREEN + "A locking upgrade has just been applied to this pedestal!"));
  121. te.setLockable(true);
  122. }
  123. else {
  124. player.sendMessage(new TextComponentTranslation(TextFormatting.AQUA + "[EssencePlus] Block Update>" + TextFormatting.DARK_RED + "This pedestal already has a locking upgrade applied!"));
  125. }
  126.  
  127. }
  128. else{
  129.  
  130.  
  131. if (te.getStack().isEmpty()) {
  132. if(te.isLocked()){
  133.  
  134. player.sendMessage(new TextComponentTranslation(TextFormatting.AQUA + "[EssencePlus] " + TextFormatting.RED + "This pedestal is locked!"));
  135.  
  136.  
  137. }
  138.  
  139. else{
  140. if (!player.getHeldItem(hand).isEmpty()) {
  141. // There is no item in the pedestal and the player is holding an item. We move that item
  142. // to the pedestal
  143. te.setStack(player.getHeldItem(hand));
  144. player.inventory.setInventorySlotContents(player.inventory.currentItem, ItemStack.EMPTY);
  145. // Make sure the client knows about the changes in the player inventory
  146.  
  147. }
  148. }
  149. } else if (!te.getStack().isEmpty()){
  150. if(te.isLocked()){
  151.  
  152. player.sendMessage(new TextComponentTranslation(TextFormatting.AQUA + "[EssencePlus] " + TextFormatting.RED + "This pedestal is locked!"));
  153.  
  154.  
  155. }
  156. else{
  157. // There is a stack in the pedestal. In this case we remove it and try to put it in the
  158. // players inventory if there is room
  159. ItemStack stack = te.getStack();
  160.  
  161. if (!player.inventory.addItemStackToInventory(stack)) {
  162. // Not possible. Throw item in the world
  163. EntityItem entityItem = new EntityItem(world, pos.getX(), pos.getY()+1, pos.getZ(), stack);
  164. world.spawnEntity(entityItem);
  165. }
  166. te.setStack(ItemStack.EMPTY);
  167. }
  168. }
  169. }
  170. }
  171.  
  172. // Return true also on the client to make sure that MC knows we handled this and will not try to place
  173. // a block on the client
  174. return true;
  175. }
  176.  
  177. }
Advertisement
Add Comment
Please, Sign In to add comment