aether-legacy/src/main/java/com/legacy/aether/items/weapons/ItemValkyrieLance.java

98 lines
2.3 KiB
Java
Raw Normal View History

2017-11-28 05:02:38 +01:00
package com.legacy.aether.items.weapons;
2016-12-17 16:28:16 +01:00
import java.util.List;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
2018-12-07 05:33:43 +01:00
import net.minecraft.item.EnumAction;
2017-07-07 03:07:09 +02:00
import net.minecraft.item.EnumRarity;
2016-12-17 16:28:16 +01:00
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemSword;
2018-12-07 05:33:43 +01:00
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.Vec3;
2016-12-17 16:28:16 +01:00
2017-11-28 05:02:38 +01:00
import com.legacy.aether.items.ItemsAether;
import com.legacy.aether.registry.creative_tabs.AetherCreativeTabs;
2016-12-17 16:28:16 +01:00
2018-12-07 06:32:48 +01:00
public class ItemValkyrieLance extends ItemSword {
2016-12-17 16:28:16 +01:00
2018-12-07 06:32:48 +01:00
public ItemValkyrieLance() {
2018-12-07 05:33:43 +01:00
super(ToolMaterial.EMERALD);
2016-12-17 16:28:16 +01:00
this.setCreativeTab(AetherCreativeTabs.weapons);
}
2018-12-07 05:33:43 +01:00
@Override
2018-12-07 06:32:48 +01:00
public EnumAction getItemUseAction(ItemStack stack) {
return EnumAction.none;
}
2018-12-07 05:33:43 +01:00
2017-07-07 03:07:09 +02:00
@Override
2018-12-07 06:32:48 +01:00
public EnumRarity getRarity(ItemStack stack) {
return ItemsAether.aether_loot;
}
2017-07-07 03:07:09 +02:00
2016-12-17 16:28:16 +01:00
@Override
2018-12-07 05:33:43 +01:00
@SuppressWarnings("unchecked")
2018-12-07 06:32:48 +01:00
public boolean onEntitySwing(EntityLivingBase entityLiving, ItemStack stack) {
if (!(entityLiving instanceof EntityPlayer)) {
2016-12-17 16:28:16 +01:00
return false;
}
EntityPlayer player = (EntityPlayer) entityLiving;
2018-12-07 05:33:43 +01:00
Vec3 playerVision = player.getLookVec();
AxisAlignedBB reachDistance = player.boundingBox.expand(10.0D, 10.0D, 10.0D);
2016-12-17 16:28:16 +01:00
List<Entity> locatedEntities = player.worldObj.getEntitiesWithinAABB(Entity.class, reachDistance);
Entity found = null;
double foundLen = 0.0D;
2018-12-07 06:32:48 +01:00
for (Object o : locatedEntities) {
if (o == player) {
2016-12-17 16:28:16 +01:00
continue;
}
Entity ent = (Entity) o;
2018-12-07 06:32:48 +01:00
if (!ent.canBeCollidedWith()) {
2016-12-17 16:28:16 +01:00
continue;
}
2018-12-07 05:33:43 +01:00
Vec3 vec = Vec3.createVectorHelper(ent.posX - player.posX, ent.boundingBox.minY + ent.height / 2f - player.posY - player.getEyeHeight(), ent.posZ - player.posZ);
2016-12-17 16:28:16 +01:00
double len = vec.lengthVector();
2018-12-07 06:32:48 +01:00
if (len > 10.0F) {
2016-12-17 16:28:16 +01:00
continue;
}
vec = vec.normalize();
double dot = playerVision.dotProduct(vec);
2018-12-07 06:32:48 +01:00
if (dot < 1.0 - 0.125 / len || !player.canEntityBeSeen(ent)) {
2016-12-17 16:28:16 +01:00
continue;
}
2018-12-07 06:32:48 +01:00
if (foundLen == 0.0 || len < foundLen) {
2016-12-17 16:28:16 +01:00
found = ent;
foundLen = len;
}
}
2018-12-07 06:32:48 +01:00
if (found != null && player.ridingEntity != found) {
2016-12-17 16:28:16 +01:00
stack.damageItem(1, player);
player.attackTargetEntityWithCurrentItem(found);
}
return false;
}
@Override
2018-12-07 06:32:48 +01:00
public boolean getIsRepairable(ItemStack repairingItem, ItemStack material) {
2016-12-17 16:28:16 +01:00
return false;
}
}