Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.mightydanp.eot.block;
- import java.util.List;
- import java.util.Random;
- import com.mightydanp.eot.Eot;
- import com.mightydanp.eot.block.BlockDefaultOre.EnumType;
- import com.mightydanp.eot.item.ItemEssenceOre;
- import com.mightydanp.eot.item.ModItems;
- import com.mightydanp.eot.lib.BlockStrings;
- import com.mightydanp.eot.lib.References;
- import net.minecraftforge.fml.common.registry.GameRegistry;
- import net.minecraftforge.fml.relauncher.Side;
- import net.minecraftforge.fml.relauncher.SideOnly;
- import net.minecraft.block.Block;
- import net.minecraft.block.material.Material;
- import net.minecraft.block.properties.IProperty;
- import net.minecraft.block.properties.PropertyEnum;
- import net.minecraft.block.state.BlockStateContainer;
- import net.minecraft.block.state.IBlockState;
- import net.minecraft.client.Minecraft;
- import net.minecraft.creativetab.CreativeTabs;
- import net.minecraft.entity.item.EntityItem;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.init.Blocks;
- import net.minecraft.item.Item;
- import net.minecraft.item.ItemStack;
- import net.minecraft.tileentity.TileEntity;
- import net.minecraft.util.EnumHand;
- import net.minecraft.util.IStringSerializable;
- import net.minecraft.util.math.BlockPos;
- import net.minecraft.util.math.RayTraceResult;
- import net.minecraft.world.IBlockAccess;
- import net.minecraft.world.World;
- public class BlockEssenceOre extends Block implements IMetaBlockName{
- public static final PropertyEnum TYPE = PropertyEnum.create("essenceOre", BlockEssenceOre.EnumType.class);
- public float originalHardness;
- protected BlockEssenceOre(String unlocalizedName) {
- super(Material.ROCK);
- this.setCreativeTab(Eot.eotTab);
- this.setUnlocalizedName(unlocalizedName);
- this.setDefaultState(this.blockState.getBaseState().withProperty(TYPE, EnumType.ESSENCEOREMAGIC));
- }
- @Override
- public Block setHardness(float par1){
- originalHardness = par1;
- return super.setHardness(par1);
- }
- @Override
- protected BlockStateContainer createBlockState() {
- return new BlockStateContainer(this, new IProperty[] { TYPE });
- }
- @Override
- public IBlockState getStateFromMeta(int meta) {
- return getDefaultState().withProperty(TYPE, EnumType.values()[meta]);
- }
- @Override
- public int getMetaFromState(IBlockState state) {
- return ((Enum<EnumType>) state.getValue(TYPE)).ordinal();
- }
- @Override
- public int damageDropped(IBlockState state) {
- return getMetaFromState(state);
- }
- @SuppressWarnings({ "unchecked", "rawtypes" })
- @Override
- public void getSubBlocks(Item itemIn, CreativeTabs tab, List list) {
- for (EnumType t : EnumType.values())
- list.add(new ItemStack(itemIn, 1, t.ordinal()));
- }
- @Override
- public String getSpecialName(ItemStack stack) {
- return EnumType.values()[stack.getItemDamage()].name().toLowerCase();
- }
- public Item getItemDropped(IBlockState state, Random rand, int fortune){
- int randomDrop = rand.nextInt(100);
- if(randomDrop<=60){
- return ModItems.essenceChunks;
- }
- return null;
- }
- public int quantityDroppedWithBonus(int fortune, Random random){
- if (fortune > 0)
- {
- int j = random.nextInt(fortune + 2) - 1;
- if (j < 0)
- {
- return j++;
- }
- return quantityDropped(random) * (j + 1);
- }
- return quantityDropped(random);
- }
- @Override
- public void onBlockHarvested(World worldIn, BlockPos pos, IBlockState state, EntityPlayer player) {
- if(player.getHeldItem(EnumHand.MAIN_HAND) != null){;
- EntityItem entityItem = new EntityItem(worldIn, player.posX , player.posY , player.posZ, new ItemStack(ModItems.magicalStone, 1, 16));
- Random random = worldIn.rand;
- int randomDrop = random.nextInt(99);
- if(player.getHeldItem(EnumHand.MAIN_HAND).getItem() == ModItems.hammerMysterious){
- if(randomDrop<=10){
- worldIn.spawnEntityInWorld(entityItem);
- }
- }
- }
- }
- @Override
- public void onBlockClicked(World worldIn, BlockPos pos, EntityPlayer playerIn){
- if(!(playerIn.getHeldItem(EnumHand.MAIN_HAND).getItem() == ModItems.hammerMysterious)){
- this.blockHardness = -1;
- return;
- }
- this.blockHardness = originalHardness;
- super.onBlockClicked(worldIn, pos, playerIn);
- }
- @Override
- public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World world, BlockPos pos, EntityPlayer player){
- return new ItemStack(Item.getItemFromBlock(this), 1, this.getMetaFromState(world.getBlockState(pos)));
- }
- public enum EnumType implements IStringSerializable {
- ESSENCEOREMAGIC(0, "essenceOreMagic"),
- ESSENCEOREAIR(1, "essenceOreAir"),
- ESSENCEOREEARTH(2, "essenceOreEarth"),
- ESSENCEOREFIRE(3, "essenceOreFire"),
- ESSENCEOREWATER(4, "essenceOreWater"),;
- private int ID;
- private String name;
- private EnumType(int ID, String name) {
- this.ID = ID;
- this.name = name;
- }
- @Override
- public String getName() {
- return this.name;
- }
- public int getID() {
- return this.ID;
- }
- @Override
- public String toString() {
- return this.getName();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment