Add scythe
|
@ -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;
|
||||
|
||||
|
||||
}
|
|
@ -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)
|
||||
|
|
185
src/main/java/biomesoplenty/common/item/ItemBOPScythe.java
Normal file
|
@ -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;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -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 ]
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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 ]
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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 ]
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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 ]
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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 ]
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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 ]
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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 ]
|
||||
}
|
||||
}
|
||||
}
|
After Width: | Height: | Size: 268 B |
After Width: | Height: | Size: 273 B |
After Width: | Height: | Size: 273 B |
After Width: | Height: | Size: 268 B |
After Width: | Height: | Size: 321 B |
After Width: | Height: | Size: 270 B |
After Width: | Height: | Size: 293 B |