Added an item finder. I'll get it prettied up tomrrow.

This commit is contained in:
Lizbeth Rika committed 2014-07-31 03:45:34 +01:00
1 parent 7953c961dc
commit 743e97c141
5 files changed
+134

No files matched your search

@@ -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);
@@ -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++) {
@@ -0,0 +1,129 @@
/**
* This class was created by <Vazkii>. 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<EntityItem> 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;
}
}
@@ -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",
Binary file not shown.

After

Width:  |  Height:  |  Size: 404 B