Added night vision upgrade for DS helm.

This commit is contained in:
CrazyPants committed 2014-08-04 21:02:39 +08:00
1 parent aca0a0c43c
commit db6538916f
7 files changed
+147 -15

No files matched your search

@@ -174,6 +174,8 @@ public final class Config {
public static int darkSteelSwimCost = 15;
public static int darkSteelNightVisionCost = 15;
public static int darkSteelSoundLocatorCost = 10;
public static int darkSteelSoundLocatorRange = 40;
public static int darkSteelSoundLocatorLifespan = 40;
@@ -464,8 +466,11 @@ public final class Config {
darkSteelFallDistanceCost = config.get(sectionDarkSteel.name, "darkSteelFallDistanceCost", darkSteelFallDistanceCost,
"Amount of power used (RF) per block height of fall distance damage negated.").getInt(darkSteelFallDistanceCost);
darkSteelSwimCost = config.get(sectionDarkSteel.name, "darkSteelGliderCost", darkSteelGliderCost,
"Number of levels required for the 'Swim' upgrade.").getInt(darkSteelGliderCost);
darkSteelSwimCost = config.get(sectionDarkSteel.name, "darkSteelSwimCost", darkSteelSwimCost,
"Number of levels required for the 'Swim' upgrade.").getInt(darkSteelSwimCost);
darkSteelNightVisionCost = config.get(sectionDarkSteel.name, "darkSteelNightVisionCost", darkSteelNightVisionCost,
"Number of levels required for the 'Night Vision' upgrade.").getInt(darkSteelNightVisionCost);
darkSteelGliderCost = config.get(sectionDarkSteel.name, "darkSteelGliderCost", darkSteelGliderCost,
"Number of levels required for the 'Glider' upgrade.").getInt(darkSteelGliderCost);
@@ -11,6 +11,8 @@ import net.minecraft.entity.ai.attributes.AttributeModifier;
import net.minecraft.entity.ai.attributes.IAttributeInstance;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.MovementInput;
import cofh.api.energy.IEnergyContainerItem;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
@@ -48,8 +50,11 @@ public class DarkSteelController {
private boolean wasJumping;
private int jumpCount;
private int ticksSinceLastJump;
//private boolean isGlideActive = false;
private Map<String, Boolean> glideActiveMap = new HashMap<String, Boolean>();
private boolean nightVisionActive = false;
private boolean removeNightvision = false;
private DarkSteelController() {
PacketHandler.INSTANCE.registerMessage(PacketDarkSteelPowerPacket.class, PacketDarkSteelPowerPacket.class, PacketHandler.nextID(), Side.SERVER);
@@ -74,8 +79,6 @@ public class DarkSteelController {
public void onPlayerTick(TickEvent.PlayerTickEvent event) {
EntityPlayer player = event.player;
if(event.phase == Phase.START) {
//boots
updateStepHeightAndFallDistance(player);
@@ -87,8 +90,9 @@ public class DarkSteelController {
updateSword(player);
updateGlide(player);
updateSwim(player);
}
}
@@ -99,10 +103,10 @@ public class DarkSteelController {
if(upgrade == null) {
return;
}
if(player.isInWater()) {
if(player.isInWater()) {
player.motionX *= 1.1;
player.motionZ *= 1.1;
}
}
}
private void updateGlide(EntityPlayer player) {
@@ -178,23 +182,23 @@ public class DarkSteelController {
}
IAttributeInstance moveInst = player.getAttributeMap().getAttributeInstance(SharedMonsterAttributes.movementSpeed);
if(moveInst.getModifier(walkModifiers[0].getID()) != null) {
if(moveInst.getModifier(walkModifiers[0].getID()) != null) {
moveInst.removeModifier(walkModifiers[0]); //any will so as they all have the same UID
} else if(moveInst.getModifier(sprintModifiers[0].getID()) != null) {
} else if(moveInst.getModifier(sprintModifiers[0].getID()) != null) {
moveInst.removeModifier(sprintModifiers[0]);
}
}
ItemStack leggings = player.getEquipmentInSlot(2);
SpeedUpgrade speedUpgrade = SpeedUpgrade.loadFromItem(leggings);
if(leggings != null && leggings.getItem() == EnderIO.itemDarkSteelLeggings && speedUpgrade != null) {
double horzMovement = Math.abs(player.distanceWalkedModified - player.prevDistanceWalkedModified);
double costModifier = player.isSprinting() ? Config.darkSteelSprintPowerCost : Config.darkSteelWalkPowerCost;
costModifier = costModifier + (costModifier * speedUpgrade.walkMultiplier);
int cost = (int) (horzMovement * costModifier);
int totalEnergy = getPlayerEnergy(player, EnderIO.itemDarkSteelLeggings);
if(totalEnergy > 0) {
if(totalEnergy > 0) {
usePlayerEnergy(player, EnderIO.itemDarkSteelLeggings, cost);
if(player.isSprinting()) {
moveInst.applyModifier(sprintModifiers[speedUpgrade.level - 1]);
@@ -298,7 +302,11 @@ public class DarkSteelController {
jumpCount = 0;
}
ticksSinceLastJump++;
updateNightvision(player);
}
}
@SideOnly(Side.CLIENT)
@@ -322,5 +330,32 @@ public class DarkSteelController {
}
}
private void updateNightvision(EntityPlayer player) {
if(isNightVisionUpgradeEquipped(player) && nightVisionActive) {
player.addPotionEffect(new PotionEffect(Potion.nightVision.getId(), 210, 0, true));
}
if(!isNightVisionUpgradeEquipped(player) && nightVisionActive) {
nightVisionActive = false;
removeNightvision = true;
}
if(removeNightvision) {
player.removePotionEffect(Potion.nightVision.getId());
removeNightvision = false;
}
}
public boolean isNightVisionUpgradeEquipped(EntityPlayer player) {
ItemStack helmet = player.getEquipmentInSlot(4);
return NightVisionUpgrade.loadFromItem(helmet) != null;
}
public void setNightVisionActive(boolean isNightVisionActive) {
if(nightVisionActive && !isNightVisionActive) {
removeNightvision = true;
}
this.nightVisionActive = isNightVisionActive;
}
}
@@ -37,6 +37,7 @@ public class DarkSteelRecipeManager {
upgrades.add(GliderUpgrade.INSTANCE);
upgrades.add(SoundDetectorUpgrade.INSTANCE);
upgrades.add(SwimUpgrade.INSTANCE);
upgrades.add(NightVisionUpgrade.INSTANCE);
}
@SubscribeEvent
@@ -112,6 +112,7 @@ public class ItemDarkSteelArmor extends ItemArmor implements IEnergyContainerIte
GliderUpgrade.INSTANCE.writeToItem(is);
} else if(armorType == 0) {
SoundDetectorUpgrade.INSTANCE.writeToItem(is);
NightVisionUpgrade.INSTANCE.writeToItem(is);
}
par3List.add(is);
@@ -30,17 +30,23 @@ public class KeyTracker {
private KeyBinding soundDetectorKey;
private boolean isSoundDectorActive = false;
private KeyBinding nightVisionKey;
private boolean isNightVisionActive = false;
public KeyTracker() {
glideKey = new KeyBinding("Glider Toggle", Keyboard.KEY_G, "Dark Steel Armor");
ClientRegistry.registerKeyBinding(glideKey);
soundDetectorKey = new KeyBinding("Sound Locator", Keyboard.KEY_L, "Dark Steel Armor");
ClientRegistry.registerKeyBinding(soundDetectorKey);
nightVisionKey = new KeyBinding("Night Vision", Keyboard.KEY_P, "Dark Steel Armor");
ClientRegistry.registerKeyBinding(nightVisionKey);
}
@SubscribeEvent
public void onKeyInput(KeyInputEvent event) {
handleGlide();
handleSoundDetector();
handleNightVision();
}
private void handleSoundDetector() {
@@ -79,6 +85,24 @@ public class KeyTracker {
PacketHandler.INSTANCE.sendToServer(new PacketGlideState(isGlideActive));
}
}
private void handleNightVision() {
if(!DarkSteelController.instance.isNightVisionUpgradeEquipped(Minecraft.getMinecraft().thePlayer)) {
isNightVisionActive = false;
return;
}
if(nightVisionKey.getIsKeyPressed()) {
isNightVisionActive = !isNightVisionActive;
String message;
if(isNightVisionActive) {
message = Lang.localize("darksteel.upgrade.nightVision.enabled");
} else {
message = Lang.localize("darksteel.upgrade.nightVision.disabled");
}
Minecraft.getMinecraft().thePlayer.addChatComponentMessage(new ChatComponentTranslation(message));
DarkSteelController.instance.setNightVisionActive(isNightVisionActive);
}
}
public boolean isGlideActive() {
return isGlideActive;
@@ -0,0 +1,62 @@
package crazypants.enderio.item.darksteel;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.potion.PotionHelper;
import crazypants.enderio.EnderIO;
import crazypants.enderio.config.Config;
public class NightVisionUpgrade extends AbstractUpgrade {
private static String UPGRADE_NAME = "nightVision";
public static final NightVisionUpgrade INSTANCE = new NightVisionUpgrade();
public static NightVisionUpgrade 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 NightVisionUpgrade((NBTTagCompound) stack.stackTagCompound.getTag(KEY_UPGRADE_PREFIX + UPGRADE_NAME));
}
private static ItemStack createUpgradeItem() {
ItemStack pot = new ItemStack(Items.potionitem, 1, 0);
int res = PotionHelper.applyIngredient(0, Items.nether_wart.getPotionEffect(new ItemStack(Items.nether_wart)));
res = PotionHelper.applyIngredient(res, PotionHelper.goldenCarrotEffect);
pot.setItemDamage(res);
return pot;
}
public NightVisionUpgrade(NBTTagCompound tag) {
super(UPGRADE_NAME, tag);
}
public NightVisionUpgrade() {
super(UPGRADE_NAME, "enderio.darksteel.upgrade.nightVision", createUpgradeItem(), Config.darkSteelNightVisionCost);
}
@Override
public boolean canAddToItem(ItemStack stack) {
if(stack == null || stack.getItem() != EnderIO.itemDarkSteelHelmet) {
return false;
}
NightVisionUpgrade up = loadFromItem(stack);
if(up == null) {
return true;
}
return false;
}
@Override
public void writeUpgradeToNBT(NBTTagCompound upgradeRoot) {
}
}