From 4e4fa7b3d30e4b3147a704c9229cad06fd5ae388 Mon Sep 17 00:00:00 2001 From: Adubbz Date: Sat, 20 Apr 2013 11:42:26 +1000 Subject: [PATCH] Added an API for changing the speed of shears against blocks --- src/minecraft/biomesoplenty/api/Blocks.java | 9 +++ .../biomesoplenty/configuration/BOPItems.java | 45 ++++++++++++++ .../items/overrides/ItemShears.java | 62 +++++++++++++++++++ 3 files changed, 116 insertions(+) create mode 100644 src/minecraft/biomesoplenty/items/overrides/ItemShears.java diff --git a/src/minecraft/biomesoplenty/api/Blocks.java b/src/minecraft/biomesoplenty/api/Blocks.java index 7dea8d8cd..c649ddc0d 100644 --- a/src/minecraft/biomesoplenty/api/Blocks.java +++ b/src/minecraft/biomesoplenty/api/Blocks.java @@ -1,5 +1,9 @@ package biomesoplenty.api; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + import com.google.common.base.Optional; import net.minecraft.block.Block; @@ -75,4 +79,9 @@ public class Blocks public static Optional quicksand = Optional.absent(); public static Optional promisedPortal = Optional.absent(); + + /** + * Populated by Biomes O Plenty with default Biomes O Plenty leaves. Add additional leaves here (E.g. "Blocks.shearBlockIds.put(acaciaLeaves.blockID, 15.0F);") + */ + public static Map shearBlockIds = new HashMap(); } diff --git a/src/minecraft/biomesoplenty/configuration/BOPItems.java b/src/minecraft/biomesoplenty/configuration/BOPItems.java index 4f5bc9411..d3eff99b1 100644 --- a/src/minecraft/biomesoplenty/configuration/BOPItems.java +++ b/src/minecraft/biomesoplenty/configuration/BOPItems.java @@ -1,5 +1,8 @@ package biomesoplenty.configuration; +import java.util.Map; +import java.util.logging.Level; + import biomesoplenty.BiomesOPlenty; import biomesoplenty.api.Blocks; import biomesoplenty.armor.ArmorAmethyst; @@ -22,8 +25,10 @@ import biomesoplenty.items.ItemMediumGrass; import biomesoplenty.items.ItemShortGrass; import biomesoplenty.items.ItemShroomPowder; import biomesoplenty.items.ItemSprout; +import biomesoplenty.items.overrides.ItemShears; import net.minecraft.block.Block; +import net.minecraft.creativetab.CreativeTabs; import net.minecraft.item.EnumArmorMaterial; import net.minecraft.item.EnumToolMaterial; import net.minecraft.item.Item; @@ -33,10 +38,14 @@ import net.minecraft.util.WeightedRandomChestContent; import net.minecraftforge.common.ChestGenHooks; import net.minecraftforge.common.EnumHelper; import net.minecraftforge.common.MinecraftForge; +import cpw.mods.fml.common.FMLLog; +import cpw.mods.fml.common.registry.GameData; import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.common.registry.LanguageRegistry; +import cpw.mods.fml.relauncher.ReflectionHelper; public class BOPItems { + public static Item shears; public static Item shroomPowder; public static Item mudBall; @@ -85,6 +94,39 @@ public class BOPItems { public static EnumArmorMaterial EnumArmorMaterialAmethyst; public static EnumToolMaterial EnumToolMaterialAmethyst; + public static int clearItem(Item var1) + { + return clearItem(var1.itemID); + } + + public static int clearItem(Item var1, boolean var2) + { + return clearItem(var1.itemID, var2); + } + + public static int clearItem(int var1) + { + return clearItem(var1, true); + } + + public static int clearItem(int var1, boolean var2) + { + if (var1 < 0 || var1 >= Item.itemsList.length) + { + FMLLog.log(Level.SEVERE, "BiomesOPlenty has an invalid item ID (%i)", new Object[] {Integer.valueOf(var1)}); + } + + if (var2 && Item.itemsList[var1] == null) + { + FMLLog.log(Level.WARNING, "BiomesOPlenty tried clearing an already cleared item (%i)", new Object[] {Integer.valueOf(var1)}); + } + + Item.itemsList[var1] = null; + Map var3 = (Map)ReflectionHelper.getPrivateValue(GameData.class, null, new String[] {"idMap"}); + var3.remove(Integer.valueOf(var1)); + return var1 - 256; + } + public static void init() { // Material declaration @@ -93,6 +135,9 @@ public class BOPItems { EnumArmorMaterialAmethyst = EnumHelper.addArmorMaterial("AMETHYST", 40, new int[]{6, 12, 10, 6}, 20); EnumToolMaterialAmethyst = EnumHelper.addToolMaterial("AMETHYST", 4, 2013, 15.0F, 5, 16); + //Override Items + shears = (new ItemShears(clearItem(Item.shears))).setUnlocalizedName("shears").setCreativeTab(CreativeTabs.tabTools); + // Item declaration shroomPowder = (new ItemShroomPowder(BOPConfiguration.shroomPowderID, 1, 0.5F, false)).setPotionEffect(Potion.confusion.id, 30, 0, 0.6F).setAlwaysEdible().setUnlocalizedName("shroomPowder").setCreativeTab(BiomesOPlenty.tabBiomesOPlenty); mudBall = (new ItemBOP(BOPConfiguration.mudBallID, 0)).setUnlocalizedName("mudBall").setCreativeTab(BiomesOPlenty.tabBiomesOPlenty); diff --git a/src/minecraft/biomesoplenty/items/overrides/ItemShears.java b/src/minecraft/biomesoplenty/items/overrides/ItemShears.java new file mode 100644 index 000000000..f295a97e9 --- /dev/null +++ b/src/minecraft/biomesoplenty/items/overrides/ItemShears.java @@ -0,0 +1,62 @@ +package biomesoplenty.items.overrides; + +import java.util.ArrayList; + +import cpw.mods.fml.common.registry.LanguageRegistry; + +import biomesoplenty.api.Blocks; +import biomesoplenty.configuration.BOPBlocks; +import net.minecraft.block.Block; +import net.minecraft.block.material.Material; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.entity.passive.EntityCow; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemBucket; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumMovingObjectType; +import net.minecraft.util.MovingObjectPosition; +import net.minecraft.world.World; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.event.Event; +import net.minecraftforge.event.entity.player.FillBucketEvent; +import net.minecraftforge.oredict.OreDictionary; + +public class ItemShears extends net.minecraft.item.ItemShears +{ + public ItemShears(int var1) + { + super(var1); + this.maxStackSize = 1; + } + + + /** + * Returns the strength of the stack against a given block. 1.0F base, (Quality+1)*2 if correct blocktype, 1.5F if + * sword + */ + @Override + public float getStrVsBlock(ItemStack par1ItemStack, Block par2Block) + { + Float Strength = null; + + if (Blocks.shearBlockIds.get(par2Block.blockID) != null) + { + Strength = Float.parseFloat(Blocks.shearBlockIds.get(par2Block.blockID).toString()); + } + else if (par2Block.blockID == Block.web.blockID | par2Block.blockID == Block.leaves.blockID) + { + Strength = 15.0F; + } + else if (par2Block.blockID == Block.cloth.blockID) + { + Strength = 5.0F; + } + else + { + Strength = super.getStrVsBlock(par1ItemStack, par2Block); + } + + return Strength; + } +}