Implimented a new IShearable system. This allows mods to create both new shear-like items/blocks. As well as new Entities/Blocks that work with other mod's shear-like items.

This commit is contained in:
LexManos committed 2012-02-13 04:13:02 -08:00
1 parent 5163a30002
commit f2b973e48a
13 files changed
+758 -8

No files matched your search

@@ -0,0 +1,53 @@
package net.minecraft.src.forge;
import java.util.ArrayList;
import net.minecraft.src.EntityPlayer;
import net.minecraft.src.ItemStack;
import net.minecraft.src.MovingObjectPosition;
import net.minecraft.src.World;
/**
*
* This allows for mods to create there own Shear-like items
* and have them interact with Blocks/Entities without extra work.
* Also, if your block/entity supports the Shears, this allows you
* to support mod-shears as well.
*
*/
public interface IShearable
{
/**
* Checks if the object is currently shearable
* Example: Sheep return false when they have no wool
*
* @param item The itemstack that is being used, Possible to be null
* @param world The current world
* @param X The X Position
* @param Y The Y Position
* @param Z The Z Position
* @return If this is shearable, and onSheared should be called.
*/
public boolean isShearable(ItemStack item, World world, int X, int Y, int Z);
/**
* Performs the shear function on this object.
* This is called for both client, and server.
* The object should perform all actions related to being sheared,
* except for dropping of the items.
*
* Returns a list of items that resulted from the shearing process.
*
* For entities, they should trust there internal location information
* over the values passed into this function.
*
* @param item The itemstack that is being used, Possible to be null
* @param world The current world
* @param X The X Position
* @param Y The Y Position
* @param Z The Z Position
* @param fortune The fortune level of the shears being used
* @return A ArrayList containing all items from this shearing. Possible to be null.
*/
public ArrayList<ItemStack> onSheared(ItemStack item, World world, int X, int Y, int Z, int fortune);
}
@@ -0,0 +1,51 @@
--- ../src_base/minecraft/net/minecraft/src/BlockLeaves.java 0000-00-00 00:00:00.000000000 -0000
+++ ../src_work/minecraft/net/minecraft/src/BlockLeaves.java 0000-00-00 00:00:00.000000000 -0000
@@ -1,8 +1,11 @@
package net.minecraft.src;
+import java.util.ArrayList;
import java.util.Random;
-public class BlockLeaves extends BlockLeavesBase
+import net.minecraft.src.forge.IShearable;
+
+public class BlockLeaves extends BlockLeavesBase implements IShearable
{
private int baseIndexInPNG;
int adjacentTreeBlocks[];
@@ -213,15 +216,7 @@
public void harvestBlock(World world, EntityPlayer entityplayer, int i, int j, int k, int l)
{
- if (!world.isRemote && entityplayer.getCurrentEquippedItem() != null && entityplayer.getCurrentEquippedItem().itemID == Item.shears.shiftedIndex)
- {
- entityplayer.addStat(StatList.mineBlockStatArray[blockID], 1);
- dropBlockAsItem_do(world, i, j, k, new ItemStack(Block.leaves.blockID, 1, l & 3));
- }
- else
- {
- super.harvestBlock(world, entityplayer, i, j, k, l);
- }
+ super.harvestBlock(world, entityplayer, i, j, k, l);
}
protected int damageDropped(int i)
@@ -256,4 +251,18 @@
{
super.onEntityWalking(world, i, j, k, entity);
}
+
+ @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(Block.leaves.blockID, 1, world.getBlockMetadata(X, Y, Z) & 3));
+ return ret;
+ }
}
@@ -1,17 +1,20 @@
--- ../src_base/minecraft/net/minecraft/src/BlockTallGrass.java 0000-00-00 00:00:00.000000000 -0000
+++ ../src_work/minecraft/net/minecraft/src/BlockTallGrass.java 0000-00-00 00:00:00.000000000 -0000
@@ -1,7 +1,10 @@
@@ -1,8 +1,12 @@
package net.minecraft.src;
+import java.util.ArrayList;
import java.util.Random;
-public class BlockTallGrass extends BlockFlower
+import net.minecraft.src.forge.ForgeHooks;
+import net.minecraft.src.forge.IShearable;
+
public class BlockTallGrass extends BlockFlower
+public class BlockTallGrass extends BlockFlower implements IShearable
{
protected BlockTallGrass(int i, int j)
@@ -65,14 +68,7 @@
{
@@ -65,14 +69,7 @@
public int idDropped(int i, Random random, int j)
{
@@ -27,7 +30,7 @@
}
public int quantityDroppedWithBonus(int i, Random random)
@@ -80,6 +76,23 @@
@@ -80,16 +77,39 @@
return 1 + random.nextInt(i * 2 + 1);
}
@@ -50,4 +53,29 @@
+
public void harvestBlock(World world, EntityPlayer entityplayer, int i, int j, int k, int l)
{
if (!world.isRemote && entityplayer.getCurrentEquippedItem() != null && entityplayer.getCurrentEquippedItem().itemID == Item.shears.shiftedIndex)
- if (!world.isRemote && entityplayer.getCurrentEquippedItem() != null && entityplayer.getCurrentEquippedItem().itemID == Item.shears.shiftedIndex)
- {
- entityplayer.addStat(StatList.mineBlockStatArray[blockID], 1);
- dropBlockAsItem_do(world, i, j, k, new ItemStack(Block.tallGrass, 1, l));
- }
- else
- {
- super.harvestBlock(world, entityplayer, i, j, k, l);
- }
+ super.harvestBlock(world, entityplayer, i, j, k, l);
+ }
+
+ @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(Block.tallGrass, 1, world.getBlockMetadata(X, Y, Z)));
+ return ret;
}
}
@@ -0,0 +1,45 @@
--- ../src_base/minecraft/net/minecraft/src/BlockVine.java 0000-00-00 00:00:00.000000000 -0000
+++ ../src_work/minecraft/net/minecraft/src/BlockVine.java 0000-00-00 00:00:00.000000000 -0000
@@ -1,8 +1,11 @@
package net.minecraft.src;
+import java.util.ArrayList;
import java.util.Random;
-public class BlockVine extends Block
+import net.minecraft.src.forge.IShearable;
+
+public class BlockVine extends Block implements IShearable
{
public BlockVine(int i)
{
@@ -345,14 +348,20 @@
public void harvestBlock(World world, EntityPlayer entityplayer, int i, int j, int k, int l)
{
- if (!world.isRemote && entityplayer.getCurrentEquippedItem() != null && entityplayer.getCurrentEquippedItem().itemID == Item.shears.shiftedIndex)
- {
- entityplayer.addStat(StatList.mineBlockStatArray[blockID], 1);
- dropBlockAsItem_do(world, i, j, k, new ItemStack(Block.vine, 1, 0));
- }
- else
- {
- super.harvestBlock(world, entityplayer, i, j, k, l);
- }
+ super.harvestBlock(world, entityplayer, i, j, k, l);
+ }
+
+ @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(Block.vine, 1, 0));
+ return ret;
}
}
@@ -0,0 +1,71 @@
--- ../src_base/minecraft/net/minecraft/src/EntityMooshroom.java 0000-00-00 00:00:00.000000000 -0000
+++ ../src_work/minecraft/net/minecraft/src/EntityMooshroom.java 0000-00-00 00:00:00.000000000 -0000
@@ -1,6 +1,10 @@
package net.minecraft.src;
-public class EntityMooshroom extends EntityCow
+import java.util.ArrayList;
+
+import net.minecraft.src.forge.IShearable;
+
+public class EntityMooshroom extends EntityCow implements IShearable
{
public EntityMooshroom(World world)
{
@@ -17,30 +21,36 @@
entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem, new ItemStack(Item.bowlSoup));
return true;
}
- if (itemstack != null && itemstack.itemID == Item.shears.shiftedIndex && getDelay() >= 0)
- {
- setEntityDead();
- EntityCow entitycow = new EntityCow(worldObj);
- entitycow.setLocationAndAngles(posX, posY, posZ, rotationYaw, rotationPitch);
- entitycow.setEntityHealth(getEntityHealth());
- entitycow.renderYawOffset = renderYawOffset;
- worldObj.spawnEntityInWorld(entitycow);
- worldObj.spawnParticle("largeexplode", posX, posY + (double)(height / 2.0F), posZ, 0.0D, 0.0D, 0.0D);
- for (int i = 0; i < 5; i++)
- {
- worldObj.spawnEntityInWorld(new EntityItem(worldObj, posX, posY + (double)height, posZ, new ItemStack(Block.mushroomRed)));
- }
-
- return true;
- }
- else
- {
- return super.interact(entityplayer);
- }
+ return super.interact(entityplayer);
}
protected EntityAnimal spawnBabyAnimal(EntityAnimal entityanimal)
{
return new EntityMooshroom(worldObj);
}
+
+ @Override
+ public boolean isShearable(ItemStack item, World world, int X, int Y, int Z)
+ {
+ return getDelay() >= 0;
+ }
+
+ @Override
+ public ArrayList<ItemStack> onSheared(ItemStack item, World world, int X, int Y, int Z, int fortune)
+ {
+ setEntityDead();
+ EntityCow entitycow = new EntityCow(worldObj);
+ entitycow.setLocationAndAngles(posX, posY, posZ, rotationYaw, rotationPitch);
+ entitycow.setEntityHealth(getEntityHealth());
+ entitycow.renderYawOffset = renderYawOffset;
+ worldObj.spawnEntityInWorld(entitycow);
+ worldObj.spawnParticle("largeexplode", posX, posY + (double)(height / 2.0F), posZ, 0.0D, 0.0D, 0.0D);
+
+ ArrayList<ItemStack> ret = new ArrayList<ItemStack>();
+ for (int x = 0; x < 5; x++)
+ {
+ ret.add(new ItemStack(Block.mushroomRed));
+ }
+ return ret;
+ }
}
@@ -0,0 +1,63 @@
--- ../src_base/minecraft/net/minecraft/src/EntitySheep.java 0000-00-00 00:00:00.000000000 -0000
+++ ../src_work/minecraft/net/minecraft/src/EntitySheep.java 0000-00-00 00:00:00.000000000 -0000
@@ -1,8 +1,11 @@
package net.minecraft.src;
+import java.util.ArrayList;
import java.util.Random;
-public class EntitySheep extends EntityAnimal
+import net.minecraft.src.forge.IShearable;
+
+public class EntitySheep extends EntityAnimal implements IShearable
{
public static final float fleeceColorTable[][] =
{
@@ -194,23 +197,6 @@
public boolean interact(EntityPlayer entityplayer)
{
- ItemStack itemstack = entityplayer.inventory.getCurrentItem();
- if (itemstack != null && itemstack.itemID == Item.shears.shiftedIndex && !getSheared() && !isChild())
- {
- if (!worldObj.isRemote)
- {
- setSheared(true);
- int i = 1 + rand.nextInt(3);
- for (int j = 0; j < i; j++)
- {
- EntityItem entityitem = entityDropItem(new ItemStack(Block.cloth.blockID, 1, getFleeceColor()), 1.0F);
- entityitem.motionY += rand.nextFloat() * 0.05F;
- entityitem.motionX += (rand.nextFloat() - rand.nextFloat()) * 0.1F;
- entityitem.motionZ += (rand.nextFloat() - rand.nextFloat()) * 0.1F;
- }
- }
- itemstack.damageItem(1, entityplayer);
- }
return super.interact(entityplayer);
}
@@ -308,4 +294,23 @@
}
return entitysheep1;
}
+
+ @Override
+ public boolean isShearable(ItemStack item, World world, int X, int Y, int Z)
+ {
+ return !getSheared() && !isChild();
+ }
+
+ @Override
+ public ArrayList<ItemStack> onSheared(ItemStack item, World world, int X, int Y, int Z, int fortune)
+ {
+ ArrayList<ItemStack> ret = new ArrayList<ItemStack>();
+ setSheared(true);
+ int i = 1 + rand.nextInt(3);
+ for (int j = 0; j < i; j++)
+ {
+ ret.add(new ItemStack(Block.cloth.blockID, 1, getFleeceColor()));
+ }
+ return ret;
+ }
}
@@ -0,0 +1,90 @@
--- ../src_base/minecraft/net/minecraft/src/ItemShears.java 0000-00-00 00:00:00.000000000 -0000
+++ ../src_work/minecraft/net/minecraft/src/ItemShears.java 0000-00-00 00:00:00.000000000 -0000
@@ -1,5 +1,9 @@
package net.minecraft.src;
+import java.util.ArrayList;
+
+import net.minecraft.src.forge.IShearable;
+
public class ItemShears extends Item
{
public ItemShears(int i)
@@ -11,12 +15,11 @@
public boolean onBlockDestroyed(ItemStack itemstack, int i, int j, int k, int l, EntityLiving entityliving)
{
- if (i == Block.leaves.blockID || i == Block.web.blockID || i == Block.tallGrass.blockID || i == Block.vine.blockID)
+ if (i == Block.leaves.blockID || i == Block.web.blockID || i == Block.tallGrass.blockID || i == Block.vine.blockID || Block.blocksList[i] instanceof IShearable)
{
- itemstack.damageItem(1, entityliving);
return true;
}
- else
+ else
{
return super.onBlockDestroyed(itemstack, i, j, k, l, entityliving);
}
@@ -42,4 +45,62 @@
return super.getStrVsBlock(itemstack, block);
}
}
+
+ @Override
+ public void useItemOnEntity(ItemStack itemstack, EntityLiving entity)
+ {
+ if (entity.worldObj.isRemote)
+ {
+ return;
+ }
+ 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);
+ }
+ }
+ }
+
+ @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] != null && 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,51 @@
--- ../src_base/minecraft_server/net/minecraft/src/BlockLeaves.java 0000-00-00 00:00:00.000000000 -0000
+++ ../src_work/minecraft_server/net/minecraft/src/BlockLeaves.java 0000-00-00 00:00:00.000000000 -0000
@@ -1,8 +1,11 @@
package net.minecraft.src;
+import java.util.ArrayList;
import java.util.Random;
-public class BlockLeaves extends BlockLeavesBase
+import net.minecraft.src.forge.IShearable;
+
+public class BlockLeaves extends BlockLeavesBase implements IShearable
{
private int baseIndexInPNG;
int adjacentTreeBlocks[];
@@ -162,15 +165,7 @@
public void harvestBlock(World world, EntityPlayer entityplayer, int i, int j, int k, int l)
{
- if (!world.isRemote && entityplayer.getCurrentEquippedItem() != null && entityplayer.getCurrentEquippedItem().itemID == Item.shears.shiftedIndex)
- {
- entityplayer.addStat(StatList.mineBlockStatArray[blockID], 1);
- dropBlockAsItem_do(world, i, j, k, new ItemStack(Block.leaves.blockID, 1, l & 3));
- }
- else
- {
- super.harvestBlock(world, entityplayer, i, j, k, l);
- }
+ super.harvestBlock(world, entityplayer, i, j, k, l);
}
protected int damageDropped(int i)
@@ -199,4 +194,18 @@
{
super.onEntityWalking(world, i, j, k, entity);
}
+
+ @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(Block.leaves.blockID, 1, world.getBlockMetadata(X, Y, Z) & 3));
+ return ret;
+ }
}
@@ -1,17 +1,20 @@
--- ../src_base/minecraft_server/net/minecraft/src/BlockTallGrass.java 0000-00-00 00:00:00.000000000 -0000
+++ ../src_work/minecraft_server/net/minecraft/src/BlockTallGrass.java 0000-00-00 00:00:00.000000000 -0000
@@ -1,7 +1,10 @@
@@ -1,8 +1,12 @@
package net.minecraft.src;
+import java.util.ArrayList;
import java.util.Random;
-public class BlockTallGrass extends BlockFlower
+import net.minecraft.src.forge.ForgeHooks;
+import net.minecraft.src.forge.IShearable;
+
public class BlockTallGrass extends BlockFlower
+public class BlockTallGrass extends BlockFlower implements IShearable
{
protected BlockTallGrass(int i, int j)
@@ -33,15 +36,25 @@
{
@@ -33,15 +37,25 @@
public int idDropped(int i, Random random, int j)
{
@@ -42,3 +45,33 @@
public int quantityDroppedWithBonus(int i, Random random)
{
@@ -50,14 +64,20 @@
public void harvestBlock(World world, EntityPlayer entityplayer, int i, int j, int k, int l)
{
- if (!world.isRemote && entityplayer.getCurrentEquippedItem() != null && entityplayer.getCurrentEquippedItem().itemID == Item.shears.shiftedIndex)
- {
- entityplayer.addStat(StatList.mineBlockStatArray[blockID], 1);
- dropBlockAsItem_do(world, i, j, k, new ItemStack(Block.tallGrass, 1, l));
- }
- else
- {
- super.harvestBlock(world, entityplayer, i, j, k, l);
- }
+ super.harvestBlock(world, entityplayer, i, j, k, l);
+ }
+
+ @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(Block.tallGrass, 1, world.getBlockMetadata(X, Y, Z)));
+ return ret;
}
}
@@ -0,0 +1,45 @@
--- ../src_base/minecraft_server/net/minecraft/src/BlockVine.java 0000-00-00 00:00:00.000000000 -0000
+++ ../src_work/minecraft_server/net/minecraft/src/BlockVine.java 0000-00-00 00:00:00.000000000 -0000
@@ -1,8 +1,11 @@
package net.minecraft.src;
+import java.util.ArrayList;
import java.util.Random;
-public class BlockVine extends Block
+import net.minecraft.src.forge.IShearable;
+
+public class BlockVine extends Block implements IShearable
{
public BlockVine(int i)
{
@@ -330,14 +333,20 @@
public void harvestBlock(World world, EntityPlayer entityplayer, int i, int j, int k, int l)
{
- if (!world.isRemote && entityplayer.getCurrentEquippedItem() != null && entityplayer.getCurrentEquippedItem().itemID == Item.shears.shiftedIndex)
- {
- entityplayer.addStat(StatList.mineBlockStatArray[blockID], 1);
- dropBlockAsItem_do(world, i, j, k, new ItemStack(Block.vine, 1, 0));
- }
- else
- {
- super.harvestBlock(world, entityplayer, i, j, k, l);
- }
+ super.harvestBlock(world, entityplayer, i, j, k, l);
+ }
+
+ @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(Block.vine, 1, 0));
+ return ret;
}
}
@@ -0,0 +1,71 @@
--- ../src_base/minecraft_server/net/minecraft/src/EntityMooshroom.java 0000-00-00 00:00:00.000000000 -0000
+++ ../src_work/minecraft_server/net/minecraft/src/EntityMooshroom.java 0000-00-00 00:00:00.000000000 -0000
@@ -1,6 +1,10 @@
package net.minecraft.src;
-public class EntityMooshroom extends EntityCow
+import java.util.ArrayList;
+
+import net.minecraft.src.forge.IShearable;
+
+public class EntityMooshroom extends EntityCow implements IShearable
{
public EntityMooshroom(World world)
{
@@ -17,30 +21,36 @@
entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem, new ItemStack(Item.bowlSoup));
return true;
}
- if (itemstack != null && itemstack.itemID == Item.shears.shiftedIndex && getDelay() >= 0)
- {
- setEntityDead();
- EntityCow entitycow = new EntityCow(worldObj);
- entitycow.setLocationAndAngles(posX, posY, posZ, rotationYaw, rotationPitch);
- entitycow.setEntityHealth(getEntityHealth());
- entitycow.renderYawOffset = renderYawOffset;
- worldObj.spawnEntityInWorld(entitycow);
- worldObj.spawnParticle("largeexplode", posX, posY + (double)(height / 2.0F), posZ, 0.0D, 0.0D, 0.0D);
- for (int i = 0; i < 5; i++)
- {
- worldObj.spawnEntityInWorld(new EntityItem(worldObj, posX, posY + (double)height, posZ, new ItemStack(Block.mushroomRed)));
- }
-
- return true;
- }
- else
- {
- return super.interact(entityplayer);
- }
+ return super.interact(entityplayer);
}
protected EntityAnimal spawnBabyAnimal(EntityAnimal entityanimal)
{
return new EntityMooshroom(worldObj);
}
+
+ @Override
+ public boolean isShearable(ItemStack item, World world, int X, int Y, int Z)
+ {
+ return getDelay() >= 0;
+ }
+
+ @Override
+ public ArrayList<ItemStack> onSheared(ItemStack item, World world, int X, int Y, int Z, int fortune)
+ {
+ setEntityDead();
+ EntityCow entitycow = new EntityCow(worldObj);
+ entitycow.setLocationAndAngles(posX, posY, posZ, rotationYaw, rotationPitch);
+ entitycow.setEntityHealth(getEntityHealth());
+ entitycow.renderYawOffset = renderYawOffset;
+ worldObj.spawnEntityInWorld(entitycow);
+ worldObj.spawnParticle("largeexplode", posX, posY + (double)(height / 2.0F), posZ, 0.0D, 0.0D, 0.0D);
+
+ ArrayList<ItemStack> ret = new ArrayList<ItemStack>();
+ for (int x = 0; x < 5; x++)
+ {
+ ret.add(new ItemStack(Block.mushroomRed));
+ }
+ return ret;
+ }
}
@@ -0,0 +1,63 @@
--- ../src_base/minecraft_server/net/minecraft/src/EntitySheep.java 0000-00-00 00:00:00.000000000 -0000
+++ ../src_work/minecraft_server/net/minecraft/src/EntitySheep.java 0000-00-00 00:00:00.000000000 -0000
@@ -1,8 +1,11 @@
package net.minecraft.src;
+import java.util.ArrayList;
import java.util.Random;
-public class EntitySheep extends EntityAnimal
+import net.minecraft.src.forge.IShearable;
+
+public class EntitySheep extends EntityAnimal implements IShearable
{
public static final float fleeceColorTable[][] =
{
@@ -145,23 +148,6 @@
public boolean interact(EntityPlayer entityplayer)
{
- ItemStack itemstack = entityplayer.inventory.getCurrentItem();
- if (itemstack != null && itemstack.itemID == Item.shears.shiftedIndex && !getSheared() && !isChild())
- {
- if (!worldObj.isRemote)
- {
- setSheared(true);
- int i = 1 + rand.nextInt(3);
- for (int j = 0; j < i; j++)
- {
- EntityItem entityitem = entityDropItem(new ItemStack(Block.cloth.blockID, 1, getFleeceColor()), 1.0F);
- entityitem.motionY += rand.nextFloat() * 0.05F;
- entityitem.motionX += (rand.nextFloat() - rand.nextFloat()) * 0.1F;
- entityitem.motionZ += (rand.nextFloat() - rand.nextFloat()) * 0.1F;
- }
- }
- itemstack.damageItem(1, entityplayer);
- }
return super.interact(entityplayer);
}
@@ -259,4 +245,23 @@
}
return entitysheep1;
}
+
+ @Override
+ public boolean isShearable(ItemStack item, World world, int X, int Y, int Z)
+ {
+ return !getSheared() && !isChild();
+ }
+
+ @Override
+ public ArrayList<ItemStack> onSheared(ItemStack item, World world, int X, int Y, int Z, int fortune)
+ {
+ ArrayList<ItemStack> ret = new ArrayList<ItemStack>();
+ setSheared(true);
+ int i = 1 + rand.nextInt(3);
+ for (int j = 0; j < i; j++)
+ {
+ ret.add(new ItemStack(Block.cloth.blockID, 1, getFleeceColor()));
+ }
+ return ret;
+ }
}
@@ -0,0 +1,86 @@
--- ../src_base/minecraft_server/net/minecraft/src/ItemShears.java 0000-00-00 00:00:00.000000000 -0000
+++ ../src_work/minecraft_server/net/minecraft/src/ItemShears.java 0000-00-00 00:00:00.000000000 -0000
@@ -1,5 +1,9 @@
package net.minecraft.src;
+import java.util.ArrayList;
+
+import net.minecraft.src.forge.IShearable;
+
public class ItemShears extends Item
{
public ItemShears(int i)
@@ -11,9 +15,8 @@
public boolean onBlockDestroyed(ItemStack itemstack, int i, int j, int k, int l, EntityLiving entityliving)
{
- if (i == Block.leaves.blockID || i == Block.web.blockID || i == Block.tallGrass.blockID || i == Block.vine.blockID)
+ if (i == Block.leaves.blockID || i == Block.web.blockID || i == Block.tallGrass.blockID || i == Block.vine.blockID || Block.blocksList[i] instanceof IShearable)
{
- itemstack.damageItem(1, entityliving);
return true;
}
else
@@ -42,4 +45,62 @@
return super.getStrVsBlock(itemstack, block);
}
}
+
+ @Override
+ public void useItemOnEntity(ItemStack itemstack, EntityLiving entity)
+ {
+ if (entity.worldObj.isRemote)
+ {
+ return;
+ }
+ 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);
+ }
+ }
+ }
+
+ @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] != null && 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;
+ }
}