From 743e97c1416ca2182098c68792fbc50afea96e5c Mon Sep 17 00:00:00 2001 From: Lizbeth Rika Date: Thu, 31 Jul 2014 03:45:34 +0100 Subject: [PATCH] Added an item finder. I'll get it prettied up tomrrow. --- .../common/core/BotaniaCreativeTab.java | 1 + .../vazkii/botania/common/item/ModItems.java | 3 + .../item/equipment/bauble/ItemItemFinder.java | 129 ++++++++++++++++++ .../botania/common/lib/LibItemNames.java | 1 + .../botania/textures/items/itemFinder.png | Bin 0 -> 404 bytes 5 files changed, 134 insertions(+) create mode 100644 MODSRC/vazkii/botania/common/item/equipment/bauble/ItemItemFinder.java create mode 100644 resources/assets/botania/textures/items/itemFinder.png diff --git a/MODSRC/vazkii/botania/common/core/BotaniaCreativeTab.java b/MODSRC/vazkii/botania/common/core/BotaniaCreativeTab.java index c78cf18e3..382a6c938 100644 --- a/MODSRC/vazkii/botania/common/core/BotaniaCreativeTab.java +++ b/MODSRC/vazkii/botania/common/core/BotaniaCreativeTab.java @@ -207,6 +207,7 @@ public final class BotaniaCreativeTab extends CreativeTabs { addItem(ModItems.travelBelt); addItem(ModItems.superTravelBelt); addItem(ModItems.knockbackBelt); + addItem(ModItems.itemFinder); addItem(ModItems.icePendant); addItem(ModItems.lavaPendant); addItem(ModItems.goldLaurel); diff --git a/MODSRC/vazkii/botania/common/item/ModItems.java b/MODSRC/vazkii/botania/common/item/ModItems.java index 610cbd200..284021ce8 100644 --- a/MODSRC/vazkii/botania/common/item/ModItems.java +++ b/MODSRC/vazkii/botania/common/item/ModItems.java @@ -36,6 +36,7 @@ import vazkii.botania.common.item.equipment.bauble.ItemGoldenLaurel; import vazkii.botania.common.item.equipment.bauble.ItemGreaterAuraRing; import vazkii.botania.common.item.equipment.bauble.ItemGreaterManaRing; import vazkii.botania.common.item.equipment.bauble.ItemIcePendant; +import vazkii.botania.common.item.equipment.bauble.ItemItemFinder; import vazkii.botania.common.item.equipment.bauble.ItemKnockbackBelt; import vazkii.botania.common.item.equipment.bauble.ItemLavaPendant; import vazkii.botania.common.item.equipment.bauble.ItemMagnetRing; @@ -142,6 +143,7 @@ public final class ModItems { public static Item virus; public static Item reachRing; public static Item skyDirtRod; + public static Item itemFinder; public static void init() { lexicon = new ItemLexicon(); @@ -222,6 +224,7 @@ public final class ModItems { virus = new ItemVirus(); reachRing = new ItemReachRing(); skyDirtRod = new ItemSkyDirtRod(); + itemFinder = new ItemItemFinder(); OreDictionary.registerOre(LibOreDict.LEXICON, lexicon); for(int i = 0; i < 16; i++) { diff --git a/MODSRC/vazkii/botania/common/item/equipment/bauble/ItemItemFinder.java b/MODSRC/vazkii/botania/common/item/equipment/bauble/ItemItemFinder.java new file mode 100644 index 000000000..221fc92cd --- /dev/null +++ b/MODSRC/vazkii/botania/common/item/equipment/bauble/ItemItemFinder.java @@ -0,0 +1,129 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under a + * Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License + * (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB) + * + * File Created @ [Jul 31, 2014, 12:59:16 AM (GMT)] + */ +package vazkii.botania.common.item.equipment.bauble; + +import java.util.List; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.util.MathHelper; +import vazkii.botania.common.Botania; +import vazkii.botania.common.core.helper.ItemNBTHelper; +import vazkii.botania.common.lib.LibItemNames; +import baubles.api.BaubleType; +import baubles.common.network.PacketHandler; +import baubles.common.network.PacketSyncBauble; + +public class ItemItemFinder extends ItemBauble { + + private static final String TAG_POSITIONS = "highlightPositions"; + + public ItemItemFinder() { + super(LibItemNames.ITEM_FINDER); + } + + @Override + public void onWornTick(ItemStack stack, EntityLivingBase player) { + super.onWornTick(stack, player); + + if(!(player instanceof EntityPlayer)) + return; + + if(player.worldObj.isRemote) + tickClient(stack, (EntityPlayer) player); + else tickServer(stack, (EntityPlayer) player); + } + + public void tickClient(ItemStack stack, EntityPlayer player) { + String pos = ItemNBTHelper.getString(stack, TAG_POSITIONS, ""); + String[] tokens = pos.split(";"); + for(String token : tokens) { + if(token.isEmpty()) + continue; + + if(token.contains(",")) { + String[] tokens_ = token.split(","); + int x = Integer.parseInt(tokens_[0]); + int y = Integer.parseInt(tokens_[1]); + int z = Integer.parseInt(tokens_[2]); + float m = 0.08F; + Botania.proxy.wispFX(player.worldObj, x + (float) Math.random(), y + 0.5, z + (float) Math.random(), 0.2F * (float) Math.random(), 1F, 0.2F * (float) Math.random(), 0.15F + 0.05F * (float) Math.random(), m * (float) (Math.random() - 0.5), m * (float) (Math.random() - 0.5), m * (float) (Math.random() - 0.5)); + } else { + int id = Integer.parseInt(token); + Entity e = player.worldObj.getEntityByID(id); + if(e != null) + if(Math.random() < 0.6) + Botania.proxy.wispFX(player.worldObj, e.posX + (float) (Math.random() * 0.5 - 0.25) * 0.45F, e.posY + 0.2, e.posZ + (float) (Math.random() * 0.5 - 0.25) * 0.45F, 0.2F * (float) Math.random(), 1F, 0.2F * (float) Math.random(), 0.15F + 0.05F * (float) Math.random(), -0.05F - 0.03F * (float) Math.random()); + } + } + } + + public void tickServer(ItemStack stack, EntityPlayer player) { + ItemStack pstack = player.getCurrentEquippedItem(); + StringBuilder positionsBuilder = new StringBuilder(); + + if(pstack != null || player.isSneaking()) { + int range = 24; + + List items = player.worldObj.getEntitiesWithinAABB(EntityItem.class, AxisAlignedBB.getBoundingBox(player.posX - range, player.posY - range, player.posZ - range, player.posX + range, player.posY + range, player.posZ + range)); + for(EntityItem item : items) { + ItemStack istack = item.getEntityItem(); + if(player.isSneaking() || (istack.isItemEqual(pstack) && ItemStack.areItemStackTagsEqual(istack, pstack))) + positionsBuilder.append(item.getEntityId()).append(";"); + } + + if(pstack != null) { + range = 12; + int x = (int) MathHelper.floor_double(player.posX); + int y = (int) MathHelper.floor_double(player.posY); + int z = (int) MathHelper.floor_double(player.posZ); + for(int i = -range; i < range + 1; i++) + for(int j = -range; j < range + 1; j++) + for(int k = -range; k < range + 1; k++) { + int xp = x + i; + int yp = y + j; + int zp = z + k; + TileEntity tile = player.worldObj.getTileEntity(xp, yp, zp); + if(tile != null && tile instanceof IInventory) { + IInventory inv = (IInventory) tile; + for(int l = 0; l < inv.getSizeInventory(); l++) { + ItemStack istack = inv.getStackInSlot(l); + if(istack != null && istack.isItemEqual(pstack) && ItemStack.areItemStackTagsEqual(istack, pstack)) { + positionsBuilder.append(xp).append(",").append(yp).append(",").append(zp).append(";"); + break; + } + } + } + } + } + } + + String current = ItemNBTHelper.getString(stack, TAG_POSITIONS, ""); + String positions = positionsBuilder.toString(); + if(!current.equals(positions)) { + ItemNBTHelper.setString(stack, TAG_POSITIONS, positions); + PacketHandler.INSTANCE.sendToAll(new PacketSyncBauble(player, 0)); + } + } + + @Override + public BaubleType getBaubleType(ItemStack arg0) { + return BaubleType.AMULET; + } + +} diff --git a/MODSRC/vazkii/botania/common/lib/LibItemNames.java b/MODSRC/vazkii/botania/common/lib/LibItemNames.java index 280fc6ceb..98429b4ae 100644 --- a/MODSRC/vazkii/botania/common/lib/LibItemNames.java +++ b/MODSRC/vazkii/botania/common/lib/LibItemNames.java @@ -91,6 +91,7 @@ public final class LibItemNames { public static final String MANASTEEL_HELM_R = "manasteelHelmReveal"; public static final String TERRASTEEL_HELM_R = "terrasteelHelmReveal"; public static final String ELEMENTIUM_HELM_R = "elementiumHelmReveal"; + public static final String ITEM_FINDER = "itemFinder"; public static final String[] LENS_NAMES = new String[] { "lensNormal", diff --git a/resources/assets/botania/textures/items/itemFinder.png b/resources/assets/botania/textures/items/itemFinder.png new file mode 100644 index 0000000000000000000000000000000000000000..d60695681daebe6f8c273e5a22b9144c4eb51e59 GIT binary patch literal 404 zcmV;F0c-w=P)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D02p*dSaefwW^{L9 za%BK;VQFr3E^cLXAT%y8E;9S!r^WyP0R>4!K~y+Tosm6m!ax*+U&kR*S)z5}4i`>? zdq+y+62+1ak^`hc@+}Ztgcd2{02Jxz(96!SZ?*AHf-}-5?0qw{50J7f|3%Q)@DU`9 z3RKm<&Cp*3UDpLD1o}W>9Z!-ZIt2r!xBwfNscl=W>zc@`glF)hC@#QZ(==LDl@>+8 zAlToI;W^K9bzZ`fegVj`jOMd`5!ozM4y!xv9CPyy3fzxH)29o*Uw5Rwe2}NpTPT5# z1tu%NkSpU>2ZHkAKiBRIY?ms}GG4$9+z>b6M!>Lr1%%URgQ<0gf*5H5u0000