Some more work on adding new targets to the item finder.

This commit is contained in:
Lizbeth Rika committed 2014-07-31 16:35:45 +01:00
1 parent b44cf90a70
commit 81126d2e00
2 files changed
+67 -25

No files matched your search

@@ -16,7 +16,10 @@ import java.util.List;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.passive.EntityHorse;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.AnimalChest;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
@@ -25,14 +28,18 @@ import net.minecraft.util.MathHelper;
import vazkii.botania.common.Botania;
import vazkii.botania.common.core.helper.ItemNBTHelper;
import vazkii.botania.common.lib.LibItemNames;
import vazkii.botania.common.lib.LibObfuscation;
import baubles.api.BaubleType;
import baubles.common.container.InventoryBaubles;
import baubles.common.lib.PlayerHandler;
import baubles.common.network.PacketHandler;
import baubles.common.network.PacketSyncBauble;
import cpw.mods.fml.relauncher.ReflectionHelper;
public class ItemItemFinder extends ItemBauble {
private static final String TAG_POSITIONS = "highlightPositions";
public ItemItemFinder() {
super(LibItemNames.ITEM_FINDER);
}
@@ -40,22 +47,22 @@ public class ItemItemFinder extends ItemBauble {
@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]);
@@ -66,27 +73,53 @@ public class ItemItemFinder extends ItemBauble {
} 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());
if(e != null && Math.random() < 0.6)
Botania.proxy.wispFX(player.worldObj, e.posX + (float) (Math.random() * 0.5 - 0.25) * 0.45F, e.posY + e.height, 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(";");
List<Entity> entities = player.worldObj.getEntitiesWithinAABB(Entity.class, AxisAlignedBB.getBoundingBox(player.posX - range, player.posY - range, player.posZ - range, player.posX + range, player.posY + range, player.posZ + range));
for(Entity e : entities) {
if(e == player)
continue;
if(e instanceof EntityItem) {
EntityItem item = (EntityItem) e;
ItemStack istack = item.getEntityItem();
if(player.isSneaking() || (istack.isItemEqual(pstack) && ItemStack.areItemStackTagsEqual(istack, pstack)))
positionsBuilder.append(item.getEntityId()).append(";");
} else if(e instanceof IInventory) {
IInventory inv = (IInventory) e;
if(scanInventory(inv, pstack))
positionsBuilder.append(e.getEntityId()).append(";");
} else if(e instanceof EntityHorse) {
EntityHorse horse = (EntityHorse) e;
AnimalChest chest = ReflectionHelper.getPrivateValue(EntityHorse.class, horse, LibObfuscation.HORSE_CHEST);
if(scanInventory(chest, pstack))
positionsBuilder.append(horse.getEntityId()).append(";");
} else if(e instanceof EntityPlayer) {
EntityPlayer player_ = (EntityPlayer) e;
InventoryPlayer inv = player_.inventory;
InventoryBaubles binv = PlayerHandler.getPlayerBaubles(player_);
if(scanInventory(inv, pstack) || scanInventory(binv, pstack))
positionsBuilder.append(player_.getEntityId()).append(";");
} else if(e instanceof EntityLivingBase) {
EntityLivingBase living = (EntityLivingBase) e;
ItemStack estack = living.getEquipmentInSlot(0);
if(pstack != null && estack != null && estack.isItemEqual(pstack) && ItemStack.areItemStackTagsEqual(estack, pstack))
positionsBuilder.append(living.getEntityId()).append(";");
}
}
if(pstack != null) {
range = 12;
int x = (int) MathHelper.floor_double(player.posX);
@@ -101,18 +134,13 @@ public class ItemItemFinder extends ItemBauble {
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;
}
}
if(scanInventory(inv, pstack))
positionsBuilder.append(xp).append(",").append(yp).append(",").append(zp).append(";");
}
}
}
}
String current = ItemNBTHelper.getString(stack, TAG_POSITIONS, "");
String positions = positionsBuilder.toString();
if(!current.equals(positions)) {
@@ -120,7 +148,20 @@ public class ItemItemFinder extends ItemBauble {
PacketHandler.INSTANCE.sendToAll(new PacketSyncBauble(player, 0));
}
}
boolean scanInventory(IInventory inv, ItemStack pstack) {
if(pstack == null)
return false;
for(int l = 0; l < inv.getSizeInventory(); l++) {
ItemStack istack = inv.getStackInSlot(l);
if(istack != null && istack.isItemEqual(pstack) && ItemStack.areItemStackTagsEqual(istack, pstack))
return true;
}
return false;
}
@Override
public BaubleType getBaubleType(ItemStack arg0) {
return BaubleType.AMULET;
@@ -47,6 +47,7 @@ public final class LibObfuscation {
// EntityHorse
public static final String[] HORSE_JUMP_STRENGTH = new String[] { "horseJumpStrength", "field_110271_bv", "bv" };
public static final String[] HORSE_CHEST = new String[] { "horseChest", "field_110296_bG", "bG" };
// PlayerControllerMP
public static final String[] NET_CLIENT_HANDLER = new String[] { "netClientHandler", "field_78774_b", "b" };