Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package sometimesHardcoreSometimes;
- import java.util.ArrayList;
- import java.util.Random;
- import cpw.mods.fml.relauncher.Side;
- import cpw.mods.fml.relauncher.SideOnly;
- import net.minecraft.block.Block;
- import net.minecraft.block.BlockContainer;
- import net.minecraft.block.material.Material;
- import net.minecraft.client.renderer.texture.IconRegister;
- import net.minecraft.entity.EntityLivingBase;
- import net.minecraft.entity.item.EntityItem;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.item.Item;
- import net.minecraft.item.ItemStack;
- import net.minecraft.nbt.NBTTagCompound;
- import net.minecraft.tileentity.TileEntity;
- import net.minecraft.tileentity.TileEntitySkull;
- import net.minecraft.util.Icon;
- import net.minecraft.util.MathHelper;
- import net.minecraft.world.World;
- import net.minecraftforge.common.ForgeDirection;
- public class BlockSapphireCrop extends BlockContainer
- {
- @SideOnly(Side.CLIENT)
- private Icon[] iconArray;
- static int bAmt = 14;
- public BlockSapphireCrop(int id)
- {
- super(id, Material.cactus);
- this.setHardness(3.0F);
- this.setTickRandomly(true);
- this.setUnlocalizedName("sapphireCrop");
- this.setCreativeTab(Base.tabSometimes);
- //Block bounds -- What you collide with
- this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.75F, 1.0F);
- }
- //slows down growth speeds
- public void updateTick(World world, int x, int y, int z, Random rand)
- {
- if(world.getBlockId(x, y - 1, z) != Block.slowSand.blockID)
- return;
- if(world.getBlockLightValue(x, y + 1, z) < 9)
- return;
- if(rand.nextInt() % 5 != 0)
- return;
- if(bAmt < 7)
- bAmt += 2;
- //checks for staff and slows growth speed
- // for(int i = 0; i < 3; i++)
- // {
- // if(world.getBlockId(x + (i + 3), y, z))
- // }
- }
- //Called when block is sheared
- public boolean onBlockActivated(World world, int par2, int par3, int par4, EntityPlayer player, int par6, float par7, float par8, float par9)
- {
- ItemStack itemStack = player.inventory.getCurrentItem();
- if(itemStack.itemID == Base.itemSapphireBerry.itemID)
- {
- if(bAmt < 14)
- {
- for(int i = 0; i <= 0; i++)
- bAmt++;
- }
- if(!player.capabilities.isCreativeMode)
- itemStack.stackSize--;
- return true;
- }
- else if(itemStack.itemID == Item.shears.itemID && isShearable())
- {
- ItemStack stack = new ItemStack(Base.itemSapphireBerry);
- Random rand = new Random();
- EntityItem item = player.entityDropItem(stack, 1.0F);
- item.motionY += rand.nextFloat() * 0.05F;
- item.motionX += (rand.nextFloat() - rand.nextFloat()) * 0.2F;
- item.motionZ += (rand.nextFloat() - rand.nextFloat()) * 0.2F;
- if(!player.capabilities.isCreativeMode)
- itemStack.damageItem(5, player);
- bAmt--;
- return true;
- }
- else
- return true;
- }
- public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, int par5)
- {
- if (!par1World.doesBlockHaveSolidTopSurface(par2, par3 - 1, par4))
- {
- this.dropBlockAsItem(par1World, par2, par3, par4, par1World.getBlockMetadata(par2, par3, par4), 0);
- par1World.setBlockToAir(par2, par3, par4);
- }
- }
- //Given berry amount, checks to see if shear-able
- public boolean isShearable()
- {
- if(bAmt > 0)
- return true;
- else
- return false;
- }
- public void onBlockAdded(World par1World, int par2, int par3, int par4)
- {
- super.onBlockAdded(par1World, par2, par3, par4);
- this.setDefaultDirection(par1World, par2, par3, par4);
- }
- private void setDefaultDirection(World par1World, int par2, int par3, int par4)
- {
- if (!par1World.isRemote)
- {
- int l = par1World.getBlockId(par2, par3, par4 - 1);
- int i1 = par1World.getBlockId(par2, par3, par4 + 1);
- int j1 = par1World.getBlockId(par2 - 1, par3, par4);
- int k1 = par1World.getBlockId(par2 + 1, par3, par4);
- byte b0 = 3;
- if (Block.opaqueCubeLookup[l] && !Block.opaqueCubeLookup[i1])
- {
- b0 = 3;
- }
- if (Block.opaqueCubeLookup[i1] && !Block.opaqueCubeLookup[l])
- {
- b0 = 2;
- }
- if (Block.opaqueCubeLookup[j1] && !Block.opaqueCubeLookup[k1])
- {
- b0 = 5;
- }
- if (Block.opaqueCubeLookup[k1] && !Block.opaqueCubeLookup[j1])
- {
- b0 = 4;
- }
- par1World.setBlockMetadataWithNotify(par2, par3, par4, b0, 2);
- }
- }
- public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLivingBase par5EntityLivingBase, ItemStack par6ItemStack)
- {
- int l = MathHelper.floor_double((double)(par5EntityLivingBase.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
- if (l == 0)
- {
- par1World.setBlockMetadataWithNotify(par2, par3, par4, 2, 2);
- }
- if (l == 1)
- {
- par1World.setBlockMetadataWithNotify(par2, par3, par4, 5, 2);
- }
- if (l == 2)
- {
- par1World.setBlockMetadataWithNotify(par2, par3, par4, 3, 2);
- }
- if (l == 3)
- {
- par1World.setBlockMetadataWithNotify(par2, par3, par4, 4, 2);
- }
- }
- @Override
- public TileEntity createNewTileEntity(World world)
- {
- return new TileEntitySapphireCrop();
- }
- @Override
- public int getRenderType()
- {
- return -1;
- }
- @Override
- public boolean isOpaqueCube()
- {
- return false;
- }
- public boolean renderAsNormalBlock()
- {
- return false;
- }
- public static int getBerryAmount()
- {
- return bAmt;
- }
- @SideOnly(Side.CLIENT)
- public Icon getIcon(int side, int meta)
- {
- if (meta < 0 || meta > 7)
- {
- meta = 7;
- }
- return this.iconArray[meta];
- }
- public void registerIcons(IconRegister icon)
- {
- this.iconArray = new Icon[8];
- for (int i = 0; i < this.iconArray.length; ++i)
- {
- this.iconArray[i] = icon.registerIcon(Base.modid + ":" + (this.getUnlocalizedName().substring(5)) + "_" + i);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment