Skip to content

Commit 144b2dc

Browse files
committed
bry
1 parent 8652ae7 commit 144b2dc

File tree

3 files changed

+188
-8
lines changed

3 files changed

+188
-8
lines changed

src/main/java/net/aspw/viaforgeplus/api/McUpdatesHandler.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package net.aspw.viaforgeplus.api;
22

3-
import net.aspw.viaforgeplus.event.EventTarget;
4-
import net.aspw.viaforgeplus.event.Listenable;
5-
import net.aspw.viaforgeplus.event.MotionEvent;
6-
import net.aspw.viaforgeplus.event.PushOutEvent;
3+
import net.aspw.viaforgeplus.event.*;
74
import net.aspw.viaforgeplus.network.MinecraftInstance;
85
import net.minecraft.block.material.Material;
96
import net.minecraft.client.settings.GameSettings;
@@ -66,7 +63,10 @@ public void onMotion(MotionEvent event) {
6663
if (eyeHeight >= START_HEIGHT && doingEyeRot)
6764
doingEyeRot = false;
6865
}
66+
}
6967

68+
@EventTarget
69+
public void onUpdate(UpdateEvent event) {
7070
if (ProtocolFixer.newerThanOrEqualsTo1_13()) {
7171
if (isSwimming()) {
7272
if (mc.thePlayer.motionX < -0.4D) {
@@ -95,11 +95,11 @@ public void onMotion(MotionEvent event) {
9595
mc.thePlayer.motionY += (d3 - mc.thePlayer.motionY) * d4;
9696
}
9797

98-
mc.thePlayer.motionY += 0.016d;
98+
mc.thePlayer.motionY += 0.018d;
9999

100100
if (shouldAnimation()) {
101-
mc.thePlayer.motionX *= 1.08F;
102-
mc.thePlayer.motionZ *= 1.08F;
101+
mc.thePlayer.motionX *= 1.09F;
102+
mc.thePlayer.motionZ *= 1.09F;
103103
}
104104
}
105105
}

src/main/java/net/aspw/viaforgeplus/event/Events.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ class MotionEvent(
1515

1616
class PacketEvent(val packet: Packet<*>) : CancellableEvent()
1717
class PushOutEvent : CancellableEvent()
18-
class TextEvent(var text: String?) : Event()
18+
class UpdateEvent : Event()

src/main/java/net/aspw/viaforgeplus/injection/forge/mixins/entity/MixinEntityPlayerSP.java

Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,19 @@
66
import net.aspw.viaforgeplus.event.EventState;
77
import net.aspw.viaforgeplus.event.MotionEvent;
88
import net.aspw.viaforgeplus.event.PushOutEvent;
9+
import net.aspw.viaforgeplus.event.UpdateEvent;
910
import net.minecraft.client.Minecraft;
11+
import net.minecraft.client.audio.PositionedSoundRecord;
1012
import net.minecraft.client.entity.AbstractClientPlayer;
1113
import net.minecraft.client.entity.EntityPlayerSP;
1214
import net.minecraft.client.network.NetHandlerPlayClient;
15+
import net.minecraft.item.ItemSword;
1316
import net.minecraft.network.Packet;
1417
import net.minecraft.network.play.client.C03PacketPlayer;
1518
import net.minecraft.network.play.client.C0BPacketEntityAction;
19+
import net.minecraft.potion.Potion;
20+
import net.minecraft.util.MovementInput;
21+
import net.minecraft.util.ResourceLocation;
1622
import net.minecraft.world.World;
1723
import org.spongepowered.asm.mixin.*;
1824
import org.spongepowered.asm.mixin.injection.At;
@@ -27,11 +33,25 @@ public abstract class MixinEntityPlayerSP extends AbstractClientPlayer {
2733
@Shadow
2834
public boolean serverSprintState;
2935
@Shadow
36+
public int sprintingTicksLeft;
37+
@Shadow
38+
public float timeInPortal;
39+
@Shadow
40+
public float prevTimeInPortal;
41+
@Shadow
42+
public MovementInput movementInput;
43+
@Shadow
44+
public float horseJumpPower;
45+
@Shadow
46+
public int horseJumpPowerCounter;
47+
@Shadow
3048
@Final
3149
public NetHandlerPlayClient sendQueue;
3250
@Shadow
3351
public int positionUpdateTicks;
3452
@Shadow
53+
protected int sprintToggleTimer;
54+
@Shadow
3555
protected Minecraft mc;
3656
@Unique
3757
private boolean viaForge$prevOnGround;
@@ -60,6 +80,12 @@ public MixinEntityPlayerSP(World p_i45074_1_, GameProfile p_i45074_2_) {
6080
@Shadow
6181
protected abstract boolean isCurrentViewEntity();
6282

83+
@Shadow
84+
protected abstract void sendHorseJump();
85+
86+
@Shadow
87+
public abstract boolean isRidingHorse();
88+
6389
@Redirect(method = "onUpdateWalkingPlayer", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/NetHandlerPlayClient;addToSendQueue(Lnet/minecraft/network/Packet;)V", ordinal = 7))
6490
public void viaPatch(final NetHandlerPlayClient instance, final Packet<?> p_addToSendQueue_1_) {
6591
if (ProtocolFixer.newerThan1_8()) {
@@ -159,6 +185,160 @@ public void onUpdateWalkingPlayer() {
159185
}
160186
}
161187

188+
/**
189+
* @author As_pw
190+
* @reason Update Event
191+
*/
192+
@Override
193+
@Overwrite
194+
public void onLivingUpdate() {
195+
ProtocolInject.eventManager.callEvent(new UpdateEvent());
196+
if (this.sprintingTicksLeft > 0) {
197+
--this.sprintingTicksLeft;
198+
199+
if (this.sprintingTicksLeft == 0) {
200+
this.setSprinting(false);
201+
}
202+
}
203+
204+
if (this.sprintToggleTimer > 0) {
205+
--this.sprintToggleTimer;
206+
}
207+
208+
this.prevTimeInPortal = this.timeInPortal;
209+
210+
if (this.inPortal) {
211+
if (this.mc.currentScreen != null && !this.mc.currentScreen.doesGuiPauseGame()) {
212+
this.mc.displayGuiScreen(null);
213+
}
214+
215+
if (this.timeInPortal == 0.0F) {
216+
this.mc.getSoundHandler().playSound(PositionedSoundRecord.create(new ResourceLocation("portal.trigger"), this.rand.nextFloat() * 0.4F + 0.8F));
217+
}
218+
219+
this.timeInPortal += 0.0125F;
220+
221+
if (this.timeInPortal >= 1.0F) {
222+
this.timeInPortal = 1.0F;
223+
}
224+
225+
this.inPortal = false;
226+
} else if (this.isPotionActive(Potion.confusion) && this.getActivePotionEffect(Potion.confusion).getDuration() > 60) {
227+
this.timeInPortal += 0.006666667F;
228+
229+
if (this.timeInPortal > 1.0F) {
230+
this.timeInPortal = 1.0F;
231+
}
232+
} else {
233+
if (this.timeInPortal > 0.0F) {
234+
this.timeInPortal -= 0.05F;
235+
}
236+
237+
if (this.timeInPortal < 0.0F) {
238+
this.timeInPortal = 0.0F;
239+
}
240+
}
241+
242+
if (this.timeUntilPortal > 0) {
243+
--this.timeUntilPortal;
244+
}
245+
246+
final boolean flag = this.movementInput.jump;
247+
final boolean flag1 = this.movementInput.sneak;
248+
final float f = 0.8F;
249+
final boolean flag2 = this.movementInput.moveForward >= f;
250+
this.movementInput.updatePlayerMoveState();
251+
252+
if (getHeldItem() != null && (this.isUsingItem() || (getHeldItem().getItem() instanceof ItemSword && mc.thePlayer.isBlocking() && !this.isRiding()))) {
253+
this.movementInput.moveStrafe *= 0.2F;
254+
this.movementInput.moveForward *= 0.2F;
255+
this.sprintToggleTimer = 0;
256+
}
257+
258+
this.pushOutOfBlocks(this.posX - (double) this.width * 0.35D, this.getEntityBoundingBox().minY + 0.5D, this.posZ + (double) this.width * 0.35D);
259+
this.pushOutOfBlocks(this.posX - (double) this.width * 0.35D, this.getEntityBoundingBox().minY + 0.5D, this.posZ - (double) this.width * 0.35D);
260+
this.pushOutOfBlocks(this.posX + (double) this.width * 0.35D, this.getEntityBoundingBox().minY + 0.5D, this.posZ - (double) this.width * 0.35D);
261+
this.pushOutOfBlocks(this.posX + (double) this.width * 0.35D, this.getEntityBoundingBox().minY + 0.5D, this.posZ + (double) this.width * 0.35D);
262+
263+
final boolean flag3 = (float) this.getFoodStats().getFoodLevel() > 6.0F || this.capabilities.allowFlying;
264+
265+
if (this.onGround && !flag1 && !flag2 && this.movementInput.moveForward >= f && !this.isSprinting() && flag3 && !this.isUsingItem() && !this.isPotionActive(Potion.blindness)) {
266+
if (this.sprintToggleTimer <= 0 && !this.mc.gameSettings.keyBindSprint.isKeyDown()) {
267+
this.sprintToggleTimer = 7;
268+
} else {
269+
this.setSprinting(true);
270+
}
271+
}
272+
273+
if (!this.isSprinting() && this.movementInput.moveForward >= f && flag3 && !this.isUsingItem() && !this.isPotionActive(Potion.blindness) && this.mc.gameSettings.keyBindSprint.isKeyDown())
274+
this.setSprinting(true);
275+
276+
if (this.isSprinting() && (this.movementInput.moveForward < f || mc.thePlayer.isCollidedHorizontally || !flag3))
277+
this.setSprinting(false);
278+
279+
if (this.capabilities.allowFlying) {
280+
if (this.mc.playerController.isSpectatorMode()) {
281+
if (!this.capabilities.isFlying) {
282+
this.capabilities.isFlying = true;
283+
this.sendPlayerAbilities();
284+
}
285+
} else if (!flag && this.movementInput.jump) {
286+
if (this.flyToggleTimer == 0) {
287+
this.flyToggleTimer = 7;
288+
} else {
289+
this.capabilities.isFlying = !this.capabilities.isFlying;
290+
this.sendPlayerAbilities();
291+
this.flyToggleTimer = 0;
292+
}
293+
}
294+
}
295+
296+
if (this.capabilities.isFlying && this.isCurrentViewEntity()) {
297+
if (this.movementInput.sneak) {
298+
this.motionY -= this.capabilities.getFlySpeed() * 3.0F;
299+
}
300+
301+
if (this.movementInput.jump) {
302+
this.motionY += this.capabilities.getFlySpeed() * 3.0F;
303+
}
304+
}
305+
306+
if (this.isRidingHorse()) {
307+
if (this.horseJumpPowerCounter < 0) {
308+
++this.horseJumpPowerCounter;
309+
310+
if (this.horseJumpPowerCounter == 0) {
311+
this.horseJumpPower = 0.0F;
312+
}
313+
}
314+
315+
if (flag && !this.movementInput.jump) {
316+
this.horseJumpPowerCounter = -10;
317+
this.sendHorseJump();
318+
} else if (!flag && this.movementInput.jump) {
319+
this.horseJumpPowerCounter = 0;
320+
this.horseJumpPower = 0.0F;
321+
} else if (flag) {
322+
++this.horseJumpPowerCounter;
323+
324+
if (this.horseJumpPowerCounter < 10) {
325+
this.horseJumpPower = (float) this.horseJumpPowerCounter * 0.1F;
326+
} else {
327+
this.horseJumpPower = 0.8F + 2.0F / (float) (this.horseJumpPowerCounter - 9) * 0.1F;
328+
}
329+
}
330+
} else {
331+
this.horseJumpPower = 0.0F;
332+
}
333+
334+
super.onLivingUpdate();
335+
336+
if (this.onGround && this.capabilities.isFlying && !this.mc.playerController.isSpectatorMode()) {
337+
this.capabilities.isFlying = false;
338+
this.sendPlayerAbilities();
339+
}
340+
}
341+
162342
@Inject(method = "pushOutOfBlocks", at = @At("HEAD"), cancellable = true)
163343
private void pushOutEvent(final CallbackInfoReturnable<Boolean> callbackInfoReturnable) {
164344
final PushOutEvent event = new PushOutEvent();

0 commit comments

Comments
 (0)