Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package combat.enhancer.item;
- import java.util.ArrayList;
- import java.util.List;
- import scala.collection.mutable.HashMap;
- import net.minecraft.entity.Entity;
- import net.minecraft.entity.EntityLiving;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.item.EnumToolMaterial;
- import net.minecraft.item.Item;
- import net.minecraft.item.ItemStack;
- import net.minecraft.item.ItemSword;
- import net.minecraft.nbt.NBTTagCompound;
- import net.minecraft.util.AxisAlignedBB;
- import net.minecraft.util.DamageSource;
- import net.minecraft.util.Icon;
- import net.minecraft.world.World;
- public class VectorWeapon extends ItemSword {
- //Client only fields
- //public boolean isSwinging = false;
- //public int swingTimeCur = 0;
- public int swingTimeMax = 10;
- public int swingTimeCooldown = 20;
- //this is used server side, should be split up to each player otherwise potential data collisions
- public HashMap<Integer, Boolean> swingHitEntityIDs = new HashMap<Integer, Boolean>();
- public VectorWeapon(int par1, EnumToolMaterial par2EnumToolMaterial) {
- super(par1, par2EnumToolMaterial);
- // TODO Auto-generated constructor stub
- }
- @Override
- public Icon getIconFromDamage(int par1) {
- return Item.swordIron.getIconFromDamage(0);
- }
- @Override
- public boolean hitEntity(ItemStack par1ItemStack, EntityLiving par2EntityLiving, EntityLiving par3EntityLiving)
- {
- //par1ItemStack.damageItem(1, par3EntityLiving);
- //par2EntityLiving.worldObj.playSoundAtEntity(par2EntityLiving, "zc.meleehit", 1.0F, 1.0F);
- //possibly not needed
- return false;
- }
- @Override
- public int getDamageVsEntity(Entity par1Entity)
- {
- System.out.println("sdfsfsdfsdf");
- //this prevents the damage vanilla style
- return 0;
- }
- @Override
- public void onUpdate(ItemStack par1ItemStack, World par2World, Entity par3Entity, int par4, boolean par5) {
- if (par1ItemStack.stackTagCompound == null) par1ItemStack.stackTagCompound = new NBTTagCompound();
- if (par5) {
- if (!par2World.isRemote) {
- int serverSwingTime = par1ItemStack.stackTagCompound.getInteger("swingTimeCur");
- if (serverSwingTime > 0) {
- serverSwingTime--;
- par1ItemStack.stackTagCompound.setInteger("swingTimeCur", serverSwingTime);
- if (serverSwingTime == 0) {
- //end of swing
- System.out.println("SWINGED");
- swingHitEntityIDs.clear();
- } else {
- System.out.println("SWINGING");
- updateSwing(par1ItemStack, par2World, par3Entity, serverSwingTime);
- }
- } else {
- }
- }
- //System.out.println(par5);
- }
- }
- @Override
- public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) {
- if (par1ItemStack.stackTagCompound == null) par1ItemStack.stackTagCompound = new NBTTagCompound();
- int serverSwingTime = par1ItemStack.stackTagCompound.getInteger("swingTimeCur");
- if (serverSwingTime <= 0) {
- System.out.println("SWING");
- //temp
- swingTimeMax = 10;
- swingTimeCooldown = 20;
- par1ItemStack.stackTagCompound.setInteger("swingTimeCur", swingTimeMax);
- }
- System.out.println(par2World.isRemote);
- return par1ItemStack;
- }
- public void updateSwing(ItemStack par1ItemStack, World par2World, Entity par3Entity, int swingTime) {
- //assume 0 = default right to left
- int gestureType = par1ItemStack.stackTagCompound.getInteger("gestureType");
- double swingSizeDegrees = 60D;
- double swingCurDegrees = ((double)swingTime / (double)swingTimeMax) * swingSizeDegrees;
- double adjAngle = 90D + ((swingSizeDegrees / 2) - swingCurDegrees);
- System.out.println("adjAngle: " + adjAngle);
- double swingMin = 0.5D;
- double swingRes = 0.5D;
- double swingReach = 1.5D;
- for (double range = swingMin; range <= swingReach; range += swingRes) {
- //System.out.println("range: " + range);
- double dist = range;
- Entity center = par3Entity;
- double posX = (center.posX - Math.cos((-center.rotationYaw + adjAngle) * 0.01745329D) * dist);
- double posY = (center.posY/* - 0.3D - Math.sin((center.rotationPitch) / 180.0F * 3.1415927F) * dist*/);
- double posZ = (center.posZ + Math.sin((-center.rotationYaw + adjAngle) * 0.01745329D) * dist);
- //System.out.println(posX + ", " + posY + ", " + posZ);
- double aabbSize = 1.0D;
- AxisAlignedBB aabb = AxisAlignedBB.getBoundingBox(posX, posY, posZ, posX, posY, posZ).expand(aabbSize, aabbSize, aabbSize);
- List entities = par2World.getEntitiesWithinAABB(EntityLiving.class, aabb);
- for (int i = 0; i < entities.size(); i++) {
- EntityLiving entL = (EntityLiving)entities.get(i);
- if (entL != null && !entL.isDead && entL != par3Entity && !swingHitEntityIDs.contains(entL.entityId)) {
- System.out.println("hit! " + entL);
- entL.attackEntityFrom(DamageSource.causeMobDamage((EntityLiving)par3Entity), 2);
- swingHitEntityIDs.put(entL.entityId, true);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement