Skip to content

Commit db122ad

Browse files
committed
PATCHES
1 parent 3a5a5a2 commit db122ad

File tree

3 files changed

+7
-288
lines changed

3 files changed

+7
-288
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ open class CancellableEvent : Event() {
1111
}
1212
}
1313

14-
enum class EventState(val stateName: String) {
15-
PRE("PRE"), POST("POST")
14+
enum class EventState {
15+
PRE, POST
1616
}

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

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
package net.aspw.viaforgeplus.event
22

3-
class MotionEvent(
4-
var x: Double,
5-
var y: Double,
6-
var z: Double,
7-
var yaw: Float,
8-
var pitch: Float,
9-
var onGround: Boolean
10-
) : Event() {
3+
class MotionEvent : Event() {
114
var eventState: EventState = EventState.PRE
125
}
136

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

Lines changed: 4 additions & 278 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,11 @@
66
import net.aspw.viaforgeplus.event.MotionEvent;
77
import net.aspw.viaforgeplus.event.PushOutEvent;
88
import net.aspw.viaforgeplus.event.UpdateEvent;
9-
import net.minecraft.client.Minecraft;
10-
import net.minecraft.client.audio.PositionedSoundRecord;
119
import net.minecraft.client.entity.AbstractClientPlayer;
1210
import net.minecraft.client.entity.EntityPlayerSP;
13-
import net.minecraft.client.network.NetHandlerPlayClient;
14-
import net.minecraft.item.ItemSword;
15-
import net.minecraft.network.play.client.C03PacketPlayer;
16-
import net.minecraft.network.play.client.C0BPacketEntityAction;
17-
import net.minecraft.potion.Potion;
18-
import net.minecraft.util.MovementInput;
19-
import net.minecraft.util.ResourceLocation;
2011
import net.minecraft.world.World;
21-
import org.spongepowered.asm.mixin.Final;
2212
import org.spongepowered.asm.mixin.Mixin;
2313
import org.spongepowered.asm.mixin.Shadow;
24-
import org.spongepowered.asm.mixin.Unique;
2514
import org.spongepowered.asm.mixin.injection.At;
2615
import org.spongepowered.asm.mixin.injection.Inject;
2716
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@@ -30,287 +19,24 @@
3019
@Mixin(EntityPlayerSP.class)
3120
public abstract class MixinEntityPlayerSP extends AbstractClientPlayer {
3221

33-
@Shadow
34-
public boolean serverSprintState;
35-
@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
48-
@Final
49-
public NetHandlerPlayClient sendQueue;
50-
@Shadow
51-
public int positionUpdateTicks;
52-
@Shadow
53-
protected int sprintToggleTimer;
54-
@Shadow
55-
protected Minecraft mc;
56-
@Shadow
57-
private boolean serverSneakState;
58-
@Shadow
59-
private double lastReportedPosX;
60-
@Shadow
61-
private double lastReportedPosY;
62-
@Shadow
63-
private double lastReportedPosZ;
64-
@Shadow
65-
private float lastReportedYaw;
66-
@Shadow
67-
private float lastReportedPitch;
68-
@Unique
69-
private boolean lastOnGround;
70-
7122
public MixinEntityPlayerSP(World p_i45074_1_, GameProfile p_i45074_2_) {
7223
super(p_i45074_1_, p_i45074_2_);
7324
}
7425

7526
@Shadow
7627
public abstract boolean isSneaking();
7728

78-
@Shadow
79-
protected abstract boolean isCurrentViewEntity();
80-
81-
@Shadow
82-
protected abstract void sendHorseJump();
83-
84-
@Shadow
85-
public abstract boolean isRidingHorse();
86-
87-
@Inject(method = "onUpdateWalkingPlayer", at = @At("HEAD"), cancellable = true)
29+
@Inject(method = "onUpdateWalkingPlayer", at = @At("HEAD"))
8830
private void onUpdateWalkingPlayer(CallbackInfo ci) {
89-
final MotionEvent event = new MotionEvent(this.posX, this.getEntityBoundingBox().minY, this.posZ, this.rotationYaw, this.rotationPitch, this.onGround);
31+
final MotionEvent event = new MotionEvent();
9032
ProtocolInject.eventManager.callEvent(event);
91-
92-
final boolean sprinting = this.isSprinting();
93-
final boolean sneaking = this.isSneaking();
94-
95-
if (sprinting != this.serverSprintState) {
96-
if (sprinting)
97-
this.sendQueue.addToSendQueue(new C0BPacketEntityAction((EntityPlayerSP) (Object) this, C0BPacketEntityAction.Action.START_SPRINTING));
98-
else
99-
this.sendQueue.addToSendQueue(new C0BPacketEntityAction((EntityPlayerSP) (Object) this, C0BPacketEntityAction.Action.STOP_SPRINTING));
100-
101-
this.serverSprintState = sprinting;
102-
}
103-
104-
if (sneaking != this.serverSneakState) {
105-
if (sneaking)
106-
this.sendQueue.addToSendQueue(new C0BPacketEntityAction((EntityPlayerSP) (Object) this, C0BPacketEntityAction.Action.START_SNEAKING));
107-
else
108-
this.sendQueue.addToSendQueue(new C0BPacketEntityAction((EntityPlayerSP) (Object) this, C0BPacketEntityAction.Action.STOP_SNEAKING));
109-
110-
this.serverSneakState = sneaking;
111-
}
112-
113-
if (this.isCurrentViewEntity()) {
114-
float yaw = event.getYaw();
115-
float pitch = event.getPitch();
116-
117-
final double xDiff = event.getX() - this.lastReportedPosX;
118-
final double yDiff = event.getY() - this.lastReportedPosY;
119-
final double zDiff = event.getZ() - this.lastReportedPosZ;
120-
final double yawDiff = yaw - lastReportedYaw;
121-
final double pitchDiff = pitch - lastReportedPitch;
122-
boolean moved = xDiff * xDiff + yDiff * yDiff + zDiff * zDiff > 9.0E-4 || this.positionUpdateTicks >= 20;
123-
final boolean rotated = yawDiff != 0.0D || pitchDiff != 0.0D;
124-
125-
if (this.ridingEntity == null) {
126-
if (moved && rotated) {
127-
sendQueue.addToSendQueue(new C03PacketPlayer.C06PacketPlayerPosLook(posX, getEntityBoundingBox().minY, posZ, yaw, pitch, onGround));
128-
} else if (moved) {
129-
sendQueue.addToSendQueue(new C03PacketPlayer.C04PacketPlayerPosition(posX, getEntityBoundingBox().minY, posZ, onGround));
130-
} else if (rotated) {
131-
sendQueue.addToSendQueue(new C03PacketPlayer.C05PacketPlayerLook(yaw, pitch, onGround));
132-
} else {
133-
sendQueue.addToSendQueue(new C03PacketPlayer(onGround));
134-
}
135-
} else {
136-
sendQueue.addToSendQueue(new C03PacketPlayer.C06PacketPlayerPosLook(motionX, -999, motionZ, yaw, pitch, onGround));
137-
moved = false;
138-
}
139-
140-
++this.positionUpdateTicks;
141-
142-
if (moved) {
143-
lastReportedPosX = posX;
144-
lastReportedPosY = getEntityBoundingBox().minY;
145-
lastReportedPosZ = posZ;
146-
positionUpdateTicks = 0;
147-
}
148-
149-
if (rotated) {
150-
this.lastReportedYaw = yaw;
151-
this.lastReportedPitch = pitch;
152-
}
153-
}
154-
155-
if (this.isCurrentViewEntity())
156-
lastOnGround = event.getOnGround();
157-
15833
event.setEventState(EventState.POST);
159-
16034
ProtocolInject.eventManager.callEvent(event);
161-
162-
ci.cancel();
16335
}
16436

165-
@Inject(method = "onLivingUpdate", at = @At("HEAD"), cancellable = true)
37+
@Inject(method = "onLivingUpdate", at = @At("HEAD"))
16638
private void onLivingUpdate(CallbackInfo ci) {
16739
ProtocolInject.eventManager.callEvent(new UpdateEvent());
168-
if (this.sprintingTicksLeft > 0) {
169-
--this.sprintingTicksLeft;
170-
171-
if (this.sprintingTicksLeft == 0) {
172-
this.setSprinting(false);
173-
}
174-
}
175-
176-
if (this.sprintToggleTimer > 0) {
177-
--this.sprintToggleTimer;
178-
}
179-
180-
this.prevTimeInPortal = this.timeInPortal;
181-
182-
if (this.inPortal) {
183-
if (this.mc.currentScreen != null && !this.mc.currentScreen.doesGuiPauseGame()) {
184-
this.mc.displayGuiScreen(null);
185-
}
186-
187-
if (this.timeInPortal == 0.0F) {
188-
this.mc.getSoundHandler().playSound(PositionedSoundRecord.create(new ResourceLocation("portal.trigger"), this.rand.nextFloat() * 0.4F + 0.8F));
189-
}
190-
191-
this.timeInPortal += 0.0125F;
192-
193-
if (this.timeInPortal >= 1.0F) {
194-
this.timeInPortal = 1.0F;
195-
}
196-
197-
this.inPortal = false;
198-
} else if (this.isPotionActive(Potion.confusion) && this.getActivePotionEffect(Potion.confusion).getDuration() > 60) {
199-
this.timeInPortal += 0.006666667F;
200-
201-
if (this.timeInPortal > 1.0F) {
202-
this.timeInPortal = 1.0F;
203-
}
204-
} else {
205-
if (this.timeInPortal > 0.0F) {
206-
this.timeInPortal -= 0.05F;
207-
}
208-
209-
if (this.timeInPortal < 0.0F) {
210-
this.timeInPortal = 0.0F;
211-
}
212-
}
213-
214-
if (this.timeUntilPortal > 0) {
215-
--this.timeUntilPortal;
216-
}
217-
218-
final boolean flag = this.movementInput.jump;
219-
final boolean flag1 = this.movementInput.sneak;
220-
final float f = 0.8F;
221-
final boolean flag2 = this.movementInput.moveForward >= f;
222-
this.movementInput.updatePlayerMoveState();
223-
224-
if (getHeldItem() != null && (this.isUsingItem() || (getHeldItem().getItem() instanceof ItemSword && mc.thePlayer.isBlocking() && !this.isRiding()))) {
225-
this.movementInput.moveStrafe *= 0.2F;
226-
this.movementInput.moveForward *= 0.2F;
227-
this.sprintToggleTimer = 0;
228-
}
229-
230-
this.pushOutOfBlocks(this.posX - (double) this.width * 0.35D, this.getEntityBoundingBox().minY + 0.5D, this.posZ + (double) this.width * 0.35D);
231-
this.pushOutOfBlocks(this.posX - (double) this.width * 0.35D, this.getEntityBoundingBox().minY + 0.5D, this.posZ - (double) this.width * 0.35D);
232-
this.pushOutOfBlocks(this.posX + (double) this.width * 0.35D, this.getEntityBoundingBox().minY + 0.5D, this.posZ - (double) this.width * 0.35D);
233-
this.pushOutOfBlocks(this.posX + (double) this.width * 0.35D, this.getEntityBoundingBox().minY + 0.5D, this.posZ + (double) this.width * 0.35D);
234-
235-
final boolean flag3 = (float) this.getFoodStats().getFoodLevel() > 6.0F || this.capabilities.allowFlying;
236-
237-
if (this.onGround && !flag1 && !flag2 && this.movementInput.moveForward >= f && !this.isSprinting() && flag3 && !this.isUsingItem() && !this.isPotionActive(Potion.blindness)) {
238-
if (this.sprintToggleTimer <= 0 && !this.mc.gameSettings.keyBindSprint.isKeyDown()) {
239-
this.sprintToggleTimer = 7;
240-
} else {
241-
this.setSprinting(true);
242-
}
243-
}
244-
245-
if (!this.isSprinting() && this.movementInput.moveForward >= f && flag3 && !this.isUsingItem() && !this.isPotionActive(Potion.blindness) && this.mc.gameSettings.keyBindSprint.isKeyDown())
246-
this.setSprinting(true);
247-
248-
if (this.isSprinting() && (this.movementInput.moveForward < f || mc.thePlayer.isCollidedHorizontally || !flag3))
249-
this.setSprinting(false);
250-
251-
if (this.capabilities.allowFlying) {
252-
if (this.mc.playerController.isSpectatorMode()) {
253-
if (!this.capabilities.isFlying) {
254-
this.capabilities.isFlying = true;
255-
this.sendPlayerAbilities();
256-
}
257-
} else if (!flag && this.movementInput.jump) {
258-
if (this.flyToggleTimer == 0) {
259-
this.flyToggleTimer = 7;
260-
} else {
261-
this.capabilities.isFlying = !this.capabilities.isFlying;
262-
this.sendPlayerAbilities();
263-
this.flyToggleTimer = 0;
264-
}
265-
}
266-
}
267-
268-
if (this.capabilities.isFlying && this.isCurrentViewEntity()) {
269-
if (this.movementInput.sneak) {
270-
this.motionY -= this.capabilities.getFlySpeed() * 3.0F;
271-
}
272-
273-
if (this.movementInput.jump) {
274-
this.motionY += this.capabilities.getFlySpeed() * 3.0F;
275-
}
276-
}
277-
278-
if (this.isRidingHorse()) {
279-
if (this.horseJumpPowerCounter < 0) {
280-
++this.horseJumpPowerCounter;
281-
282-
if (this.horseJumpPowerCounter == 0) {
283-
this.horseJumpPower = 0.0F;
284-
}
285-
}
286-
287-
if (flag && !this.movementInput.jump) {
288-
this.horseJumpPowerCounter = -10;
289-
this.sendHorseJump();
290-
} else if (!flag && this.movementInput.jump) {
291-
this.horseJumpPowerCounter = 0;
292-
this.horseJumpPower = 0.0F;
293-
} else if (flag) {
294-
++this.horseJumpPowerCounter;
295-
296-
if (this.horseJumpPowerCounter < 10) {
297-
this.horseJumpPower = (float) this.horseJumpPowerCounter * 0.1F;
298-
} else {
299-
this.horseJumpPower = 0.8F + 2.0F / (float) (this.horseJumpPowerCounter - 9) * 0.1F;
300-
}
301-
}
302-
} else {
303-
this.horseJumpPower = 0.0F;
304-
}
305-
306-
super.onLivingUpdate();
307-
308-
if (this.onGround && this.capabilities.isFlying && !this.mc.playerController.isSpectatorMode()) {
309-
this.capabilities.isFlying = false;
310-
this.sendPlayerAbilities();
311-
}
312-
313-
ci.cancel();
31440
}
31541

31642
@Inject(method = "pushOutOfBlocks", at = @At("HEAD"), cancellable = true)
@@ -322,4 +48,4 @@ private void pushOutEvent(final CallbackInfoReturnable<Boolean> callbackInfoRetu
32248
if (event.isCancelled())
32349
callbackInfoReturnable.setReturnValue(false);
32450
}
325-
}
51+
}

0 commit comments

Comments
 (0)