Camellias_

Untitled

Jun 10th, 2018
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.88 KB | None | 0 0
  1. package com.camellias.voidaicarcania.enchants;
  2.  
  3. import com.camellias.voidaicarcania.Reference;
  4. import com.camellias.voidaicarcania.init.ModEnchants;
  5.  
  6. import net.minecraft.block.Block;
  7. import net.minecraft.block.state.IBlockState;
  8. import net.minecraft.enchantment.Enchantment;
  9. import net.minecraft.enchantment.EnchantmentHelper;
  10. import net.minecraft.enchantment.EnumEnchantmentType;
  11. import net.minecraft.init.Blocks;
  12. import net.minecraft.init.Items;
  13. import net.minecraft.inventory.EntityEquipmentSlot;
  14. import net.minecraft.item.ItemStack;
  15. import net.minecraft.util.math.BlockPos;
  16. import net.minecraft.world.World;
  17. import net.minecraftforge.event.world.BlockEvent.BreakEvent;
  18. import net.minecraftforge.event.world.BlockEvent.HarvestDropsEvent;
  19. import net.minecraftforge.fml.common.Mod;
  20. import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
  21.  
  22. @Mod.EventBusSubscriber(modid = Reference.MODID)
  23. public class EnchantAlchemy extends Enchantment
  24. {
  25.     public EnchantAlchemy(String name, Rarity rarity, EnumEnchantmentType type, EntityEquipmentSlot[] slots)
  26.     {
  27.         super(rarity, type, slots);
  28.         this.setName(name);
  29.         this.setRegistryName(name);
  30.     }
  31.    
  32.     @Override
  33.     public boolean canApplyAtEnchantingTable(ItemStack stack)
  34.     {
  35.         return false;
  36.     }
  37.    
  38.     @Override
  39.     public int getMaxLevel()
  40.     {
  41.         return 1;
  42.     }
  43.    
  44.     @SubscribeEvent
  45.     public static void onMinedDrop(HarvestDropsEvent event)
  46.     {
  47.         int level = EnchantmentHelper.getMaxEnchantmentLevel(ModEnchants.ALCHEMY, event.getHarvester());
  48.        
  49.         if(!event.getHarvester().world.isRemote)
  50.         {
  51.             if(level > 0)
  52.             {
  53.                 World world = event.getHarvester().world;
  54.                 BlockPos pos = event.getHarvester().getPosition();
  55.                 IBlockState state = world.getBlockState(pos);
  56.                
  57.                 if(state.getBlock() == Blocks.IRON_ORE)
  58.                 {
  59.                     event.getDrops().add(new ItemStack(Blocks.GOLD_ORE));
  60.                     event.getDrops().clear();
  61.                 }
  62.             }
  63.         }
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment