mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-18 11:29:15 +00:00
Implemeneted adding grass seeds, as well as IShearable for BlockTallGrass
This commit is contained in:
1 parent
cc74f7d7d0
commit
545b905f11
6 files changed
+248
-20
No files matched your search
@@ -39,6 +39,16 @@ public class ForgeHooks
|
||||
}
|
||||
world.setBlockAndMetadataWithNotify(x, y, z, grass.block.blockID, grass.metadata);
|
||||
}
|
||||
|
||||
public static ItemStack getGrassSeed(World world)
|
||||
{
|
||||
SeedEntry entry = (SeedEntry)WeightedRandom.getRandomItem(world.rand, seedList);
|
||||
if (entry == null || entry.seed == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return entry.seed.copy();
|
||||
}
|
||||
|
||||
static
|
||||
{
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package net.minecraft.src.forge;
|
||||
package net.minecraftforge.common;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
/**
|
||||
* This software is provided under the terms of the Minecraft Forge Public
|
||||
* License v1.0.
|
||||
*/
|
||||
|
||||
package net.minecraft.src.forge;
|
||||
|
||||
import net.minecraft.src.World;
|
||||
|
||||
public interface IBonemealHandler
|
||||
{
|
||||
/** Called when bonemeal is used on a block. This is also called for
|
||||
* multiplayer servers, which must still return true if appropriate but
|
||||
* shouldn't actually perform world manipulation.
|
||||
* @return true to use up the bonemeal and stop processing.
|
||||
*/
|
||||
public boolean onUseBonemeal(World world, int blockID, int X, int Y, int Z);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
--- ../src_base/common/net/minecraft/src/ItemShears.java
|
||||
+++ ../src_work/common/net/minecraft/src/ItemShears.java
|
||||
@@ -1,4 +1,8 @@
|
||||
package net.minecraft.src;
|
||||
+
|
||||
+import java.util.ArrayList;
|
||||
+
|
||||
+import net.minecraftforge.common.IShearable;
|
||||
|
||||
public class ItemShears extends Item
|
||||
{
|
||||
@@ -16,9 +20,12 @@
|
||||
{
|
||||
return super.func_77660_a(par1ItemStack, par2World, par3, par4, par5, par6, par7EntityLiving);
|
||||
}
|
||||
+ else if (!(Block.blocksList[par3] instanceof IShearable))
|
||||
+ {
|
||||
+ return super.func_77660_a(par1ItemStack, par2World, par3, par4, par5, par6, par7EntityLiving);
|
||||
+ }
|
||||
else
|
||||
{
|
||||
- par1ItemStack.damageItem(1, par7EntityLiving);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -39,4 +46,64 @@
|
||||
{
|
||||
return par2Block.blockID != Block.web.blockID && par2Block.blockID != Block.leaves.blockID ? (par2Block.blockID == Block.cloth.blockID ? 5.0F : super.getStrVsBlock(par1ItemStack, par2Block)) : 15.0F;
|
||||
}
|
||||
+
|
||||
+ @Override
|
||||
+ public boolean itemInteractionForEntity(ItemStack itemstack, EntityLiving entity)
|
||||
+ {
|
||||
+ if (entity.worldObj.isRemote)
|
||||
+ {
|
||||
+ return false;
|
||||
+ }
|
||||
+ if (entity instanceof IShearable)
|
||||
+ {
|
||||
+ IShearable target = (IShearable)entity;
|
||||
+ if (target.isShearable(itemstack, entity.worldObj, (int)entity.posX, (int)entity.posY, (int)entity.posZ))
|
||||
+ {
|
||||
+ ArrayList<ItemStack> drops = target.onSheared(itemstack, entity.worldObj, (int)entity.posX, (int)entity.posY, (int)entity.posZ,
|
||||
+ EnchantmentHelper.getEnchantmentLevel(Enchantment.fortune.effectId, itemstack));
|
||||
+ for(ItemStack stack : drops)
|
||||
+ {
|
||||
+ EntityItem ent = entity.entityDropItem(stack, 1.0F);
|
||||
+ ent.motionY += entity.rand.nextFloat() * 0.05F;
|
||||
+ ent.motionX += (entity.rand.nextFloat() - entity.rand.nextFloat()) * 0.1F;
|
||||
+ ent.motionZ += (entity.rand.nextFloat() - entity.rand.nextFloat()) * 0.1F;
|
||||
+ }
|
||||
+ itemstack.damageItem(1, entity);
|
||||
+ }
|
||||
+ return true;
|
||||
+ }
|
||||
+ return false;
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public boolean onBlockStartBreak(ItemStack itemstack, int x, int y, int z, EntityPlayer player)
|
||||
+ {
|
||||
+ if (player.worldObj.isRemote)
|
||||
+ {
|
||||
+ return false;
|
||||
+ }
|
||||
+ int id = player.worldObj.getBlockId(x, y, z);
|
||||
+ if (Block.blocksList[id] instanceof IShearable)
|
||||
+ {
|
||||
+ IShearable target = (IShearable)Block.blocksList[id];
|
||||
+ if (target.isShearable(itemstack, player.worldObj, x, y, z))
|
||||
+ {
|
||||
+ ArrayList<ItemStack> drops = target.onSheared(itemstack, player.worldObj, x, y, z,
|
||||
+ EnchantmentHelper.getEnchantmentLevel(Enchantment.fortune.effectId, itemstack));
|
||||
+ for(ItemStack stack : drops)
|
||||
+ {
|
||||
+ float f = 0.7F;
|
||||
+ double d = (double)(player.rand.nextFloat() * f) + (double)(1.0F - f) * 0.5D;
|
||||
+ double d1 = (double)(player.rand.nextFloat() * f) + (double)(1.0F - f) * 0.5D;
|
||||
+ double d2 = (double)(player.rand.nextFloat() * f) + (double)(1.0F - f) * 0.5D;
|
||||
+ EntityItem entityitem = new EntityItem(player.worldObj, (double)x + d, (double)y + d1, (double)z + d2, stack);
|
||||
+ entityitem.delayBeforeCanPickup = 10;
|
||||
+ player.worldObj.spawnEntityInWorld(entityitem);
|
||||
+ }
|
||||
+ itemstack.damageItem(1, player);
|
||||
+ player.addStat(StatList.mineBlockStatArray[id], 1);
|
||||
+ }
|
||||
+ }
|
||||
+ return false;
|
||||
+ }
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
--- ../src_base/minecraft/net/minecraft/src/BlockTallGrass.java
|
||||
+++ ../src_work/minecraft/net/minecraft/src/BlockTallGrass.java
|
||||
@@ -1,9 +1,13 @@
|
||||
package net.minecraft.src;
|
||||
|
||||
+import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
-public class BlockTallGrass extends BlockFlower
|
||||
+import net.minecraftforge.common.ForgeHooks;
|
||||
+import net.minecraftforge.common.IShearable;
|
||||
+
|
||||
+public class BlockTallGrass extends BlockFlower implements IShearable
|
||||
{
|
||||
protected BlockTallGrass(int par1, int par2)
|
||||
{
|
||||
@@ -50,7 +54,7 @@
|
||||
*/
|
||||
public int idDropped(int par1, Random par2Random, int par3)
|
||||
{
|
||||
- return par2Random.nextInt(8) == 0 ? Item.seeds.shiftedIndex : -1;
|
||||
+ return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -67,15 +71,7 @@
|
||||
*/
|
||||
public void harvestBlock(World par1World, EntityPlayer par2EntityPlayer, int par3, int par4, int par5, int par6)
|
||||
{
|
||||
- if (!par1World.isRemote && par2EntityPlayer.getCurrentEquippedItem() != null && par2EntityPlayer.getCurrentEquippedItem().itemID == Item.shears.shiftedIndex)
|
||||
- {
|
||||
- par2EntityPlayer.addStat(StatList.mineBlockStatArray[this.blockID], 1);
|
||||
- this.dropBlockAsItem_do(par1World, par3, par4, par5, new ItemStack(Block.tallGrass, 1, par6));
|
||||
- }
|
||||
- else
|
||||
- {
|
||||
- super.harvestBlock(par1World, par2EntityPlayer, par3, par4, par5, par6);
|
||||
- }
|
||||
+ super.harvestBlock(par1World, par2EntityPlayer, par3, par4, par5, par6);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -96,4 +92,35 @@
|
||||
par3List.add(new ItemStack(par1, 1, var4));
|
||||
}
|
||||
}
|
||||
+
|
||||
+ @Override
|
||||
+ public ArrayList<ItemStack> getBlockDropped(World world, int x, int y, int z, int meta, int fortune)
|
||||
+ {
|
||||
+ ArrayList<ItemStack> ret = new ArrayList<ItemStack>();
|
||||
+ if (world.rand.nextInt(8) != 0)
|
||||
+ {
|
||||
+ return ret;
|
||||
+ }
|
||||
+
|
||||
+ ItemStack item = ForgeHooks.getGrassSeed(world);
|
||||
+ if (item != null)
|
||||
+ {
|
||||
+ ret.add(item);
|
||||
+ }
|
||||
+ return ret;
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public boolean isShearable(ItemStack item, World world, int x, int y, int z)
|
||||
+ {
|
||||
+ return true;
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public ArrayList<ItemStack> onSheared(ItemStack item, World world, int x, int y, int z, int fortune)
|
||||
+ {
|
||||
+ ArrayList<ItemStack> ret = new ArrayList<ItemStack>();
|
||||
+ ret.add(new ItemStack(this, 1, world.getBlockMetadata(x, y, z)));
|
||||
+ return ret;
|
||||
+ }
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
--- ../src_base/minecraft_server/net/minecraft/src/BlockTallGrass.java
|
||||
+++ ../src_work/minecraft_server/net/minecraft/src/BlockTallGrass.java
|
||||
@@ -1,8 +1,12 @@
|
||||
package net.minecraft.src;
|
||||
|
||||
+import java.util.ArrayList;
|
||||
import java.util.Random;
|
||||
|
||||
-public class BlockTallGrass extends BlockFlower
|
||||
+import net.minecraftforge.common.ForgeHooks;
|
||||
+import net.minecraftforge.common.IShearable;
|
||||
+
|
||||
+public class BlockTallGrass extends BlockFlower implements IShearable
|
||||
{
|
||||
protected BlockTallGrass(int par1, int par2)
|
||||
{
|
||||
@@ -24,7 +28,7 @@
|
||||
*/
|
||||
public int idDropped(int par1, Random par2Random, int par3)
|
||||
{
|
||||
- return par2Random.nextInt(8) == 0 ? Item.seeds.shiftedIndex : -1;
|
||||
+ return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -41,14 +45,37 @@
|
||||
*/
|
||||
public void harvestBlock(World par1World, EntityPlayer par2EntityPlayer, int par3, int par4, int par5, int par6)
|
||||
{
|
||||
- if (!par1World.isRemote && par2EntityPlayer.getCurrentEquippedItem() != null && par2EntityPlayer.getCurrentEquippedItem().itemID == Item.shears.shiftedIndex)
|
||||
+ super.harvestBlock(par1World, par2EntityPlayer, par3, par4, par5, par6);
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public ArrayList<ItemStack> getBlockDropped(World world, int x, int y, int z, int meta, int fortune)
|
||||
+ {
|
||||
+ ArrayList<ItemStack> ret = new ArrayList<ItemStack>();
|
||||
+ if (world.rand.nextInt(8) != 0)
|
||||
{
|
||||
- par2EntityPlayer.addStat(StatList.mineBlockStatArray[this.blockID], 1);
|
||||
- this.dropBlockAsItem_do(par1World, par3, par4, par5, new ItemStack(Block.tallGrass, 1, par6));
|
||||
+ return ret;
|
||||
}
|
||||
- else
|
||||
+
|
||||
+ ItemStack item = ForgeHooks.getGrassSeed(world);
|
||||
+ if (item != null)
|
||||
{
|
||||
- super.harvestBlock(par1World, par2EntityPlayer, par3, par4, par5, par6);
|
||||
+ ret.add(item);
|
||||
}
|
||||
+ return ret;
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public boolean isShearable(ItemStack item, World world, int x, int y, int z)
|
||||
+ {
|
||||
+ return true;
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public ArrayList<ItemStack> onSheared(ItemStack item, World world, int x, int y, int z, int fortune)
|
||||
+ {
|
||||
+ ArrayList<ItemStack> ret = new ArrayList<ItemStack>();
|
||||
+ ret.add(new ItemStack(this, 1, world.getBlockMetadata(x, y, z)));
|
||||
+ return ret;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user