Skip to content

Commit

Permalink
Backport fixes from 1.9
Browse files Browse the repository at this point in the history
  • Loading branch information
Sollace committed May 8, 2016
1 parent 2a79e74 commit e00c0bc
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 34 deletions.
3 changes: 3 additions & 0 deletions pf-resources/assets/presencefootsteps/lang/en_US.lang
Expand Up @@ -3,6 +3,9 @@ menu.pf.title=Presence Footsteps Configuration
menu.pf.on=On
menu.pf.off=Off

menu.pf.multiplayer.on=Mode: Multiplayer
menu.pf.multiplayer.off=Mode: Singleplayer

menu.pf.volume.min=Minimum
menu.pf.volume.max=Maximum
menu.pf.volume=Volume
Expand Down
49 changes: 31 additions & 18 deletions pf-src/eu/ha3/presencefootsteps/game/reader/PFReader.java
Expand Up @@ -51,6 +51,8 @@ public class PFReader implements Generator, VariatorSettable {
private boolean isMessyFoliage;
private long brushesTime;

protected EntityPlayer clientPlayer;

public PFReader(Isolator isolator, Utility util) {
mod = isolator;
this.util = util;
Expand All @@ -76,6 +78,7 @@ public void generateFootsteps(EntityPlayer ply) {
* Fills in the blanks that aren't present on the client when playing on a remote server.
*/
protected void simulateMotionData(EntityPlayer ply) {
clientPlayer = resolveToClientPlayer(ply);
if (isClientPlayer(ply)) {
EntityPlayer clientPlayer = util.getClient().getPlayer();
motionX = clientPlayer.motionX;
Expand Down Expand Up @@ -229,7 +232,7 @@ protected void simulateAirborne(EntityPlayer ply) {

protected boolean isJumping(EntityPlayer ply) {
try {
return (boolean)util.getPrivate(ply, "isJumping");
return (boolean)util.getPrivate(clientPlayer, "isJumping");
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
Expand All @@ -247,27 +250,32 @@ protected void simulateJumpingLanding(EntityPlayer ply) {
if (mod.getSolver().hasSpecialStoppingConditions(ply)) return;

boolean isJumping = isJumping(ply);

if (isAirborne && isJumping) {
if (VAR.EVENT_ON_JUMP) {
double speed = motionX * motionX + motionZ * motionZ;

if (speed < VAR.SPEED_TO_JUMP_AS_MULTIFOOT) { // STILL JUMP
playMultifoot(ply, getOffsetMinus(ply) + 0.4d, EventType.JUMP); // 2 - 0.7531999805212d (magic number for vertical offset?)
} else {
playSinglefoot(ply, getOffsetMinus(ply) + 0.4d, EventType.JUMP, isRightFoot); // RUNNING JUMP
// Do not toggle foot: After landing sounds, the first foot will be same as the one used to jump.
}
}
simulateJumping(ply);
} else if (!isAirborne) {
if (fallDistance > VAR.LAND_HARD_DISTANCE_MIN) {
playMultifoot(ply, getOffsetMinus(ply), EventType.LAND); // Always assume the player lands on their two feet
simulateLanding(ply);
}
}

protected void simulateJumping(EntityPlayer ply) {
if (VAR.EVENT_ON_JUMP) {
double speed = motionX * motionX + motionZ * motionZ;
if (speed < VAR.SPEED_TO_JUMP_AS_MULTIFOOT) { // STILL JUMP
playMultifoot(ply, getOffsetMinus(ply) + 0.4d, EventType.JUMP); // 2 - 0.7531999805212d (magic number for vertical offset?)
} else {
playSinglefoot(ply, getOffsetMinus(ply) + 0.4d, EventType.JUMP, isRightFoot); // RUNNING JUMP
// Do not toggle foot: After landing sounds, the first foot will be same as the one used to jump.
} else if (!this.stepThisFrame && !ply.isSneaking()) {
playSinglefoot(ply, getOffsetMinus(ply), speedDisambiguator(ply, EventType.CLIMB, EventType.CLIMB_RUN), isRightFoot);
isRightFoot = !isRightFoot;
}

}
}

protected void simulateLanding(EntityPlayer ply) {
if (fallDistance > VAR.LAND_HARD_DISTANCE_MIN) {
playMultifoot(ply, getOffsetMinus(ply), EventType.LAND); // Always assume the player lands on their two feet
// Do not toggle foot: After landing sounds, the first foot will be same as the one used to jump.
} else if (!this.stepThisFrame && !ply.isSneaking()) {
playSinglefoot(ply, getOffsetMinus(ply), speedDisambiguator(ply, EventType.CLIMB, EventType.CLIMB_RUN), isRightFoot);
isRightFoot = !isRightFoot;
}
}

Expand All @@ -276,6 +284,11 @@ private boolean isClientPlayer(EntityPlayer ply) {
return ply.getUniqueID().equals(clientPlayer.getUniqueID());
}

private EntityPlayer resolveToClientPlayer(EntityPlayer ply) {
EntityPlayer clientPlayer = util.getClient().getPlayer();
return ply.getUniqueID().equals(clientPlayer.getUniqueID()) ? clientPlayer : ply;
}

protected EventType speedDisambiguator(EntityPlayer ply, EventType walk, EventType run) {
if (!isClientPlayer(ply)) { //Other players don't send motion data, so have to decide some other way
if (ply.isSprinting()) {
Expand Down
11 changes: 10 additions & 1 deletion pf-src/eu/ha3/presencefootsteps/game/reader/PFReaderPeg.java
Expand Up @@ -72,6 +72,8 @@ protected int getWingSpeed() {
}

protected void simulateJumpingLanding(EntityPlayer ply) {
if (mod.getSolver().hasSpecialStoppingConditions(ply)) return;

final long now = System.currentTimeMillis();

double xpd = motionX * motionX + motionZ * motionZ;
Expand All @@ -90,7 +92,14 @@ protected void simulateJumpingLanding(EntityPlayer ply) {
mod.getAcoustics().playAcoustic(ply, "_SWIFT", EventType.JUMP, null);
}
}
if (hugeLanding) super.simulateJumpingLanding(ply);

boolean isJumping = isJumping(ply);

if (isAirborne && isJumping) {
simulateJumping(ply);
} else if (!isAirborne && hugeLanding) {
simulateLanding(ply);
}
}

protected void simulateFlying(EntityPlayer ply) {
Expand Down
26 changes: 17 additions & 9 deletions pf-src/eu/ha3/presencefootsteps/gui/PFGuiMenu.java
Expand Up @@ -29,8 +29,8 @@ public class PFGuiMenu extends GuiScreen {
private final int BUTTON_HEIGHT = 20;

private final int Y_SPACING = BUTTON_SPACING + BUTTON_HEIGHT;
private final int BUTTON_WIDTH = 300 - Y_SPACING * 4;

private final int BUTTON_WIDTH = 270 - Y_SPACING * 4;

public PFGuiMenu(PFHaddon haddon) {
screenTitle = I18n.format("menu.pf.title");
Expand All @@ -46,8 +46,8 @@ public void initGui() {
final int _LEFT = width / 2 - 300 / 2 + Y_SPACING * 2;
final int _RIGHT = width / 2 + 300 / 2 - Y_SPACING * 2;

HGuiSliderControl sliderControl = new HGuiSliderControl(0, _LEFT, TOP + Y_SPACING, BUTTON_WIDTH - BUTTON_HEIGHT - 5, BUTTON_HEIGHT, "", mod.getVolume() / 100f);
sliderControl.setListener(new HSliderListener() {
HGuiSliderControl sliderControl = new HGuiSliderControl(0, _LEFT + BUTTON_WIDTH/2 + BUTTON_SPACING/2, TOP + Y_SPACING, BUTTON_WIDTH - BUTTON_HEIGHT - 5, BUTTON_HEIGHT, "", mod.getVolume() / 100f);
sliderControl.setListener(new HSliderListener() {
@Override
public void sliderValueChanged(HGuiSliderControl slider, float value) {
float valueSnapped = value * 100;
Expand Down Expand Up @@ -82,13 +82,19 @@ public String provideDisplayString() {

buttonList.add(sliderControl);
buttonList.add(new GuiButton(212, _RIGHT - BUTTON_HEIGHT, TOP + Y_SPACING, BUTTON_HEIGHT, BUTTON_HEIGHT, I18n.format(mod.getEnabled() ? "menu.pf.on" : "menu.pf.off")));
buttonList.add(new GuiButton(210, _LEFT, TOP + Y_SPACING * 2, BUTTON_WIDTH, BUTTON_HEIGHT, getStance()));
buttonList.add(new GuiButton(199, _LEFT, TOP + Y_SPACING * 3 + (BUTTON_SPACING * 2), BUTTON_WIDTH, BUTTON_HEIGHT, I18n.format(getResourcePacks())));
buttonList.add(new GuiButton(198, _LEFT, TOP + Y_SPACING * 4 + (BUTTON_SPACING * 2), BUTTON_WIDTH, BUTTON_HEIGHT, I18n.format("menu.pf.report.full")));
buttonList.add(new GuiButton(220, _LEFT, TOP + Y_SPACING * 5 + (BUTTON_SPACING * 2), BUTTON_WIDTH, BUTTON_HEIGHT, I18n.format("menu.pf.report.concise")));
buttonList.add(new GuiButton(212, _RIGHT + BUTTON_HEIGHT*2 - BUTTON_SPACING/2, TOP + Y_SPACING, BUTTON_HEIGHT, BUTTON_HEIGHT, I18n.format(mod.getEnabled() ? "menu.pf.on" : "menu.pf.off")));
buttonList.add(new GuiButton(210, _LEFT - BUTTON_WIDTH/2 - BUTTON_SPACING/2, TOP + Y_SPACING, BUTTON_WIDTH, BUTTON_HEIGHT, getStance()));
buttonList.add(new GuiButton(199, _LEFT + BUTTON_WIDTH/2 + BUTTON_SPACING/2, TOP + Y_SPACING * 3 + (BUTTON_SPACING * 2), BUTTON_WIDTH, BUTTON_HEIGHT, I18n.format(getResourcePacks())));
buttonList.add(new GuiButton(213, _LEFT - BUTTON_WIDTH/2 - BUTTON_SPACING/2, TOP + Y_SPACING * 3 + (BUTTON_SPACING * 2), BUTTON_WIDTH, BUTTON_HEIGHT, I18n.format(getMP())));
buttonList.add(new GuiButton(198, _LEFT - BUTTON_WIDTH/2 - BUTTON_SPACING/2, TOP + Y_SPACING * 4 + (BUTTON_SPACING * 2), BUTTON_WIDTH, BUTTON_HEIGHT, I18n.format("menu.pf.report.full")));
buttonList.add(new GuiButton(220, _LEFT + BUTTON_WIDTH/2 + BUTTON_SPACING/2, TOP + Y_SPACING * 4 + (BUTTON_SPACING * 2), BUTTON_WIDTH, BUTTON_HEIGHT, I18n.format("menu.pf.report.concise")));
buttonList.add(new GuiButton(200, _LEFT, TOP + Y_SPACING * 6 + (BUTTON_SPACING * 4), BUTTON_WIDTH, BUTTON_HEIGHT, I18n.format("menu.returnToGame")));
}

private String getMP() {
return I18n.format(mod.getEnabledMP() ? "menu.pf.multiplayer.on" : "menu.pf.multiplayer.off");
}

private String getStance() {
return I18n.format("menu.pf.stance") + ": " + I18n.format("menu.pf.stance." + mod.getConfig().getInteger("custom.stance"));
}
Expand Down Expand Up @@ -126,7 +132,9 @@ protected void actionPerformed(GuiButton sender) {
}
} else if (sender.id == 212) {
sender.displayString = I18n.format(mod.toggle() ? "menu.pf.on" : "menu.pf.off");
}
} else if (sender.id == 213) {
sender.displayString = I18n.format(mod.toggleMP() ? "menu.pf.multiplayer.on" : "menu.pf.multiplayer.off");
}

}

Expand Down
28 changes: 22 additions & 6 deletions pf-src/eu/ha3/presencefootsteps/main/PFHaddon.java
Expand Up @@ -78,7 +78,8 @@ public class PFHaddon extends HaddonImpl implements SupportsFrameEvents, Support
private boolean debugState;
private long pressedOptionsTime;
private boolean enabled = true;

private boolean enableMP = true;

// System
private PFResourcePackDealer dealer = new PFResourcePackDealer();
private PFIsolator isolator;
Expand Down Expand Up @@ -203,7 +204,8 @@ private void reloadConfig() {
config.setProperty("custom.stance", 0);
config.setProperty("key.code", keyBindDefaultCode);
config.setProperty("user.enabled", true);
config.commit();
config.setProperty("user.multiplayer", true);
config.commit();

boolean fileExisted = new File(presenceDir, "userconfig.cfg").exists();

Expand All @@ -219,6 +221,9 @@ private void reloadConfig() {
config.save();
}

enabled = config.getBoolean("user.enabled");
enableMP = config.getBoolean("user.multiplayer");

updateNotifier.loadConfig(config);
}

Expand Down Expand Up @@ -317,6 +322,10 @@ public boolean mlpInstalled() {
return MineLittlePonyCommunicator.instance.ponyModInstalled();
}

public boolean getEnabledMP() {
return enableMP;
}

public boolean getEnabled() {
return enabled;
}
Expand All @@ -329,7 +338,13 @@ public int getVolume() {
}

public void setVolume(int volume) {
getConfig().setProperty("user.volume", volume);
config.setProperty("user.volume", volume);
}

public boolean toggleMP() {
config.setProperty("user.multiplayer", enableMP = !enableMP);
saveConfig();
return enableMP;
}

public boolean toggle() {
Expand Down Expand Up @@ -371,8 +386,8 @@ public void onTick() {

@Override
public void onFrame(EntityPlayer ply, float semi) {
if (enabled && hasResourcePacks && !util().isGamePaused()) {
isolator.onFrame(ply);
if (enableMP && enabled && hasResourcePacks && !util().isGamePaused()) {
isolator.onFrame(ply);
setPlayerStepDistance(ply, Integer.MAX_VALUE);
}
}
Expand All @@ -390,7 +405,8 @@ public void onFrame(float semi) {
}

if (enabled && hasResourcePacks && !util().isGamePaused()) {
setPlayerStepDistance(ply, Integer.MAX_VALUE);
if (!enableMP) isolator.onFrame(ply);
setPlayerStepDistance(ply, Integer.MAX_VALUE);
}

if (!firstTickPassed) {
Expand Down

0 comments on commit e00c0bc

Please sign in to comment.