Skip to content

Commit ca69b2c

Browse files
committed
Merge branch 'master' into feature/combat
2 parents 500139c + 5833d73 commit ca69b2c

File tree

269 files changed

+6356
-3216
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

269 files changed

+6356
-3216
lines changed

.github/CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ Enhancement suggestions are tracked as [GitHub issues](https://github.com/lambda
9999
- **Explain why this enhancement would be useful** to most Lambda users. You may also want to point out the other projects that solved it better and which could serve as inspiration.
100100

101101
### Your First Code Contribution
102-
First of all, make sure to read or simply check the [Official Kotlin Coding Convention](https://kotlinlang.org/docs/coding-conventions.html#control-flow-statements)
102+
First of all, make sure to read or simply check the [Official Kotlin Coding Convention](https://kotlinlang.org/docs/coding-conventions.html)
103103

104104
This is required for pull requests to be accepted, or even reviewed.
105105

build.gradle.kts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
/*
2+
* Copyright 2024 Lambda
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
118
import org.gradle.internal.jvm.*
219
import net.fabricmc.loom.api.LoomGradleExtensionAPI
320
import org.apache.tools.ant.taskdefs.condition.Os

common/src/main/java/com/lambda/mixin/MinecraftClientMixin.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020
import com.lambda.Lambda;
2121
import com.lambda.event.EventFlow;
2222
import com.lambda.event.events.ClientEvent;
23-
import com.lambda.event.events.ScreenEvent;
24-
import com.lambda.event.events.ScreenHandlerEvent;
23+
import com.lambda.event.events.InventoryEvent;
2524
import com.lambda.event.events.TickEvent;
2625
import com.lambda.module.modules.player.Interact;
2726
import net.minecraft.client.MinecraftClient;
@@ -79,20 +78,16 @@ private void onStartup(CallbackInfo ci) {
7978
private void onScreenOpen(@Nullable Screen screen, CallbackInfo ci) {
8079
if (screen == null) return;
8180
if (screen instanceof ScreenHandlerProvider<?> handledScreen) {
82-
EventFlow.post(new ScreenHandlerEvent.Open(handledScreen.getScreenHandler()));
81+
EventFlow.post(new InventoryEvent.Open(handledScreen.getScreenHandler()));
8382
}
84-
85-
EventFlow.post(new ScreenEvent.Open<>(screen));
8683
}
8784

8885
@Inject(method = "setScreen", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/Screen;removed()V", shift = At.Shift.AFTER))
8986
private void onScreenRemove(@Nullable Screen screen, CallbackInfo ci) {
9087
if (currentScreen == null) return;
9188
if (currentScreen instanceof ScreenHandlerProvider<?> handledScreen) {
92-
EventFlow.post(new ScreenHandlerEvent.Close(handledScreen.getScreenHandler()));
89+
EventFlow.post(new InventoryEvent.Close(handledScreen.getScreenHandler()));
9390
}
94-
95-
EventFlow.post(new ScreenEvent.Close<>(currentScreen));
9691
}
9792

9893
@Redirect(method = "doItemUse", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerInteractionManager;isBreakingBlock()Z"))

common/src/main/java/com/lambda/mixin/client/sound/SoundSystemMixin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
@Mixin(SoundSystem.class)
3030
public class SoundSystemMixin {
31-
@Inject(method = "play(Lnet/minecraft/client/sound/SoundInstance;)V", at = @At(value = "HEAD"), cancellable = true)
31+
@Inject(method = "play(Lnet/minecraft/client/sound/SoundInstance;)V", at = @At("HEAD"), cancellable = true)
3232
public void onPlay(SoundInstance sound, CallbackInfo ci) {
3333
if (EventFlow.post(new ClientEvent.Sound(sound)).isCanceled()) {
3434
ci.cancel();

common/src/main/java/com/lambda/mixin/entity/ClientPlayInteractionManagerMixin.java

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@
1818
package com.lambda.mixin.entity;
1919

2020
import com.lambda.event.EventFlow;
21-
import com.lambda.event.events.AttackEvent;
22-
import com.lambda.event.events.InteractionEvent;
23-
import net.minecraft.client.MinecraftClient;
21+
import com.lambda.event.events.PlayerEvent;
2422
import net.minecraft.client.network.ClientPlayerEntity;
2523
import net.minecraft.client.network.ClientPlayerInteractionManager;
2624
import net.minecraft.entity.Entity;
@@ -29,9 +27,9 @@
2927
import net.minecraft.util.ActionResult;
3028
import net.minecraft.util.Hand;
3129
import net.minecraft.util.hit.BlockHitResult;
30+
import net.minecraft.util.hit.EntityHitResult;
3231
import net.minecraft.util.math.BlockPos;
3332
import net.minecraft.util.math.Direction;
34-
import org.spongepowered.asm.mixin.Final;
3533
import org.spongepowered.asm.mixin.Mixin;
3634
import org.spongepowered.asm.mixin.Shadow;
3735
import org.spongepowered.asm.mixin.injection.At;
@@ -44,53 +42,57 @@ public class ClientPlayInteractionManagerMixin {
4442

4543
@Shadow
4644
public float currentBreakingProgress;
47-
@Final
48-
@Shadow
49-
private MinecraftClient client;
5045

51-
@Inject(method = "interactBlock", at = @At("HEAD"))
46+
@Inject(method = "interactBlock", at = @At("HEAD"), cancellable = true)
5247
public void interactBlockHead(final ClientPlayerEntity player, final Hand hand, final BlockHitResult hitResult, final CallbackInfoReturnable<ActionResult> cir) {
53-
if (client.world == null) return;
54-
EventFlow.post(new InteractionEvent.Block(client.world, hitResult));
48+
if (EventFlow.post(new PlayerEvent.Interact.Block(hand, hitResult)).isCanceled()) {
49+
cir.setReturnValue(ActionResult.FAIL);
50+
}
5551
}
5652

57-
@Inject(method = "clickSlot", at = @At("HEAD"), cancellable = true)
58-
public void clickSlotHead(int syncId, int slotId, int button, SlotActionType actionType, PlayerEntity player, CallbackInfo ci) {
59-
if (syncId != player.currentScreenHandler.syncId) return;
60-
var click = new InteractionEvent.SlotClick(syncId, slotId, button, actionType, player.currentScreenHandler);
61-
if (EventFlow.post(click).isCanceled()) ci.cancel();
62-
}
63-
64-
@Inject(method = "attackEntity", at = @At("HEAD"), cancellable = true)
65-
void onAttackPre(PlayerEntity player, Entity target, CallbackInfo ci) {
66-
if (EventFlow.post(new AttackEvent.Pre(target)).isCanceled()) ci.cancel();
53+
@Inject(method = "interactEntityAtLocation", at = @At("HEAD"), cancellable = true)
54+
public void interactEntityAtLocation(PlayerEntity player, Entity entity, EntityHitResult hitResult, Hand hand, CallbackInfoReturnable<ActionResult> cir) {
55+
if (EventFlow.post(new PlayerEvent.Interact.Entity(hand, entity, hitResult)).isCanceled()) {
56+
cir.setReturnValue(ActionResult.FAIL);
57+
}
6758
}
6859

69-
@Inject(method = "attackEntity", at = @At("TAIL"))
70-
void onAttackPost(PlayerEntity player, Entity target, CallbackInfo ci) {
71-
EventFlow.post(new AttackEvent.Post(target));
60+
@Inject(method = "interactItem", at = @At("HEAD"), cancellable = true)
61+
public void interactItemHead(PlayerEntity player, Hand hand, CallbackInfoReturnable<ActionResult> cir) {
62+
if (EventFlow.post(new PlayerEvent.Interact.Item(hand)).isCanceled()) {
63+
cir.setReturnValue(ActionResult.FAIL);
64+
}
7265
}
7366

7467
@Inject(method = "attackBlock", at = @At("HEAD"), cancellable = true)
7568
public void onAttackBlock(BlockPos pos, Direction side, CallbackInfoReturnable<Boolean> cir) {
76-
if (EventFlow.post(new InteractionEvent.BlockAttack.Pre(pos, side)).isCanceled()) cir.cancel();
69+
if (EventFlow.post(new PlayerEvent.Attack.Block(pos, side)).isCanceled()) {
70+
cir.setReturnValue(false);
71+
}
7772
}
7873

79-
@Inject(method = "attackBlock", at = @At("TAIL"))
80-
public void onAttackBlockPost(BlockPos pos, Direction side, CallbackInfoReturnable<Boolean> cir) {
81-
EventFlow.post(new InteractionEvent.BlockAttack.Post(pos, side));
74+
@Inject(method = "attackEntity", at = @At("HEAD"), cancellable = true)
75+
void onAttackPre(PlayerEntity player, Entity target, CallbackInfo ci) {
76+
if (EventFlow.post(new PlayerEvent.Attack.Entity(target)).isCanceled()) ci.cancel();
77+
}
78+
79+
@Inject(method = "clickSlot", at = @At("HEAD"), cancellable = true)
80+
public void clickSlotHead(int syncId, int slotId, int button, SlotActionType actionType, PlayerEntity player, CallbackInfo ci) {
81+
if (syncId != player.currentScreenHandler.syncId) return;
82+
var click = new PlayerEvent.SlotClick(syncId, slotId, button, actionType, player.currentScreenHandler);
83+
if (EventFlow.post(click).isCanceled()) ci.cancel();
8284
}
8385

8486
@Inject(method = "updateBlockBreakingProgress", at = @At("HEAD"), cancellable = true)
8587
private void updateBlockBreakingProgressPre(BlockPos pos, Direction side, CallbackInfoReturnable<Boolean> cir) {
86-
var event = EventFlow.post(new InteractionEvent.BreakingProgress.Pre(pos, side, currentBreakingProgress));
87-
if (event.isCanceled()) cir.cancel();
88+
var event = EventFlow.post(new PlayerEvent.Breaking.Update(pos, side, currentBreakingProgress));
89+
if (event.isCanceled()) cir.setReturnValue(false);
8890

8991
currentBreakingProgress = event.getProgress();
9092
}
9193

92-
@Inject(method = "updateBlockBreakingProgress", at = @At("TAIL"))
93-
private void updateBlockBreakingProgressPost(BlockPos pos, Direction side, CallbackInfoReturnable<Boolean> cir) {
94-
EventFlow.post(new InteractionEvent.BreakingProgress.Post(pos, side, currentBreakingProgress));
94+
@Inject(method = "cancelBlockBreaking", at = @At("HEAD"), cancellable = true)
95+
private void cancelBlockBreakingPre(CallbackInfo ci) {
96+
if (EventFlow.post(new PlayerEvent.Breaking.Cancel(currentBreakingProgress)).isCanceled()) ci.cancel();
9597
}
9698
}

common/src/main/java/com/lambda/mixin/entity/ClientPlayerEntityMixin.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@
1919

2020
import com.lambda.Lambda;
2121
import com.lambda.event.EventFlow;
22-
import com.lambda.event.events.EntityEvent;
2322
import com.lambda.event.events.MovementEvent;
23+
import com.lambda.event.events.PlayerEvent;
2424
import com.lambda.event.events.TickEvent;
2525
import com.lambda.interaction.PlayerPacketManager;
2626
import com.lambda.interaction.RotationManager;
2727
import net.minecraft.client.input.Input;
2828
import net.minecraft.client.network.ClientPlayerEntity;
2929
import net.minecraft.entity.MovementType;
30+
import net.minecraft.entity.damage.DamageSource;
3031
import net.minecraft.util.Hand;
3132
import net.minecraft.util.math.Vec3d;
3233
import org.spongepowered.asm.mixin.Mixin;
@@ -50,9 +51,6 @@ public abstract class ClientPlayerEntityMixin extends EntityMixin {
5051
@Shadow
5152
protected abstract void autoJump(float dx, float dz);
5253

53-
@Shadow
54-
public abstract boolean isUsingItem();
55-
5654
@Inject(method = "move", at = @At("HEAD"), cancellable = true)
5755
void onMove(MovementType movementType, Vec3d movement, CallbackInfo ci) {
5856
ClientPlayerEntity self = (ClientPlayerEntity) (Object) this;
@@ -63,9 +61,9 @@ void onMove(MovementType movementType, Vec3d movement, CallbackInfo ci) {
6361
float prevX = (float) self.getX();
6462
float prevZ = (float) self.getZ();
6563

66-
EventFlow.post(new MovementEvent.Pre());
64+
EventFlow.post(new MovementEvent.Player.Pre(movementType, movement));
6765
super.move(movementType, self.getVelocity());
68-
EventFlow.post(new MovementEvent.Post());
66+
EventFlow.post(new MovementEvent.Player.Post(movementType, movement));
6967

7068
float currX = (float) self.getX();
7169
float currZ = (float) self.getZ();
@@ -125,6 +123,13 @@ float fixHeldItemPitch(ClientPlayerEntity instance) {
125123

126124
@Inject(method = "swingHand", at = @At("HEAD"), cancellable = true)
127125
void onSwingHandPre(Hand hand, CallbackInfo ci) {
128-
if (EventFlow.post(new EntityEvent.SwingHand(hand)).isCanceled()) ci.cancel();
126+
if (EventFlow.post(new PlayerEvent.SwingHand(hand)).isCanceled()) ci.cancel();
127+
}
128+
129+
@Inject(method = "damage", at = @At("HEAD"), cancellable = true)
130+
public void damage(DamageSource source, float amount, CallbackInfoReturnable<Boolean> cir) {
131+
if (EventFlow.post(new PlayerEvent.Damage(source, amount)).isCanceled()) {
132+
cir.setReturnValue(false);
133+
}
129134
}
130135
}

common/src/main/java/com/lambda/mixin/entity/EntityMixin.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@
2020
import com.lambda.Lambda;
2121
import com.lambda.event.EventFlow;
2222
import com.lambda.event.events.EntityEvent;
23-
import com.lambda.event.events.WorldEvent;
23+
import com.lambda.event.events.PlayerEvent;
2424
import com.lambda.interaction.RotationManager;
2525
import com.lambda.util.math.Vec2d;
2626
import net.minecraft.entity.Entity;
2727
import net.minecraft.entity.MovementType;
28+
import net.minecraft.entity.damage.DamageSource;
2829
import net.minecraft.entity.data.TrackedData;
2930
import net.minecraft.util.math.Vec3d;
3031
import org.spongepowered.asm.mixin.Mixin;
@@ -33,6 +34,7 @@
3334
import org.spongepowered.asm.mixin.injection.Inject;
3435
import org.spongepowered.asm.mixin.injection.Redirect;
3536
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
37+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
3638

3739
@Mixin(Entity.class)
3840
public abstract class EntityMixin {
@@ -87,13 +89,23 @@ float fixDirectionPitch2(Entity entity) {
8789

8890
@Inject(method = "changeLookDirection", at = @At("HEAD"), cancellable = true)
8991
private void changeLookDirection(double cursorDeltaX, double cursorDeltaY, CallbackInfo ci) {
90-
if (EventFlow.post(new EntityEvent.ChangeLookDirection(cursorDeltaX, cursorDeltaY)).isCanceled()) ci.cancel();
92+
if (EventFlow.post(new PlayerEvent.ChangeLookDirection(cursorDeltaX, cursorDeltaY)).isCanceled()) ci.cancel();
9193
}
9294

9395
@Inject(method = "onTrackedDataSet(Lnet/minecraft/entity/data/TrackedData;)V", at = @At("TAIL"))
9496
public void onTrackedDataSet(TrackedData<?> data, CallbackInfo ci) {
9597
Entity entity = (Entity) (Object) this;
9698

97-
EventFlow.post(new WorldEvent.EntityUpdate(entity, data));
99+
EventFlow.post(new EntityEvent.EntityUpdate(entity, data));
100+
}
101+
102+
// ToDo: Does not trigger for some reason.
103+
@Inject(method = "damage", at = @At("HEAD"), cancellable = true)
104+
public void damage(DamageSource source, float amount, CallbackInfoReturnable<Boolean> cir) {
105+
Entity entity = (Entity) (Object) this;
106+
107+
if (EventFlow.post(new EntityEvent.Damage(entity, source, amount)).isCanceled()) {
108+
cir.setReturnValue(false);
109+
}
98110
}
99111
}

common/src/main/java/com/lambda/mixin/entity/LivingEntityMixin.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,15 @@ void onJump(CallbackInfo ci) {
6363

6464
@Inject(method = "travel", at = @At("HEAD"), cancellable = true)
6565
void onTravelPre(Vec3d movementInput, CallbackInfo ci) {
66-
LivingEntity self = (LivingEntity) (Object) this;
67-
if (self != Lambda.getMc().player) return;
68-
69-
if (EventFlow.post(new MovementEvent.Travel.Pre()).isCanceled()) ci.cancel();
66+
LivingEntity entity = (LivingEntity) (Object) this;
67+
if (EventFlow.post(new MovementEvent.Entity.Pre(entity, movementInput)).isCanceled()) {
68+
ci.cancel();
69+
}
7070
}
7171

7272
@Inject(method = "travel", at = @At("TAIL"))
7373
void onTravelPost(Vec3d movementInput, CallbackInfo ci) {
74-
LivingEntity self = (LivingEntity) (Object) this;
75-
if (self != Lambda.getMc().player) return;
76-
77-
EventFlow.post(new MovementEvent.Travel.Post());
74+
EventFlow.post(new MovementEvent.Entity.Post((LivingEntity) (Object) this, movementInput));
7875
}
7976

8077
@Redirect(method = "travel", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;getPitch()F"))

common/src/main/java/com/lambda/mixin/input/KeyboardMixin.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
package com.lambda.mixin.input;
1919

2020
import com.lambda.event.EventFlow;
21-
import com.lambda.event.events.KeyPressEvent;
21+
import com.lambda.event.events.KeyboardEvent;
2222
import net.minecraft.client.Keyboard;
2323
import org.spongepowered.asm.mixin.Mixin;
2424
import org.spongepowered.asm.mixin.injection.At;
@@ -28,9 +28,19 @@
2828
@Mixin(Keyboard.class)
2929
public class KeyboardMixin {
3030
@Inject(method = "onKey", at = @At("HEAD"))
31-
void onKey(long window, int key, int scancode, int action, int modifiers, CallbackInfo ci) {
31+
private void onKey(long window, int key, int scancode, int action, int modifiers, CallbackInfo ci) {
3232
if (key <= 0) return;
33-
if (action != 1) return;
34-
EventFlow.post(new KeyPressEvent(key, scancode, action, modifiers));
33+
if (action != 1) return; // TODO: Post events on both press and release ?
34+
35+
EventFlow.post(new KeyboardEvent.Press(key, scancode, action, modifiers));
36+
}
37+
38+
@Inject(method = "onChar", at = @At("HEAD"))
39+
private void onChar(long window, int codePoint, int modifiers, CallbackInfo ci) {
40+
char[] chars = Character.toChars(codePoint);
41+
42+
for (char c : chars) {
43+
EventFlow.post(new KeyboardEvent.Char(c));
44+
}
3545
}
3646
}

0 commit comments

Comments
 (0)