From e0fc4010c04c6717cf90a942c8c652cf471e0849 Mon Sep 17 00:00:00 2001 From: Cheeserolls Date: Mon, 13 Apr 2015 22:31:47 +0100 Subject: [PATCH] Add scythe --- .../java/biomesoplenty/api/item/BOPItems.java | 8 + .../biomesoplenty/common/init/ModItems.java | 11 ++ .../common/item/ItemBOPScythe.java | 185 ++++++++++++++++++ .../models/item/amethyst_scythe.json | 18 ++ .../models/item/diamond_scythe.json | 18 ++ .../models/item/gold_scythe.json | 18 ++ .../models/item/iron_scythe.json | 18 ++ .../biomesoplenty/models/item/mud_scythe.json | 18 ++ .../models/item/stone_scythe.json | 18 ++ .../models/item/wood_scythe.json | 18 ++ .../textures/items/amethyst_scythe.png | Bin 0 -> 268 bytes .../textures/items/diamond_scythe.png | Bin 0 -> 273 bytes .../textures/items/gold_scythe.png | Bin 0 -> 273 bytes .../textures/items/iron_scythe.png | Bin 0 -> 268 bytes .../textures/items/mud_scythe.png | Bin 0 -> 321 bytes .../textures/items/stone_scythe.png | Bin 0 -> 270 bytes .../textures/items/wood_scythe.png | Bin 0 -> 293 bytes 17 files changed, 330 insertions(+) create mode 100644 src/main/java/biomesoplenty/common/item/ItemBOPScythe.java create mode 100644 src/main/resources/assets/biomesoplenty/models/item/amethyst_scythe.json create mode 100644 src/main/resources/assets/biomesoplenty/models/item/diamond_scythe.json create mode 100644 src/main/resources/assets/biomesoplenty/models/item/gold_scythe.json create mode 100644 src/main/resources/assets/biomesoplenty/models/item/iron_scythe.json create mode 100644 src/main/resources/assets/biomesoplenty/models/item/mud_scythe.json create mode 100644 src/main/resources/assets/biomesoplenty/models/item/stone_scythe.json create mode 100644 src/main/resources/assets/biomesoplenty/models/item/wood_scythe.json create mode 100644 src/main/resources/assets/biomesoplenty/textures/items/amethyst_scythe.png create mode 100644 src/main/resources/assets/biomesoplenty/textures/items/diamond_scythe.png create mode 100644 src/main/resources/assets/biomesoplenty/textures/items/gold_scythe.png create mode 100644 src/main/resources/assets/biomesoplenty/textures/items/iron_scythe.png create mode 100644 src/main/resources/assets/biomesoplenty/textures/items/mud_scythe.png create mode 100644 src/main/resources/assets/biomesoplenty/textures/items/stone_scythe.png create mode 100644 src/main/resources/assets/biomesoplenty/textures/items/wood_scythe.png diff --git a/src/main/java/biomesoplenty/api/item/BOPItems.java b/src/main/java/biomesoplenty/api/item/BOPItems.java index cfaff2974..5c698141f 100644 --- a/src/main/java/biomesoplenty/api/item/BOPItems.java +++ b/src/main/java/biomesoplenty/api/item/BOPItems.java @@ -66,5 +66,13 @@ public class BOPItems public static Item amethyst_shovel; public static Item amethyst_sword; + public static Item mud_scythe; + public static Item wood_scythe; + public static Item stone_scythe; + public static Item iron_scythe; + public static Item gold_scythe; + public static Item diamond_scythe; + public static Item amethyst_scythe; + } \ No newline at end of file diff --git a/src/main/java/biomesoplenty/common/init/ModItems.java b/src/main/java/biomesoplenty/common/init/ModItems.java index 7c601b5e7..bc39981ef 100644 --- a/src/main/java/biomesoplenty/common/init/ModItems.java +++ b/src/main/java/biomesoplenty/common/init/ModItems.java @@ -36,6 +36,7 @@ import net.minecraftforge.fml.common.registry.GameRegistry; import net.minecraftforge.fml.relauncher.Side; import biomesoplenty.api.block.BOPBlocks; import biomesoplenty.common.command.BOPCommand; +import biomesoplenty.common.item.ItemBOPScythe; import biomesoplenty.common.item.ItemGem; import biomesoplenty.common.item.ItemMudball; import biomesoplenty.common.item.ItemWadingBoots; @@ -139,6 +140,16 @@ public class ModItems amethyst_shovel = registerItem(new ItemSpade(amethyst_tool_material), "amethyst_shovel"); amethyst_sword = registerItem(new ItemSword(amethyst_tool_material), "amethyst_sword"); + + mud_scythe = registerItem(new ItemBOPScythe(mud_tool_material), "mud_scythe"); + wood_scythe = registerItem(new ItemBOPScythe(ToolMaterial.WOOD), "wood_scythe"); + stone_scythe = registerItem(new ItemBOPScythe(ToolMaterial.STONE), "stone_scythe"); + iron_scythe = registerItem(new ItemBOPScythe(ToolMaterial.IRON), "iron_scythe"); + gold_scythe = registerItem(new ItemBOPScythe(ToolMaterial.GOLD), "gold_scythe"); + diamond_scythe = registerItem(new ItemBOPScythe(ToolMaterial.EMERALD), "diamond_scythe"); + amethyst_scythe = registerItem(new ItemBOPScythe(amethyst_tool_material), "amethyst_scythe"); + + } public static Item registerItem(Item item, String name) diff --git a/src/main/java/biomesoplenty/common/item/ItemBOPScythe.java b/src/main/java/biomesoplenty/common/item/ItemBOPScythe.java new file mode 100644 index 000000000..9844632c3 --- /dev/null +++ b/src/main/java/biomesoplenty/common/item/ItemBOPScythe.java @@ -0,0 +1,185 @@ +/******************************************************************************* + * Copyright 2014, the Biomes O' Plenty Team + * + * This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International Public License. + * + * To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/. + ******************************************************************************/ + +package biomesoplenty.common.item; + +import biomesoplenty.api.block.BOPPlantEnums.AllPlants; +import biomesoplenty.api.item.BOPItemHelper; +import biomesoplenty.common.block.BlockBOPFlower1; +import biomesoplenty.common.block.BlockBOPFlower2; +import biomesoplenty.common.block.BlockBOPPlant; +import net.minecraft.block.Block; +import net.minecraft.block.BlockFlower; +import net.minecraft.block.material.Material; +import net.minecraft.block.state.IBlockState; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.init.Blocks; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.BlockPos; +import net.minecraft.world.World; + +public class ItemBOPScythe extends Item +{ + + protected Item.ToolMaterial theToolMaterial; + + public ItemBOPScythe(Item.ToolMaterial material) + { + this.theToolMaterial = material; + this.maxStackSize = 1; + this.setMaxDamage(material.getMaxUses()); + } + + // Scythe is strong against leaves + @Override + public float getStrVsBlock(ItemStack stack, Block block) + { + return block.getMaterial() == Material.leaves ? 15.0F : super.getStrVsBlock(stack, block); + } + + + @Override + public boolean onBlockDestroyed(ItemStack stack, World worldIn, Block blockIn, BlockPos pos, EntityLivingBase playerIn) + { + + if (blockIn == null || worldIn.getBlockState(pos).getBlock() == Blocks.air) {return false;} + + boolean isLeaves = blockIn.isLeaves(worldIn, pos); + + int radius = isLeaves ? 0 : 3; + int height = isLeaves ? 0 : 4; + if (theToolMaterial == ToolMaterial.IRON || theToolMaterial == ToolMaterial.GOLD) + { + radius = 4; + height = 4; + } + else if (theToolMaterial == ToolMaterial.EMERALD) + { + radius = 5; + height = 5; + } + else if (theToolMaterial == BOPItemHelper.amethyst_tool_material) + { + radius = 6; + height = 6; + } + + // automatically damage the item once - for the block originally destroyed + stack.damageItem(1, playerIn); + + int numberTrimmed = 0; + if (isLeaves) + { + numberTrimmed += trim(stack, playerIn, worldIn, pos, height, radius, TrimType.TRIM_LEAVES, false, 40); + } + else + { + // trim once with the corners cut + numberTrimmed += trim(stack, playerIn, worldIn, pos, height, radius, TrimType.TRIM_GRASS_AND_FLOWERS, true, 70); + if (worldIn.rand.nextInt(3) == 0) + { + // with one in 3 chance, also do another 'free' trim of a smaller radius, without the corners cut + // ('free' in the sense that it does not damage the scythe) + numberTrimmed += trim(stack, playerIn, worldIn, pos, height, radius - 1, TrimType.TRIM_GRASS_AND_FLOWERS, false, 0); + } + } + return numberTrimmed > 0; + } + + + public int trim(ItemStack stack, EntityLivingBase entity, World world, BlockPos pos, int height, int radius, TrimType trimType, boolean cutCorners, int damagePercentChance) + { + int numberTrimmed = 0; + int fortune = 0; // TODO fortune of scythe ? + + // apply to every block in a rectangle around pos + for (int dx = -radius; dx <= radius; dx++) { for (int dy = -radius; dy <= radius; dy++) { for (int dz = -radius; dz <= radius; dz++) { + if (cutCorners && (Math.abs(dx) + Math.abs(dz) >= 2 * radius)) + { + continue; + } + if (trimType.trimAtPos(world, pos.add(dx,dy,dz), fortune)) + { + numberTrimmed++; + if (world.rand.nextInt(100) < damagePercentChance) + { + stack.damageItem(1, entity); + } + } + }}} + return numberTrimmed; + } + + + public enum TrimType { + + TRIM_GRASS_AND_FLOWERS, TRIM_LEAVES; + + // return true if a block was trimmed, false otherwise + public boolean trimAtPos(World world, BlockPos pos, int fortune) + { + IBlockState state = world.getBlockState(pos); + Block block = state.getBlock(); + + switch (this) { + + case TRIM_LEAVES: + + // remove leaves + if (block.isLeaves(world, pos)) + { + block.dropBlockAsItem(world, pos, state, fortune); + world.setBlockToAir(pos); + return true; + } + return false; + + + case TRIM_GRASS_AND_FLOWERS: default: + + // TODO: remove other plants? + // shorten grass and destroy flowers + if (block instanceof BlockBOPPlant) + { + switch ((AllPlants) state.getValue(((BlockBOPPlant)block).getMyVariantProperty())) + { + case SHORTGRASS: + block.dropBlockAsItem(world, pos, state, fortune); + world.setBlockToAir(pos); + return true; + case MEDIUMGRASS: + block.dropBlockAsItem(world, pos, state, fortune); + world.setBlockState(pos, BlockBOPPlant.getVariantState(AllPlants.SHORTGRASS)); + return true; + default: + return false; + } + } + else if (block == Blocks.tallgrass) + { + block.dropBlockAsItem(world, pos, state, fortune); + world.setBlockState(pos, BlockBOPPlant.getVariantState(AllPlants.MEDIUMGRASS)); + return true; + } + else if ((block instanceof BlockFlower) || (block instanceof BlockBOPFlower1) || (block instanceof BlockBOPFlower2)) + { + block.dropBlockAsItem(world, pos, state, fortune); + world.setBlockToAir(pos); + return true; + } + return false; + + } + } + } + + + + +} \ No newline at end of file diff --git a/src/main/resources/assets/biomesoplenty/models/item/amethyst_scythe.json b/src/main/resources/assets/biomesoplenty/models/item/amethyst_scythe.json new file mode 100644 index 000000000..22391031b --- /dev/null +++ b/src/main/resources/assets/biomesoplenty/models/item/amethyst_scythe.json @@ -0,0 +1,18 @@ +{ + "parent": "builtin/generated", + "textures": { + "layer0": "biomesoplenty:items/amethyst_scythe" + }, + "display": { + "thirdperson": { + "rotation": [ 0, 90, -35 ], + "translation": [ 0, 1.25, -3.5 ], + "scale": [ 0.85, 0.85, 0.85 ] + }, + "firstperson": { + "rotation": [ 0, -135, 25 ], + "translation": [ 0, 4, 2 ], + "scale": [ 1.7, 1.7, 1.7 ] + } + } +} diff --git a/src/main/resources/assets/biomesoplenty/models/item/diamond_scythe.json b/src/main/resources/assets/biomesoplenty/models/item/diamond_scythe.json new file mode 100644 index 000000000..560d47bd4 --- /dev/null +++ b/src/main/resources/assets/biomesoplenty/models/item/diamond_scythe.json @@ -0,0 +1,18 @@ +{ + "parent": "builtin/generated", + "textures": { + "layer0": "biomesoplenty:items/diamond_scythe" + }, + "display": { + "thirdperson": { + "rotation": [ 0, 90, -35 ], + "translation": [ 0, 1.25, -3.5 ], + "scale": [ 0.85, 0.85, 0.85 ] + }, + "firstperson": { + "rotation": [ 0, -135, 25 ], + "translation": [ 0, 4, 2 ], + "scale": [ 1.7, 1.7, 1.7 ] + } + } +} diff --git a/src/main/resources/assets/biomesoplenty/models/item/gold_scythe.json b/src/main/resources/assets/biomesoplenty/models/item/gold_scythe.json new file mode 100644 index 000000000..4ea9205f5 --- /dev/null +++ b/src/main/resources/assets/biomesoplenty/models/item/gold_scythe.json @@ -0,0 +1,18 @@ +{ + "parent": "builtin/generated", + "textures": { + "layer0": "biomesoplenty:items/gold_scythe" + }, + "display": { + "thirdperson": { + "rotation": [ 0, 90, -35 ], + "translation": [ 0, 1.25, -3.5 ], + "scale": [ 0.85, 0.85, 0.85 ] + }, + "firstperson": { + "rotation": [ 0, -135, 25 ], + "translation": [ 0, 4, 2 ], + "scale": [ 1.7, 1.7, 1.7 ] + } + } +} diff --git a/src/main/resources/assets/biomesoplenty/models/item/iron_scythe.json b/src/main/resources/assets/biomesoplenty/models/item/iron_scythe.json new file mode 100644 index 000000000..7ff7cc637 --- /dev/null +++ b/src/main/resources/assets/biomesoplenty/models/item/iron_scythe.json @@ -0,0 +1,18 @@ +{ + "parent": "builtin/generated", + "textures": { + "layer0": "biomesoplenty:items/iron_scythe" + }, + "display": { + "thirdperson": { + "rotation": [ 0, 90, -35 ], + "translation": [ 0, 1.25, -3.5 ], + "scale": [ 0.85, 0.85, 0.85 ] + }, + "firstperson": { + "rotation": [ 0, -135, 25 ], + "translation": [ 0, 4, 2 ], + "scale": [ 1.7, 1.7, 1.7 ] + } + } +} diff --git a/src/main/resources/assets/biomesoplenty/models/item/mud_scythe.json b/src/main/resources/assets/biomesoplenty/models/item/mud_scythe.json new file mode 100644 index 000000000..f89f8c152 --- /dev/null +++ b/src/main/resources/assets/biomesoplenty/models/item/mud_scythe.json @@ -0,0 +1,18 @@ +{ + "parent": "builtin/generated", + "textures": { + "layer0": "biomesoplenty:items/mud_scythe" + }, + "display": { + "thirdperson": { + "rotation": [ 0, 90, -35 ], + "translation": [ 0, 1.25, -3.5 ], + "scale": [ 0.85, 0.85, 0.85 ] + }, + "firstperson": { + "rotation": [ 0, -135, 25 ], + "translation": [ 0, 4, 2 ], + "scale": [ 1.7, 1.7, 1.7 ] + } + } +} diff --git a/src/main/resources/assets/biomesoplenty/models/item/stone_scythe.json b/src/main/resources/assets/biomesoplenty/models/item/stone_scythe.json new file mode 100644 index 000000000..6feb99f48 --- /dev/null +++ b/src/main/resources/assets/biomesoplenty/models/item/stone_scythe.json @@ -0,0 +1,18 @@ +{ + "parent": "builtin/generated", + "textures": { + "layer0": "biomesoplenty:items/stone_scythe" + }, + "display": { + "thirdperson": { + "rotation": [ 0, 90, -35 ], + "translation": [ 0, 1.25, -3.5 ], + "scale": [ 0.85, 0.85, 0.85 ] + }, + "firstperson": { + "rotation": [ 0, -135, 25 ], + "translation": [ 0, 4, 2 ], + "scale": [ 1.7, 1.7, 1.7 ] + } + } +} diff --git a/src/main/resources/assets/biomesoplenty/models/item/wood_scythe.json b/src/main/resources/assets/biomesoplenty/models/item/wood_scythe.json new file mode 100644 index 000000000..be61ebdc6 --- /dev/null +++ b/src/main/resources/assets/biomesoplenty/models/item/wood_scythe.json @@ -0,0 +1,18 @@ +{ + "parent": "builtin/generated", + "textures": { + "layer0": "biomesoplenty:items/wood_scythe" + }, + "display": { + "thirdperson": { + "rotation": [ 0, 90, -35 ], + "translation": [ 0, 1.25, -3.5 ], + "scale": [ 0.85, 0.85, 0.85 ] + }, + "firstperson": { + "rotation": [ 0, -135, 25 ], + "translation": [ 0, 4, 2 ], + "scale": [ 1.7, 1.7, 1.7 ] + } + } +} diff --git a/src/main/resources/assets/biomesoplenty/textures/items/amethyst_scythe.png b/src/main/resources/assets/biomesoplenty/textures/items/amethyst_scythe.png new file mode 100644 index 0000000000000000000000000000000000000000..217ccda8dc4ccd74e7889debcc6243872f4c012e GIT binary patch literal 268 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Ea{HEjtmSN`?>!lvI6;>1s;*b z3=DkxK$!8B)5ZfpL8%hgh?3y^w370~qEv=}#LT=BJwMkFg)(D3Q$0figD*u3fvP$@ zT^vI!{Ezls!lvI6;>1s;*b z3=DkxL735kHCP2GC{^MbQ4*Y=R#Ki=l*$m0n3-3i=jR%tP-d)Ws%L0m@TF)WP*ty| zi(`m|fARv!2b;}*_xCJ3)WYb~{PFeW|6BXl|6IQ>Q*4IXDS?z;gJuVbn*#pE7ynDv z72V)v);y3VeMUgwolp4x^@_)PGa2;G8Zc~mt&vdgBkCmM8SCnh||VPo8syNt)cfPrC0d1JY8J`*R< OVGN$GelF{r5}E)kDqUUx literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/biomesoplenty/textures/items/gold_scythe.png b/src/main/resources/assets/biomesoplenty/textures/items/gold_scythe.png new file mode 100644 index 0000000000000000000000000000000000000000..89c9932ea2c73f34cbbb7c11fe3f6e58fe645891 GIT binary patch literal 273 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Ea{HEjtmSN`?>!lvI6;>1s;*b z3=Dh+K$tP>S|=w^P^!c=q9iy!t)x7$D3u`~F*C13&(AePq0Cs%RL{`B;7id$psHR^ z7sn6_|KtUd8@7i2?C)84sD;tz@apo1|If#9{MetqUw?+$DS?z;gJuVbn*#pE7ynDv z72V)v);y3VeMUgwolp4x^@_)PGa2;G8Zc~mt&vdgBkCmM8SCnh||VPo8syNt)cfPsPaY)7umssr&r PhcS4%`njxgN@xNAiP2tR literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/biomesoplenty/textures/items/iron_scythe.png b/src/main/resources/assets/biomesoplenty/textures/items/iron_scythe.png new file mode 100644 index 0000000000000000000000000000000000000000..80310fa4fdfa985a6eeee6db04060aecdac20916 GIT binary patch literal 268 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Ea{HEjtmSN`?>!lvI6;>1s;*b z3=Dh+L6~vJ#O${~L8%hgh?3y^w370~qEv=}#LT=BJwMkFg)(D3Q$0figD*u3fvP$@ zT^vI!{Ezk>!lvI6;>1s;*b z3=DjGL736~_k^`TL8%hgh?3y^w370~qEv=}#LT=BJwMkFg)(D3Q$0figD*u3fvWa; zx;Tbd_%EHfk&DTZ$7TCAp^XAAtC_b7XdgUu$?M>~unphS|J<8#bN3tG8J~-+1R~n@ z%#1bbJQ4qRmh&;wcAx4Wi>~Gw%Wz4psyP-w)A)6%nML1audY;`b zoSXPHT2F}K$DWz#5&4Y!?HM+h-rmZ%N}T_}vt!;>i{CLYNLU9KXEN}VvN1eLvuS4b z$zwQj_5)+JVyia0sQGOnhd(a)4Cdz6Uz@bPu;iIVHZ1RNxbJpJTGVCN%`IQP>;QU% N!PC{xWt~$(6985nb~yk5 literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/biomesoplenty/textures/items/stone_scythe.png b/src/main/resources/assets/biomesoplenty/textures/items/stone_scythe.png new file mode 100644 index 0000000000000000000000000000000000000000..da970304a3153613f8cde2b3736300e9e79512bc GIT binary patch literal 270 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Ea{HEjtmSN`?>!lvI6;>1s;*b z3=DjSK$uZf!>a)(C{^MbQ4*Y=R#Ki=l*$m0n3-3i=jR%tP-d)Ws%L0m@TF)WP*sSD7Smz`O_aZrB0p{v&Glu_rsU~Zf=9eGOEvHbw1X- z4w%PV>^os)>+17)3(uyO@-j*Md~fEx;`W-#6tREC&BvdWTa+^d7I$2}xBS>qpsN@> MUHx3vIVCg!0Dx;^qyPW_ literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/biomesoplenty/textures/items/wood_scythe.png b/src/main/resources/assets/biomesoplenty/textures/items/wood_scythe.png new file mode 100644 index 0000000000000000000000000000000000000000..b8cfd69ba4222dfde1b5fb47513b559047c069a8 GIT binary patch literal 293 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`jKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=85sBugD~Uq{1qucL8%hgh?3y^w370~qEv=}#LT=BJwMkFg)(D3 zQ$0figD*u3fvTo>x;Tbd_$M!rG`KGEqrYe2p%z9T=duMhGSl5Ogwi=Y1U(ErgwH6< zNHlP^IqUL2{m02fbDm`qF3zn77}WR<&3*amzv+`5hP(`#O*fg21O&1$-0XQ{wZeeu zKu)7%Lk`E8n+mfxX0=bReLgxof+hwKWx3Ovb^bBuk2Pnsz+Z^~(FY}_o# ha$?&|qXP#R7+j{5)h^$5UJ&R$22WQ%mvv4FO#u9MV8H+Y literal 0 HcmV?d00001