Skip to content

Commit 8783dd0

Browse files
committed
Migrate to yarn mappings + 1.21.4 Update
1 parent e861daa commit 8783dd0

25 files changed

+190
-348
lines changed

.github/workflows/build-gradle.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ jobs:
211211
fabric
212212
213213
game-versions: |
214-
>=1.21
214+
1.21.4
215215
216216
retry-attempts: 2
217217
retry-delay: 10000

fabric/build.gradle.kts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,7 @@ dependencies {
3636
implementation(project(":common"))
3737

3838
minecraft("com.mojang:minecraft:${rootProject.property("minecraft_version")}")
39-
mappings(loom.layered {
40-
officialMojangMappings()
41-
parchment("org.parchmentmc.data:parchment-1.21:${rootProject.property("parchment_mappings")}")
42-
})
39+
mappings("net.fabricmc:yarn:${rootProject.property("yarn_mappings")}")
4340
modImplementation("net.fabricmc:fabric-loader:${rootProject.property("loader_version")}")
4441
modImplementation(fabricApi.module("fabric-lifecycle-events-v1", "${rootProject.property("fabric_version")}"))
4542
modImplementation(fabricApi.module("fabric-events-interaction-v0", "${rootProject.property("fabric_version")}"))

fabric/src/main/java/me/caseload/knockbacksync/callback/PlayerVelocityEvent.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,23 @@
22

33
import net.fabricmc.fabric.api.event.Event;
44
import net.fabricmc.fabric.api.event.EventFactory;
5-
import net.minecraft.server.level.ServerPlayer;
6-
import net.minecraft.world.InteractionResult;
7-
import net.minecraft.world.phys.Vec3;
5+
import net.minecraft.server.network.ServerPlayerEntity;
6+
import net.minecraft.util.ActionResult;
7+
import net.minecraft.util.math.Vec3d;
88

99
public interface PlayerVelocityEvent {
1010
Event<PlayerVelocityEvent> EVENT = EventFactory.createArrayBacked(PlayerVelocityEvent.class,
1111
(listeners) -> (player, velocity) -> {
1212
for (PlayerVelocityEvent listener : listeners) {
13-
InteractionResult result = listener.onVelocityChange(player, velocity);
13+
ActionResult result = listener.onVelocityChange(player, velocity);
1414

15-
if (result != InteractionResult.PASS) {
15+
if (result != ActionResult.PASS) {
1616
return result;
1717
}
1818
}
1919

20-
return InteractionResult.PASS;
20+
return ActionResult.PASS;
2121
});
2222

23-
InteractionResult onVelocityChange(ServerPlayer player, Vec3 velocity);
23+
ActionResult onVelocityChange(ServerPlayerEntity player, Vec3d velocity);
2424
}

fabric/src/main/java/me/caseload/knockbacksync/entity/EntityTickManager.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
import me.caseload.knockbacksync.Base;
44
import me.caseload.knockbacksync.ConfigWrapper;
55
import me.caseload.knockbacksync.event.events.ConfigReloadEvent;
6+
import net.minecraft.entity.EntityType;
67
import me.caseload.knockbacksync.event.KBSyncEventHandler;
7-
import net.minecraft.world.entity.EntityType;
8-
98
import java.util.HashMap;
109
import java.util.Map;
1110
import java.util.Optional;
@@ -32,9 +31,9 @@ private static void updateTickIntervals(ConfigWrapper configWrapper) {
3231
customTickIntervals.clear();
3332
for (String entityKey : configWrapper.getKeys("entity_tick_intervals")) {
3433
try {
35-
Optional<EntityType<?>> entityType = EntityType.byString(entityKey.toLowerCase());
34+
Optional<EntityType<?>> entityType = EntityType.get(entityKey.toLowerCase());
3635
if (entityType.isPresent()) {
37-
int interval = configWrapper.getInt("entity_tick_intervals." + entityKey, entityType.get().updateInterval());
36+
int interval = configWrapper.getInt("entity_tick_intervals." + entityKey, entityType.get().getTrackTickInterval());
3837
customTickIntervals.put(entityType.get(), interval);
3938
}
4039
} catch (IllegalArgumentException e) {
@@ -44,6 +43,6 @@ private static void updateTickIntervals(ConfigWrapper configWrapper) {
4443
}
4544

4645
public static int getCustomUpdateInterval(EntityType<?> entityType) {
47-
return customTickIntervals.getOrDefault(entityType, entityType.updateInterval());
46+
return customTickIntervals.getOrDefault(entityType, entityType.getTrackTickInterval());
4847
}
4948
}

fabric/src/main/java/me/caseload/knockbacksync/listener/fabric/FabricPlayerDamageListener.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,24 @@
55
import me.caseload.knockbacksync.player.FabricPlayer;
66
import me.caseload.knockbacksync.player.PlatformPlayer;
77
import net.fabricmc.fabric.api.event.player.AttackEntityCallback;
8-
import net.minecraft.server.level.ServerPlayer;
9-
import net.minecraft.world.InteractionResult;
10-
import net.minecraft.world.entity.Entity;
11-
import net.minecraft.world.entity.player.Player;
8+
import net.minecraft.entity.Entity;
9+
import net.minecraft.entity.player.PlayerEntity;
10+
import net.minecraft.server.network.ServerPlayerEntity;
11+
import net.minecraft.util.ActionResult;
1212

1313
public class FabricPlayerDamageListener extends PlayerDamageListener {
1414

1515
public void register() {
1616
AttackEntityCallback.EVENT.register((player, world, hand, entity, source) -> {
17-
onPlayerDamage((ServerPlayer) player, entity);
18-
return InteractionResult.PASS;
17+
onPlayerDamage((ServerPlayerEntity) player, entity);
18+
return ActionResult.PASS;
1919
});
2020
}
2121

22-
private void onPlayerDamage(ServerPlayer attacker, Entity victimEntity) {
23-
if (victimEntity instanceof Player victim) {
22+
private void onPlayerDamage(ServerPlayerEntity attacker, Entity victimEntity) {
23+
if (victimEntity instanceof PlayerEntity victim) {
2424
PlatformPlayer platformAttacker = new FabricPlayer(attacker);
25-
PlatformPlayer platformVictim = new FabricPlayer((ServerPlayer) victim);
25+
PlatformPlayer platformVictim = new FabricPlayer((ServerPlayerEntity) victim);
2626
super.onPlayerDamage(platformVictim, platformAttacker); // Call the shared method
2727
}
2828
}

fabric/src/main/java/me/caseload/knockbacksync/listener/fabric/FabricPlayerKnockbackListener.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,27 @@
44
import me.caseload.knockbacksync.callback.PlayerVelocityEvent;
55
import me.caseload.knockbacksync.listener.PlayerKnockbackListener;
66
import me.caseload.knockbacksync.player.FabricPlayer;
7-
import net.minecraft.world.InteractionResult;
8-
import net.minecraft.world.damagesource.DamageSource;
9-
import net.minecraft.world.damagesource.DamageTypes;
7+
import net.minecraft.entity.damage.DamageSource;
8+
import net.minecraft.entity.damage.DamageTypes;
9+
import net.minecraft.util.ActionResult;
1010

1111
public class FabricPlayerKnockbackListener extends PlayerKnockbackListener {
1212

1313
public void register() {
1414
PlayerVelocityEvent.EVENT.register((player, velocity) -> {
15-
DamageSource lastDamageSource = player.getLastDamageSource();
15+
DamageSource lastDamageSource = player.getRecentDamageSource();
1616
if (lastDamageSource == null)
17-
return InteractionResult.PASS;
17+
return ActionResult.PASS;
1818

1919
// Check if the damage is from a player attack
20-
if (!lastDamageSource.is(DamageTypes.PLAYER_ATTACK))
21-
return InteractionResult.PASS;
20+
if (!lastDamageSource.isOf(DamageTypes.PLAYER_ATTACK))
21+
return ActionResult.PASS;
2222

2323
onPlayerVelocity(new FabricPlayer(player), new Vector3d(velocity.x, velocity.y, velocity.z));
2424
// This SHOULD mean we return original velocity for Fabric (no modification here)
2525
// But since we set it ourselves due to following bukkit's design patterns and doing victim
2626
// We return a pass so velocity isn't set twice
27-
return InteractionResult.PASS;
27+
return ActionResult.PASS;
2828
});
2929
}
3030
}

fabric/src/main/java/me/caseload/knockbacksync/mixin/ChunkMapMixin.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
package me.caseload.knockbacksync.mixin;
22

33
import me.caseload.knockbacksync.entity.EntityTickManager;
4-
import net.minecraft.server.level.ChunkMap;
5-
import net.minecraft.world.entity.EntityType;
4+
import net.minecraft.entity.EntityType;
5+
import net.minecraft.server.world.ServerChunkLoadingManager;
66
import org.spongepowered.asm.mixin.Mixin;
77
import org.spongepowered.asm.mixin.injection.At;
88
import org.spongepowered.asm.mixin.injection.Redirect;
99

10-
@Mixin(ChunkMap.class)
10+
@Mixin(ServerChunkLoadingManager.class)
1111
public abstract class ChunkMapMixin {
1212

13-
@Redirect(method = "addEntity", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/EntityType;updateInterval()I"))
13+
@Redirect(method = "loadEntity", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/EntityType;getTrackTickInterval()I"))
1414
private int getCustomUpdateInterval(EntityType<?> entityType) {
1515
return EntityTickManager.getCustomUpdateInterval(entityType);
1616
}

fabric/src/main/java/me/caseload/knockbacksync/mixin/ChunkMapMixinF.java

Lines changed: 0 additions & 86 deletions
This file was deleted.

fabric/src/main/java/me/caseload/knockbacksync/mixin/CommandStackSourceAccessor.java

Lines changed: 0 additions & 14 deletions
This file was deleted.

fabric/src/main/java/me/caseload/knockbacksync/mixin/PlayerMixin.java

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,34 @@
11
package me.caseload.knockbacksync.mixin;
22

33
import me.caseload.knockbacksync.callback.PlayerVelocityEvent;
4-
import net.minecraft.network.protocol.game.ClientboundSetEntityMotionPacket;
5-
import net.minecraft.server.level.ServerPlayer;
6-
import net.minecraft.world.InteractionResult;
7-
import net.minecraft.world.entity.Entity;
8-
import net.minecraft.world.entity.player.Player;
9-
import net.minecraft.world.phys.Vec3;
4+
import net.minecraft.entity.Entity;
5+
import net.minecraft.entity.player.PlayerEntity;
6+
import net.minecraft.network.packet.s2c.play.EntityVelocityUpdateS2CPacket;
7+
import net.minecraft.server.network.ServerPlayerEntity;
8+
import net.minecraft.util.ActionResult;
9+
import net.minecraft.util.math.Vec3d;
1010
import org.spongepowered.asm.mixin.Mixin;
1111
import org.spongepowered.asm.mixin.injection.At;
1212
import org.spongepowered.asm.mixin.injection.Inject;
1313
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
1414

15-
@Mixin(Player.class)
15+
@Mixin(PlayerEntity.class)
1616
public class PlayerMixin {
17-
18-
@Inject(method = "attack", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/protocol/game/ClientboundSetEntityMotionPacket;<init>(Lnet/minecraft/world/entity/Entity;)V"), cancellable = true)
17+
@Inject(method = "attack", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/packet/s2c/play/EntityVelocityUpdateS2CPacket;<init>(Lnet/minecraft/entity/Entity;)V"), cancellable = true)
1918
private void onAttack(Entity target, CallbackInfo ci) {
20-
if (target instanceof ServerPlayer serverPlayer && target.hurtMarked) {
21-
Vec3 velocity = target.getDeltaMovement();
19+
if (target instanceof ServerPlayerEntity serverPlayer && target.velocityModified) {
20+
Vec3d velocity = target.getVelocity();
2221

23-
InteractionResult result = PlayerVelocityEvent.EVENT.invoker().onVelocityChange(serverPlayer, velocity);
22+
ActionResult result = PlayerVelocityEvent.EVENT.invoker().onVelocityChange(serverPlayer, velocity);
2423

25-
if (result == InteractionResult.FAIL) {
26-
target.hurtMarked = false;
24+
if (result == ActionResult.FAIL) {
25+
target.velocityModified = false;
2726
ci.cancel(); // Prevent sending the velocity packet
28-
} else if (result == InteractionResult.SUCCESS) {
27+
} else if (result == ActionResult.SUCCESS) {
2928
// Currently unnecessary since we do this in the handler, will move later
30-
target.setDeltaMovement(velocity);
31-
serverPlayer.connection.send(new ClientboundSetEntityMotionPacket(target));
32-
target.hurtMarked = false;
29+
target.setVelocity(velocity);
30+
serverPlayer.networkHandler.sendPacket(new EntityVelocityUpdateS2CPacket(target));
31+
target.velocityModified = false;
3332
ci.cancel(); // Prevent sending the original velocity packet
3433
}
3534
}

0 commit comments

Comments
 (0)