Skip to content

Commit

Permalink
Added ability to toggle nightvision and prepared for possible future
Browse files Browse the repository at this point in the history
different visions #release
  • Loading branch information
maxanier committed Jun 13, 2015
1 parent e0a448f commit 04e5054
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public class KeyInputEventHandler {
public static KeyBinding AUTO = new KeyBinding(REFERENCE.KEYS.AUTO_BLOOD, Keyboard.KEY_B, REFERENCE.KEYS.CATEGORY);

public static KeyBinding SKILL = new KeyBinding(REFERENCE.KEYS.TOGGLE_SKILLS, -98, REFERENCE.KEYS.CATEGORY);

public static KeyBinding VISION = new KeyBinding(REFERENCE.KEYS.SWITCH_VISION,Keyboard.KEY_N,REFERENCE.KEYS.CATEGORY);

private static KEY getPressedKeyBinding() {
if (SUCK.isPressed()) {
Expand All @@ -32,6 +34,9 @@ private static KEY getPressedKeyBinding() {
} else if (SKILL.isPressed()) {
return KEY.SKILL;
}
else if(VISION.isPressed()){
return KEY.VISION;
}
return KEY.UNKNOWN;
}

Expand All @@ -58,5 +63,8 @@ public void handleInputEvent(InputEvent event) {
EntityPlayer player = Minecraft.getMinecraft().thePlayer;
player.openGui(VampirismMod.instance, GuiHandler.ID_SKILL, player.worldObj, player.chunkCoordX, player.chunkCoordY, player.chunkCoordZ);
}
else if(keyPressed == KEY.VISION){
VampirismMod.modChannel.sendToServer(new InputEventPacket(InputEventPacket.SWITCHVISION,"0"));
}
}
}
7 changes: 3 additions & 4 deletions src/main/java/de/teamlapen/vampirism/coremod/CoreHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.ResourceLocation;
import de.teamlapen.vampirism.VampirismMod;
import de.teamlapen.vampirism.entity.player.PlayerAbilities;
import de.teamlapen.vampirism.entity.player.VampirePlayer;
import de.teamlapen.vampirism.util.Logger;
import de.teamlapen.vampirism.util.BALANCE;

/**
* Class for static communication between modified/transformed classes and the
Expand All @@ -28,13 +27,13 @@ public static void addExhaustion(float a, EntityPlayer p) {
}

public static float getNightVisionLevel(EntityPlayer p) {
return PlayerAbilities.getPlayerAbilities(VampirePlayer.get(p).getLevel()).nightVision;
return BALANCE.getVampirePlayerNightVision(VampirePlayer.get(p).getLevel());
}

public static boolean shouldOverrideNightVision(Object o, Potion p) {

if (o instanceof EntityPlayer && p.equals(Potion.nightVision)) {
return (PlayerAbilities.getPlayerAbilities(VampirePlayer.get((EntityPlayer) o).getLevel()).nightVision > 0.0F);
return (VampirePlayer.get((EntityPlayer) o).getVision()==1&&getNightVisionLevel((EntityPlayer) o)>0F);
}
return false;
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,8 @@ public static void onPlayerJoinWorld(EntityPlayer player) {

private static final String KEY_VAMPIRE_LORD = "vampire_lord";

private static final String KEY_VISION = "vision";

private final EntityPlayer player;

private final String KEY_LEVEL = "level";
Expand All @@ -292,7 +294,15 @@ public static void onPlayerJoinWorld(EntityPlayer player) {

private boolean autoFillBlood;

private boolean nightVision;
private int vision;

public int getVision() {
return vision;
}

private void setVision(int vision) {
this.vision = vision;
}

private EntityLivingBase minionTarget;

Expand All @@ -314,6 +324,7 @@ public VampirePlayer(EntityPlayer player) {
MAXBLOOD);
bloodStats = new BloodStats();
autoFillBlood = true;
vision=1;
skillTimer = new int[Skills.getSkillCount()];
extraData = new NBTTagCompound();
minionHandler=new MinionHandler<VampirePlayer>(this);
Expand Down Expand Up @@ -368,17 +379,6 @@ private void func_71013_b(int direction) {
}
}

/**
* Adds blood to the vampires blood level level without increasing the
* saturation level
*
* @param a
* amount
*/

private boolean getAutoFillBlood() {
return autoFillBlood;
}

/**
* @return The current blood level
Expand Down Expand Up @@ -445,6 +445,7 @@ public void init(Entity entity, World world) {
public boolean isAutoFillBlood() {
return autoFillBlood;
}


private boolean isRemote() {
return player.worldObj.isRemote;
Expand Down Expand Up @@ -505,6 +506,9 @@ public void loadNBTData(NBTTagCompound compound) {
if (properties.hasKey(KEY_AUTOFILL)) {
setAutoFillBlood(properties.getBoolean(KEY_AUTOFILL));
}
if(properties.hasKey(KEY_VISION)){
setVision(properties.getInteger(KEY_VISION));
}
if (properties.hasKey(KEY_EXTRADATA)) {
extraData = properties.getCompoundTag(KEY_EXTRADATA);
}
Expand Down Expand Up @@ -714,7 +718,6 @@ private void handleSunDamage() {
* Called every LivingEntityUpdate, returns immediately if level =0;
*/
public void onUpdate() {
//Logger.i("VampirePlayer", String.format("Remote=%s, sleeping=%s, fullyAsleep=%s", player.worldObj.isRemote, player.isPlayerSleeping(), player.isPlayerFullyAsleep()));
if(this.sleepingCoffin && player.isPlayerSleeping()) {
if(!player.worldObj.isRemote)
player.motionY = 0;
Expand Down Expand Up @@ -818,7 +821,8 @@ public void saveNBTData(NBTTagCompound compound) {
properties.setInteger(KEY_LEVEL, getLevel());
properties.setInteger(KEY_BLOOD, getBlood());
properties.setIntArray(KEY_SKILLS, skillTimer);
properties.setBoolean(KEY_AUTOFILL, getAutoFillBlood());
properties.setBoolean(KEY_AUTOFILL, isAutoFillBlood());
properties.setInteger(KEY_VISION, getVision());
properties.setBoolean(KEY_VAMPIRE_LORD, isVampireLord());
properties.setTag(KEY_EXTRADATA, extraData);
this.bloodStats.writeNBT(properties);
Expand All @@ -829,6 +833,7 @@ public void saveNBTData(NBTTagCompound compound) {
private void setAutoFillBlood(boolean value) {
autoFillBlood = value;
}


/**
* DONT USE, only designed to be used at startup and by Bloodstats Try to
Expand Down Expand Up @@ -1107,16 +1112,18 @@ public void loadUpdateFromNBT(NBTTagCompound nbt) {
}
if(nbt.hasKey("sleepingCoffin"))
this.sleepingCoffin = nbt.getBoolean("sleepingCoffin");
if(nbt.hasKey("vision"))
this.setVision(nbt.getInteger("vision"));

}

@Override
public void writeFullUpdateToNBT(NBTTagCompound tag) {
tag.setInteger("level", getLevel());
tag.setIntArray("timers", skillTimer);
;
tag.setBoolean("lord", isVampireLord());
tag.setBoolean("sleepingCoffin", sleepingCoffin);
tag.setInteger("vision", getVision());
}

@Override
Expand Down Expand Up @@ -1165,4 +1172,23 @@ public void wakeUpPlayer(boolean vanilla, boolean immediately,boolean updateWorl
player.wakeUpPlayer(immediately, updateWorld, setSpawn);
}
}

public void onToggleVision() {
if(getLevel()==0){
player.addChatMessage(new ChatComponentTranslation("text.vampirism:skill.level_to_low"));
return;
}
int v=getVision()+1;
if(v>1)v=0;
this.setVision(v);
this.sync(false);
if(v==0){
player.addChatMessage(new ChatComponentTranslation("text.vampirism:normal_vision"));
}
else if(v==1){
player.addChatMessage(new ChatComponentTranslation("text.vampirism:night_vision"));
}


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ public IMessage onMessage(InputEventPacket message, MessageContext ctx) {
EntityPlayer player = ctx.getServerHandler().playerEntity;
VampirePlayer.get(player).setLevel(0);
player.attackEntityFrom(DamageSource.magic, 1000);
} else if (message.action.equals(TOGGLESKILL)) {
} else if(message.action.equals(SWITCHVISION)){
EntityPlayer player = ctx.getServerHandler().playerEntity;
VampirePlayer.get(player).onToggleVision();
}
else if (message.action.equals(TOGGLESKILL)) {
int id =-1;
try {
id = Integer.parseInt(message.param);
Expand Down Expand Up @@ -66,6 +70,7 @@ else if(message.action.equals(LEAVE_COFFIN)){
public static String TOGGLESKILL = "ts";
public static String LEAVE_COFFIN = "lc";
private final static String TAG = "InputEventPacket";
public static final String SWITCHVISION = "sw";
private String param;
private String action;

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/de/teamlapen/vampirism/util/REFERENCE.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ public static final class ENTITY {
}

public static enum KEY {
UNKNOWN, SUCK, AUTO, SKILL
UNKNOWN, SUCK, AUTO, SKILL, VISION
}

public static final class KEYS {
public static final String CATEGORY = "keys.vampirism.category";
public static final String SUCK_BLOOD = "keys.vampirism.suck";
public static final String AUTO_BLOOD = "keys.vampirism.auto";
public static final String TOGGLE_SKILLS = "keys.vampirism.skill";
public static final String SWITCH_VISION = "key.vampirism.vision";
}

public static final String MODID = "vampirism";
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/assets/vampirism/lang/de_DE.lang
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ text.vampirism:vampirelevel=Vampirlevel
text.vampirism:entitysblood=Entity's blood
text.vampirism:minion=Minion
text.vampirism:lord=Sklave
text.vampirism:normal_vision=Normale Sicht
text.vampirism:night_vision=Nachtsicht

#Skill
skill.vampirism.bat_skill=Aktiviere Fledermaus
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/assets/vampirism/lang/en_US.lang
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ text.vampirism:vampirelevel=Vampirelevel
text.vampirism:entitysblood=Entity's blood
text.vampirism:minion=Minion
text.vampirism:lord=Lord
text.vampirism:normal_vision=Normal Vision
text.vampirism:night_vision=Night Vision

#Skill
skill.vampirism.bat_skill=Toggle Batmode
Expand Down

0 comments on commit 04e5054

Please sign in to comment.