Added first cut of 'glide' upgrade for DS chestplate.

This commit is contained in:
CrazyPants committed 2014-06-27 01:54:17 +08:00
1 parent 5cc1819c39
commit ceccfe5d6a
6 files changed
+147 -18

No files matched your search

@@ -10,14 +10,20 @@ import net.minecraft.entity.ai.attributes.IAttributeInstance;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.MovementInput;
import net.minecraft.util.Vec3;
import cofh.api.energy.IEnergyContainerItem;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.TickEvent;
import cpw.mods.fml.common.gameevent.TickEvent.Phase;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import crazypants.enderio.Config;
import crazypants.enderio.EnderIO;
import crazypants.enderio.network.PacketHandler;
import crazypants.util.Util;
import crazypants.vecmath.VecmathUtil;
import crazypants.vecmath.Vector3d;
import crazypants.vecmath.Vector4d;
public class DarkSteelController {
@@ -50,16 +56,81 @@ public class DarkSteelController {
public void onPlayerTick(TickEvent.PlayerTickEvent event) {
EntityPlayer player = event.player;
//TODO: I am doing this at Phase.START and Phase.END
//boots step height
ItemStack boots = player.getEquipmentInSlot(1);
JumpUpgrade jumpUpgrade = JumpUpgrade.loadFromItem(boots);
if(jumpUpgrade != null && boots != null && boots.getItem() == EnderIO.itemDarkSteelBoots) {
player.stepHeight = 1.0023F;
} else if(player.stepHeight == 1.0023F) {
player.stepHeight = 0.5001F;
}
updateStepHeight(player);
//leggings
updateSpeed(player);
//sword
updateSword(player);
if(event.phase == Phase.END) {
updateGlide(player);
}
}
private void updateGlide(EntityPlayer player) {
ItemStack chestPlate = player.getEquipmentInSlot(3);
GlideUpgrade glideUpgrade = GlideUpgrade.loadFromItem(chestPlate);
if(glideUpgrade == null) {
return;
}
if(!player.onGround && player.motionY < 0 && !player.isSneaking()) {
double horizontalSpeed = 0.03;
double verticalSpeed = -0.02;
Vector3d look = Util.getLookVecEio(player);
Vector3d side = new Vector3d();
side.cross(new Vector3d(0, 1, 0), look);
Vector3d playerPos = new Vector3d(player.prevPosX, player.prevPosY, player.prevPosZ);
Vector3d b = new Vector3d(playerPos);
b.y += 1;
Vector3d c = new Vector3d(playerPos);
c.add(side);
Vector4d plane = new Vector4d();
VecmathUtil.computePlaneEquation(playerPos, b, c, plane);
double dist = Math.abs(VecmathUtil.distanceFromPointToPlane(plane, new Vector3d(player.posX, player.posY, player.posZ)));
double minDist = 0.15;
if(dist < minDist) {
double dropRate = (minDist * 10) - (dist * 10);
verticalSpeed = verticalSpeed + (verticalSpeed * dropRate * 8);
horizontalSpeed -= (0.02 * dropRate);
}
double x = Math.cos(Math.toRadians(player.rotationYawHead + 90))
* horizontalSpeed;
double z = Math.sin(Math.toRadians(player.rotationYawHead + 90))
* horizontalSpeed;
player.motionX += x;
player.motionZ += z;
player.motionY = verticalSpeed;
player.fallDistance = 0f;
}
}
private void updateSword(EntityPlayer player) {
if(ItemDarkSteelSword.isEquipped(player)) {
IAttributeInstance attackInst = player.getAttributeMap().getAttributeInstance(SharedMonsterAttributes.attackDamage);
attackInst.removeModifier(swordDamageModifierPowered);
ItemStack sword = player.getCurrentEquippedItem();
if(Config.darkSteelSwordPowerUsePerHit <= 0 || EnderIO.itemDarkSteelSword.getEnergyStored(sword) >= Config.darkSteelSwordPowerUsePerHit) {
attackInst.applyModifier(swordDamageModifierPowered);
}
}
}
private void updateSpeed(EntityPlayer player) {
IAttributeInstance moveInst = player.getAttributeMap().getAttributeInstance(SharedMonsterAttributes.movementSpeed);
moveInst.removeModifier(walkModifiers[0]); //any will so as they all have the same UID
moveInst.removeModifier(sprintModifiers[0]);
@@ -69,7 +140,7 @@ public class DarkSteelController {
if(leggings != null && leggings.getItem() == EnderIO.itemDarkSteelLeggings && speedUpgrade != null) {
double horzMovement = Math.sqrt(player.motionX * player.motionX + player.motionZ * player.motionZ);
double costModifier = player.isSprinting() ? Config.darkSteelSprintPowerCost : Config.darkSteelWalkPowerCost;
double costModifier = player.isSprinting() ? Config.darkSteelSprintPowerCost : Config.darkSteelWalkPowerCost;
costModifier = costModifier + (costModifier * speedUpgrade.walkMultiplier);
int cost = (int) (horzMovement * costModifier);
@@ -83,18 +154,16 @@ public class DarkSteelController {
}
}
}
}
//sword
if(ItemDarkSteelSword.isEquipped(player)) {
IAttributeInstance attackInst = player.getAttributeMap().getAttributeInstance(SharedMonsterAttributes.attackDamage);
attackInst.removeModifier(swordDamageModifierPowered);
ItemStack sword = player.getCurrentEquippedItem();
if(Config.darkSteelSwordPowerUsePerHit <= 0 || EnderIO.itemDarkSteelSword.getEnergyStored(sword) >= Config.darkSteelSwordPowerUsePerHit) {
attackInst.applyModifier(swordDamageModifierPowered);
}
private void updateStepHeight(EntityPlayer player) {
ItemStack boots = player.getEquipmentInSlot(1);
JumpUpgrade jumpUpgrade = JumpUpgrade.loadFromItem(boots);
if(jumpUpgrade != null && boots != null && boots.getItem() == EnderIO.itemDarkSteelBoots) {
player.stepHeight = 1.0023F;
} else if(player.stepHeight == 1.0023F) {
player.stepHeight = 0.5001F;
}
}
void usePlayerEnergy(EntityPlayer player, ItemDarkSteelArmor armor, int cost) {
@@ -34,6 +34,7 @@ public class DarkSteelRecipeManager {
upgrades.add(SpeedUpgrade.SPEED_ONE);
upgrades.add(SpeedUpgrade.SPEED_TWO);
upgrades.add(SpeedUpgrade.SPEED_THREE);
upgrades.add(GlideUpgrade.INSTANCE);
}
@SubscribeEvent
@@ -0,0 +1,53 @@
package crazypants.enderio.item.darksteel;
import crazypants.enderio.EnderIO;
import crazypants.enderio.material.Material;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
public class GlideUpgrade extends AbstractUpgrade {
private static String UPGRADE_NAME = "glide";
public static final GlideUpgrade INSTANCE = new GlideUpgrade();
public static GlideUpgrade loadFromItem(ItemStack stack) {
if(stack == null) {
return null;
}
if(stack.stackTagCompound == null) {
return null;
}
if(!stack.stackTagCompound.hasKey(KEY_UPGRADE_PREFIX + UPGRADE_NAME)) {
return null;
}
return new GlideUpgrade((NBTTagCompound) stack.stackTagCompound.getTag(KEY_UPGRADE_PREFIX + UPGRADE_NAME));
}
public GlideUpgrade(NBTTagCompound tag) {
super(UPGRADE_NAME, tag);
}
public GlideUpgrade() {
super(UPGRADE_NAME, "enderio.darksteel.upgrade.glide", new ItemStack(Items.feather), 15);
}
@Override
public boolean canAddToItem(ItemStack stack) {
if(stack == null || stack.getItem() != EnderIO.itemDarkSteelChestplate|| !EnergyUpgrade.itemHasAnyPowerUpgrade(stack)) {
return false;
}
GlideUpgrade up = loadFromItem(stack);
if(up == null) {
return true;
}
return false;
}
@Override
public void writeUpgradeToNBT(NBTTagCompound upgradeRoot) {
}
}
@@ -107,6 +107,8 @@ public class ItemDarkSteelArmor extends ItemArmor implements IEnergyContainerIte
SpeedUpgrade.SPEED_THREE.writeToItem(is);
} else if(armorType == 3) {
JumpUpgrade.JUMP_THREE.writeToItem(is);
} else if(armorType == 1) {
GlideUpgrade.INSTANCE.writeToItem(is);
}
par3List.add(is);