From 04d54ad29ec5782d69bc59e70e83ca3322baef1f Mon Sep 17 00:00:00 2001 From: Cheeserolls Date: Sat, 18 Apr 2015 10:36:44 +0100 Subject: [PATCH] Add dart and dart blower items --- .../java/biomesoplenty/api/item/BOPItems.java | 3 + .../biomesoplenty/common/init/ModItems.java | 5 ++ .../biomesoplenty/common/item/ItemDart.java | 76 ++++++++++++++++++ .../common/item/ItemDartBlower.java | 76 ++++++++++++++++++ .../biomesoplenty/models/item/dart.json | 18 +++++ .../models/item/dart_blower.json | 18 +++++ .../biomesoplenty/models/item/poisondart.json | 18 +++++ .../biomesoplenty/textures/items/dart.png | Bin 0 -> 266 bytes .../textures/items/dart_blower.png | Bin 0 -> 306 bytes .../textures/items/poisondart.png | Bin 0 -> 301 bytes 10 files changed, 214 insertions(+) create mode 100644 src/main/java/biomesoplenty/common/item/ItemDart.java create mode 100644 src/main/java/biomesoplenty/common/item/ItemDartBlower.java create mode 100644 src/main/resources/assets/biomesoplenty/models/item/dart.json create mode 100644 src/main/resources/assets/biomesoplenty/models/item/dart_blower.json create mode 100644 src/main/resources/assets/biomesoplenty/models/item/poisondart.json create mode 100644 src/main/resources/assets/biomesoplenty/textures/items/dart.png create mode 100644 src/main/resources/assets/biomesoplenty/textures/items/dart_blower.png create mode 100644 src/main/resources/assets/biomesoplenty/textures/items/poisondart.png diff --git a/src/main/java/biomesoplenty/api/item/BOPItems.java b/src/main/java/biomesoplenty/api/item/BOPItems.java index 5c698141f..3551f6d3e 100644 --- a/src/main/java/biomesoplenty/api/item/BOPItems.java +++ b/src/main/java/biomesoplenty/api/item/BOPItems.java @@ -74,5 +74,8 @@ public class BOPItems public static Item diamond_scythe; public static Item amethyst_scythe; + public static Item dart; + public static Item dart_blower; + } \ 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 bc39981ef..1b5ed70eb 100644 --- a/src/main/java/biomesoplenty/common/init/ModItems.java +++ b/src/main/java/biomesoplenty/common/init/ModItems.java @@ -37,6 +37,8 @@ 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.ItemDart; +import biomesoplenty.common.item.ItemDartBlower; import biomesoplenty.common.item.ItemGem; import biomesoplenty.common.item.ItemMudball; import biomesoplenty.common.item.ItemWadingBoots; @@ -61,6 +63,9 @@ public class ModItems ash = registerItem(new Item(), "ash"); berries = registerItem(new ItemFood(1, 0.1F, false), "berries"); wildcarrots = registerItem(new ItemFood(3, 0.5F, false), "wildcarrots"); + + dart = registerItem(new ItemDart(), "dart"); + dart_blower = registerItem(new ItemDartBlower(), "dart_blower"); // armor diff --git a/src/main/java/biomesoplenty/common/item/ItemDart.java b/src/main/java/biomesoplenty/common/item/ItemDart.java new file mode 100644 index 000000000..5b80ae360 --- /dev/null +++ b/src/main/java/biomesoplenty/common/item/ItemDart.java @@ -0,0 +1,76 @@ +/******************************************************************************* + * 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 java.util.List; + +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IStringSerializable; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + + +public class ItemDart extends Item +{ + + public static enum DartType implements IStringSerializable + { + // in order of preference when selecting from inventory to use in the dart blower, items on the right are preferred to items on the left + DART, POISONDART; + @Override + public String getName() + { + return this.name().toLowerCase(); + } + @Override + public String toString() + { + return this.getName(); + } + public static DartType fromMeta(int meta) + { + return DartType.values()[meta % DartType.values().length]; + } + }; + + public ItemDart() + { + this.setHasSubtypes(true); + this.setMaxDamage(0); + } + + // add all the gem types as separate items in the creative tab + @Override + @SideOnly(Side.CLIENT) + public void getSubItems(Item itemIn, CreativeTabs tab, List subItems) + { + for (DartType dartType : DartType.values()) + { + subItems.add(new ItemStack(itemIn, 1, dartType.ordinal())); + } + } + + // default behavior in Item is to return 0, but the meta value is important here because it determines which dart type to use + @Override + public int getMetadata(int metadata) + { + return metadata; + } + + // get the correct name for this item by looking up the meta value in the DartType enum + @Override + public String getUnlocalizedName(ItemStack stack) + { + return "item." + DartType.fromMeta(stack.getMetadata()).toString(); + } + + +} diff --git a/src/main/java/biomesoplenty/common/item/ItemDartBlower.java b/src/main/java/biomesoplenty/common/item/ItemDartBlower.java new file mode 100644 index 000000000..7f7189a3c --- /dev/null +++ b/src/main/java/biomesoplenty/common/item/ItemDartBlower.java @@ -0,0 +1,76 @@ +/******************************************************************************* + * 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.item.BOPItems; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.projectile.EntitySnowball; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; + + +public class ItemDartBlower extends Item +{ + + public ItemDartBlower() + { + this.maxStackSize = 1; + this.setMaxDamage(63); + } + + @Override + public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn) + { + if (worldIn.isRemote) {return itemStackIn;} + boolean isCreative = playerIn.capabilities.isCreativeMode; + + if (isCreative || playerIn.inventory.hasItem(BOPItems.dart)) + { + // TODO: implement EntityDart EntityDart entityDart = new EntityDart(worldIn, playerIn, 1.0F); + EntitySnowball entityDart = new EntitySnowball(worldIn, playerIn); + itemStackIn.damageItem(1, playerIn); + worldIn.playSoundAtEntity(playerIn, "random.bow", 1.0F, 1.75F); + + // look for the best dart in inventory - find out which slot it's in + int bestDartSlot = -1; + ItemDart.DartType bestDart = ItemDart.DartType.DART; + for (int k = 0; k < playerIn.inventory.mainInventory.length; ++k) + { + ItemStack current = playerIn.inventory.mainInventory[k]; + if (current != null && current.getItem()==BOPItems.dart) + { + ItemDart.DartType currentDart = ItemDart.DartType.fromMeta(current.getMetadata()); + if (currentDart.ordinal() >= bestDart.ordinal()) + { + bestDart = currentDart; + bestDartSlot = k; + } + } + } + + // TODO: entityDart.setDartType(bestDart); + + if (isCreative) + { + worldIn.spawnEntityInWorld(entityDart); + } + else if (bestDartSlot >= 0) + { + worldIn.spawnEntityInWorld(entityDart); + playerIn.inventory.decrStackSize(bestDartSlot, 1); + } + } + + return itemStackIn; + } + + +} diff --git a/src/main/resources/assets/biomesoplenty/models/item/dart.json b/src/main/resources/assets/biomesoplenty/models/item/dart.json new file mode 100644 index 000000000..49e25f712 --- /dev/null +++ b/src/main/resources/assets/biomesoplenty/models/item/dart.json @@ -0,0 +1,18 @@ +{ + "parent": "builtin/generated", + "textures": { + "layer0": "biomesoplenty:items/dart" + }, + "display": { + "thirdperson": { + "rotation": [ -90, 0, 0 ], + "translation": [ 0, 1, -3 ], + "scale": [ 0.55, 0.55, 0.55 ] + }, + "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/dart_blower.json b/src/main/resources/assets/biomesoplenty/models/item/dart_blower.json new file mode 100644 index 000000000..b29aa4d71 --- /dev/null +++ b/src/main/resources/assets/biomesoplenty/models/item/dart_blower.json @@ -0,0 +1,18 @@ +{ + "parent": "builtin/generated", + "textures": { + "layer0": "biomesoplenty:items/dart_blower" + }, + "display": { + "thirdperson": { + "rotation": [ -90, 0, 0 ], + "translation": [ 0, 1, -3 ], + "scale": [ 0.55, 0.55, 0.55 ] + }, + "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/poisondart.json b/src/main/resources/assets/biomesoplenty/models/item/poisondart.json new file mode 100644 index 000000000..8941cfa72 --- /dev/null +++ b/src/main/resources/assets/biomesoplenty/models/item/poisondart.json @@ -0,0 +1,18 @@ +{ + "parent": "builtin/generated", + "textures": { + "layer0": "biomesoplenty:items/poisondart" + }, + "display": { + "thirdperson": { + "rotation": [ -90, 0, 0 ], + "translation": [ 0, 1, -3 ], + "scale": [ 0.55, 0.55, 0.55 ] + }, + "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/dart.png b/src/main/resources/assets/biomesoplenty/textures/items/dart.png new file mode 100644 index 0000000000000000000000000000000000000000..c606f3034232db1c3690cb8ca428496d08d32984 GIT binary patch literal 266 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*u3fvVa( zT^vI!{F5aTAADQ-_`hStxhH-90~8-I_&h#1_w_&jH(9^rpS<BIZ2!Xn*D|%bJNAXWfc_9%xnbI!{&CNqX56IISCT+lknbB)Jn z$%zQro?b~00|pj{wg!_!Jc>7ge#%seHs%RfGPAFtk&z){ZKnC;;Dp^k7cqFc`njxg HN@xNAAz59N literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/biomesoplenty/textures/items/dart_blower.png b/src/main/resources/assets/biomesoplenty/textures/items/dart_blower.png new file mode 100644 index 0000000000000000000000000000000000000000..7c0fbb8b91ddc257c7472283dc9c0b774b8b9ac9 GIT binary patch literal 306 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*u3fvVPd zx;Tbd_$M#W+Hh^+AO6%yd=9ft2iN?|KKXHS9*0M8QNz*yJqFbq6mP^FT7J6ye!>K` z8H$#H=QP?HOsuEx_@|!1aY9uv@7MosVVeVO4L=OdP7|D#U?yO2z#xplnB|$Qfc)$< ziDO(FD%mp_ZfLvgWMXlcbzv`a5vPt0hZF!lvI6;>1s;*b z3=Dh+K$tP>S|=w^P^!c=q9iy!t)x7$D3u`~F*C13&(AePq0Cs%RL{`B;7id$psJOg zE{-7<{>c)F502e3{_j}fd->4+0L4cK&K_3(fB#0+um2k@cmLO4JM;5?tql`QnDgST z{{8=O>+FB=YySV^MJ71TdUkHnhW`pS8&|*le`eae|DO969+76a6fx()NBc8(pVUv- zZd^EPcJi}-?1?F7AIb0>xyf~D#=AgXGlnG-Rn96rP?Bc9#$$Bkwuw|v>kUy)Zj%X$ v3cUu-9%c+I4zo^N<6#!bT&A3mz`#(jH@p4+tix_VM>BZ3`njxgN@xNAKoEEc literal 0 HcmV?d00001