From f2b973e48a4d800862c2fe641e54e77e190b3074 Mon Sep 17 00:00:00 2001 From: LexManos Date: Mon, 13 Feb 2012 04:13:02 -0800 Subject: [PATCH] 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. --- .../net/minecraft/src/forge/IShearable.java | 53 +++++++++++ .../net/minecraft/src/BlockLeaves.java.patch | 51 +++++++++++ .../minecraft/src/BlockTallGrass.java.patch | 38 ++++++-- .../net/minecraft/src/BlockVine.java.patch | 45 ++++++++++ .../minecraft/src/EntityMooshroom.java.patch | 71 +++++++++++++++ .../net/minecraft/src/EntitySheep.java.patch | 63 +++++++++++++ .../net/minecraft/src/ItemShears.java.patch | 90 +++++++++++++++++++ .../net/minecraft/src/BlockLeaves.java.patch | 51 +++++++++++ .../minecraft/src/BlockTallGrass.java.patch | 39 +++++++- .../net/minecraft/src/BlockVine.java.patch | 45 ++++++++++ .../minecraft/src/EntityMooshroom.java.patch | 71 +++++++++++++++ .../net/minecraft/src/EntitySheep.java.patch | 63 +++++++++++++ .../net/minecraft/src/ItemShears.java.patch | 86 ++++++++++++++++++ 13 files changed, 758 insertions(+), 8 deletions(-) create mode 100644 forge/forge_common/net/minecraft/src/forge/IShearable.java create mode 100644 forge/patches/minecraft/net/minecraft/src/BlockLeaves.java.patch create mode 100644 forge/patches/minecraft/net/minecraft/src/BlockVine.java.patch create mode 100644 forge/patches/minecraft/net/minecraft/src/EntityMooshroom.java.patch create mode 100644 forge/patches/minecraft/net/minecraft/src/EntitySheep.java.patch create mode 100644 forge/patches/minecraft/net/minecraft/src/ItemShears.java.patch create mode 100644 forge/patches/minecraft_server/net/minecraft/src/BlockLeaves.java.patch create mode 100644 forge/patches/minecraft_server/net/minecraft/src/BlockVine.java.patch create mode 100644 forge/patches/minecraft_server/net/minecraft/src/EntityMooshroom.java.patch create mode 100644 forge/patches/minecraft_server/net/minecraft/src/EntitySheep.java.patch create mode 100644 forge/patches/minecraft_server/net/minecraft/src/ItemShears.java.patch diff --git a/forge/forge_common/net/minecraft/src/forge/IShearable.java b/forge/forge_common/net/minecraft/src/forge/IShearable.java new file mode 100644 index 0000000000..b65631be44 --- /dev/null +++ b/forge/forge_common/net/minecraft/src/forge/IShearable.java @@ -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 onSheared(ItemStack item, World world, int X, int Y, int Z, int fortune); +} diff --git a/forge/patches/minecraft/net/minecraft/src/BlockLeaves.java.patch b/forge/patches/minecraft/net/minecraft/src/BlockLeaves.java.patch new file mode 100644 index 0000000000..c74d5825d5 --- /dev/null +++ b/forge/patches/minecraft/net/minecraft/src/BlockLeaves.java.patch @@ -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 onSheared(ItemStack item, World world, int X, int Y, int Z, int fortune) ++ { ++ ArrayList ret = new ArrayList(); ++ ret.add(new ItemStack(Block.leaves.blockID, 1, world.getBlockMetadata(X, Y, Z) & 3)); ++ return ret; ++ } + } diff --git a/forge/patches/minecraft/net/minecraft/src/BlockTallGrass.java.patch b/forge/patches/minecraft/net/minecraft/src/BlockTallGrass.java.patch index af56fc4a00..9697550794 100644 --- a/forge/patches/minecraft/net/minecraft/src/BlockTallGrass.java.patch +++ b/forge/patches/minecraft/net/minecraft/src/BlockTallGrass.java.patch @@ -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 onSheared(ItemStack item, World world, int X, int Y, int Z, int fortune) ++ { ++ ArrayList ret = new ArrayList(); ++ ret.add(new ItemStack(Block.tallGrass, 1, world.getBlockMetadata(X, Y, Z))); ++ return ret; + } + } diff --git a/forge/patches/minecraft/net/minecraft/src/BlockVine.java.patch b/forge/patches/minecraft/net/minecraft/src/BlockVine.java.patch new file mode 100644 index 0000000000..4994bdaf4d --- /dev/null +++ b/forge/patches/minecraft/net/minecraft/src/BlockVine.java.patch @@ -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 onSheared(ItemStack item, World world, int X, int Y, int Z, int fortune) ++ { ++ ArrayList ret = new ArrayList(); ++ ret.add(new ItemStack(Block.vine, 1, 0)); ++ return ret; + } + } diff --git a/forge/patches/minecraft/net/minecraft/src/EntityMooshroom.java.patch b/forge/patches/minecraft/net/minecraft/src/EntityMooshroom.java.patch new file mode 100644 index 0000000000..3d624b1fd9 --- /dev/null +++ b/forge/patches/minecraft/net/minecraft/src/EntityMooshroom.java.patch @@ -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 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 ret = new ArrayList(); ++ for (int x = 0; x < 5; x++) ++ { ++ ret.add(new ItemStack(Block.mushroomRed)); ++ } ++ return ret; ++ } + } diff --git a/forge/patches/minecraft/net/minecraft/src/EntitySheep.java.patch b/forge/patches/minecraft/net/minecraft/src/EntitySheep.java.patch new file mode 100644 index 0000000000..7c278500c2 --- /dev/null +++ b/forge/patches/minecraft/net/minecraft/src/EntitySheep.java.patch @@ -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 onSheared(ItemStack item, World world, int X, int Y, int Z, int fortune) ++ { ++ ArrayList ret = new ArrayList(); ++ 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; ++ } + } diff --git a/forge/patches/minecraft/net/minecraft/src/ItemShears.java.patch b/forge/patches/minecraft/net/minecraft/src/ItemShears.java.patch new file mode 100644 index 0000000000..2c182aaed2 --- /dev/null +++ b/forge/patches/minecraft/net/minecraft/src/ItemShears.java.patch @@ -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 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 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; ++ } + } diff --git a/forge/patches/minecraft_server/net/minecraft/src/BlockLeaves.java.patch b/forge/patches/minecraft_server/net/minecraft/src/BlockLeaves.java.patch new file mode 100644 index 0000000000..55af10dd71 --- /dev/null +++ b/forge/patches/minecraft_server/net/minecraft/src/BlockLeaves.java.patch @@ -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 onSheared(ItemStack item, World world, int X, int Y, int Z, int fortune) ++ { ++ ArrayList ret = new ArrayList(); ++ ret.add(new ItemStack(Block.leaves.blockID, 1, world.getBlockMetadata(X, Y, Z) & 3)); ++ return ret; ++ } + } diff --git a/forge/patches/minecraft_server/net/minecraft/src/BlockTallGrass.java.patch b/forge/patches/minecraft_server/net/minecraft/src/BlockTallGrass.java.patch index 5c7e474243..e316e94b85 100644 --- a/forge/patches/minecraft_server/net/minecraft/src/BlockTallGrass.java.patch +++ b/forge/patches/minecraft_server/net/minecraft/src/BlockTallGrass.java.patch @@ -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 onSheared(ItemStack item, World world, int X, int Y, int Z, int fortune) ++ { ++ ArrayList ret = new ArrayList(); ++ ret.add(new ItemStack(Block.tallGrass, 1, world.getBlockMetadata(X, Y, Z))); ++ return ret; + } + } diff --git a/forge/patches/minecraft_server/net/minecraft/src/BlockVine.java.patch b/forge/patches/minecraft_server/net/minecraft/src/BlockVine.java.patch new file mode 100644 index 0000000000..9b1637bdb4 --- /dev/null +++ b/forge/patches/minecraft_server/net/minecraft/src/BlockVine.java.patch @@ -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 onSheared(ItemStack item, World world, int X, int Y, int Z, int fortune) ++ { ++ ArrayList ret = new ArrayList(); ++ ret.add(new ItemStack(Block.vine, 1, 0)); ++ return ret; + } + } diff --git a/forge/patches/minecraft_server/net/minecraft/src/EntityMooshroom.java.patch b/forge/patches/minecraft_server/net/minecraft/src/EntityMooshroom.java.patch new file mode 100644 index 0000000000..fd6fd09b18 --- /dev/null +++ b/forge/patches/minecraft_server/net/minecraft/src/EntityMooshroom.java.patch @@ -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 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 ret = new ArrayList(); ++ for (int x = 0; x < 5; x++) ++ { ++ ret.add(new ItemStack(Block.mushroomRed)); ++ } ++ return ret; ++ } + } diff --git a/forge/patches/minecraft_server/net/minecraft/src/EntitySheep.java.patch b/forge/patches/minecraft_server/net/minecraft/src/EntitySheep.java.patch new file mode 100644 index 0000000000..0e5dc67d95 --- /dev/null +++ b/forge/patches/minecraft_server/net/minecraft/src/EntitySheep.java.patch @@ -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 onSheared(ItemStack item, World world, int X, int Y, int Z, int fortune) ++ { ++ ArrayList ret = new ArrayList(); ++ 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; ++ } + } diff --git a/forge/patches/minecraft_server/net/minecraft/src/ItemShears.java.patch b/forge/patches/minecraft_server/net/minecraft/src/ItemShears.java.patch new file mode 100644 index 0000000000..20b399ab58 --- /dev/null +++ b/forge/patches/minecraft_server/net/minecraft/src/ItemShears.java.patch @@ -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 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 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; ++ } + }