Migrate to yarn mappings + 1.21.4 Update

This commit is contained in:
Axionize committed 2025-03-23 09:54:59 -04:00
1 parent e861daa8c1
commit 8783dd0683
25 files changed
+190 -348

No files matched your search

+1 -1
View File
@@ -211,7 +211,7 @@ jobs:
fabric
game-versions: |
>=1.21
1.21.4
retry-attempts: 2
retry-delay: 10000
+1 -4
View File
@@ -36,10 +36,7 @@ dependencies {
implementation(project(":common"))
minecraft("com.mojang:minecraft:${rootProject.property("minecraft_version")}")
mappings(loom.layered {
officialMojangMappings()
parchment("org.parchmentmc.data:parchment-1.21:${rootProject.property("parchment_mappings")}")
})
mappings("net.fabricmc:yarn:${rootProject.property("yarn_mappings")}")
modImplementation("net.fabricmc:fabric-loader:${rootProject.property("loader_version")}")
modImplementation(fabricApi.module("fabric-lifecycle-events-v1", "${rootProject.property("fabric_version")}"))
modImplementation(fabricApi.module("fabric-events-interaction-v0", "${rootProject.property("fabric_version")}"))
@@ -2,23 +2,23 @@ package me.caseload.knockbacksync.callback;
import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.EventFactory;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.phys.Vec3;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.ActionResult;
import net.minecraft.util.math.Vec3d;
public interface PlayerVelocityEvent {
Event<PlayerVelocityEvent> EVENT = EventFactory.createArrayBacked(PlayerVelocityEvent.class,
(listeners) -> (player, velocity) -> {
for (PlayerVelocityEvent listener : listeners) {
InteractionResult result = listener.onVelocityChange(player, velocity);
ActionResult result = listener.onVelocityChange(player, velocity);
if (result != InteractionResult.PASS) {
if (result != ActionResult.PASS) {
return result;
}
}
return InteractionResult.PASS;
return ActionResult.PASS;
});
InteractionResult onVelocityChange(ServerPlayer player, Vec3 velocity);
ActionResult onVelocityChange(ServerPlayerEntity player, Vec3d velocity);
}
@@ -3,9 +3,8 @@ package me.caseload.knockbacksync.entity;
import me.caseload.knockbacksync.Base;
import me.caseload.knockbacksync.ConfigWrapper;
import me.caseload.knockbacksync.event.events.ConfigReloadEvent;
import net.minecraft.entity.EntityType;
import me.caseload.knockbacksync.event.KBSyncEventHandler;
import net.minecraft.world.entity.EntityType;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
@@ -32,9 +31,9 @@ public class EntityTickManager {
customTickIntervals.clear();
for (String entityKey : configWrapper.getKeys("entity_tick_intervals")) {
try {
Optional<EntityType<?>> entityType = EntityType.byString(entityKey.toLowerCase());
Optional<EntityType<?>> entityType = EntityType.get(entityKey.toLowerCase());
if (entityType.isPresent()) {
int interval = configWrapper.getInt("entity_tick_intervals." + entityKey, entityType.get().updateInterval());
int interval = configWrapper.getInt("entity_tick_intervals." + entityKey, entityType.get().getTrackTickInterval());
customTickIntervals.put(entityType.get(), interval);
}
} catch (IllegalArgumentException e) {
@@ -44,6 +43,6 @@ public class EntityTickManager {
}
public static int getCustomUpdateInterval(EntityType<?> entityType) {
return customTickIntervals.getOrDefault(entityType, entityType.updateInterval());
return customTickIntervals.getOrDefault(entityType, entityType.getTrackTickInterval());
}
}
@@ -5,24 +5,24 @@ import me.caseload.knockbacksync.listener.PlayerDamageListener;
import me.caseload.knockbacksync.player.FabricPlayer;
import me.caseload.knockbacksync.player.PlatformPlayer;
import net.fabricmc.fabric.api.event.player.AttackEntityCallback;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.ActionResult;
public class FabricPlayerDamageListener extends PlayerDamageListener {
public void register() {
AttackEntityCallback.EVENT.register((player, world, hand, entity, source) -> {
onPlayerDamage((ServerPlayer) player, entity);
return InteractionResult.PASS;
onPlayerDamage((ServerPlayerEntity) player, entity);
return ActionResult.PASS;
});
}
private void onPlayerDamage(ServerPlayer attacker, Entity victimEntity) {
if (victimEntity instanceof Player victim) {
private void onPlayerDamage(ServerPlayerEntity attacker, Entity victimEntity) {
if (victimEntity instanceof PlayerEntity victim) {
PlatformPlayer platformAttacker = new FabricPlayer(attacker);
PlatformPlayer platformVictim = new FabricPlayer((ServerPlayer) victim);
PlatformPlayer platformVictim = new FabricPlayer((ServerPlayerEntity) victim);
super.onPlayerDamage(platformVictim, platformAttacker); // Call the shared method
}
}
@@ -4,27 +4,27 @@ import com.github.retrooper.packetevents.util.Vector3d;
import me.caseload.knockbacksync.callback.PlayerVelocityEvent;
import me.caseload.knockbacksync.listener.PlayerKnockbackListener;
import me.caseload.knockbacksync.player.FabricPlayer;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.damagesource.DamageTypes;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.damage.DamageTypes;
import net.minecraft.util.ActionResult;
public class FabricPlayerKnockbackListener extends PlayerKnockbackListener {
public void register() {
PlayerVelocityEvent.EVENT.register((player, velocity) -> {
DamageSource lastDamageSource = player.getLastDamageSource();
DamageSource lastDamageSource = player.getRecentDamageSource();
if (lastDamageSource == null)
return InteractionResult.PASS;
return ActionResult.PASS;
// Check if the damage is from a player attack
if (!lastDamageSource.is(DamageTypes.PLAYER_ATTACK))
return InteractionResult.PASS;
if (!lastDamageSource.isOf(DamageTypes.PLAYER_ATTACK))
return ActionResult.PASS;
onPlayerVelocity(new FabricPlayer(player), new Vector3d(velocity.x, velocity.y, velocity.z));
// This SHOULD mean we return original velocity for Fabric (no modification here)
// But since we set it ourselves due to following bukkit's design patterns and doing victim
// We return a pass so velocity isn't set twice
return InteractionResult.PASS;
return ActionResult.PASS;
});
}
}
@@ -1,16 +1,16 @@
package me.caseload.knockbacksync.mixin;
import me.caseload.knockbacksync.entity.EntityTickManager;
import net.minecraft.server.level.ChunkMap;
import net.minecraft.world.entity.EntityType;
import net.minecraft.entity.EntityType;
import net.minecraft.server.world.ServerChunkLoadingManager;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
@Mixin(ChunkMap.class)
@Mixin(ServerChunkLoadingManager.class)
public abstract class ChunkMapMixin {
@Redirect(method = "addEntity", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/EntityType;updateInterval()I"))
@Redirect(method = "loadEntity", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/EntityType;getTrackTickInterval()I"))
private int getCustomUpdateInterval(EntityType<?> entityType) {
return EntityTickManager.getCustomUpdateInterval(entityType);
}
@@ -1,86 +0,0 @@
//package me.caseload.knockbacksync.mixin;
//
//import me.caseload.knockbacksync.ConfigWrapper;
//import me.caseload.knockbacksync.KnockbackSyncBase;
//import me.caseload.knockbacksync.event.ConfigReloadEvent;
//import me.caseload.knockbacksync.event.KBSyncEventHandler;
//import me.caseload.knockbacksync.util.CustomUpdateIntervals;
//import net.minecraft.Util;
//import net.minecraft.server.level.ChunkMap;
//import net.minecraft.server.level.ServerLevel;
//import net.minecraft.server.level.ServerPlayer;
//import net.minecraft.world.entity.Entity;
//import net.minecraft.world.entity.EntityType;
//import net.minecraft.world.entity.boss.EnderDragonPart;
//import org.spongepowered.asm.mixin.Final;
//import org.spongepowered.asm.mixin.Mixin;
//import org.spongepowered.asm.mixin.Shadow;
//import org.spongepowered.asm.mixin.injection.At;
//import org.spongepowered.asm.mixin.injection.Inject;
//import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
//
//import java.util.HashMap;
//import java.util.Map;
//
//@Mixin(ChunkMap.class)
//public class ChunkMapMixin {
//
// @Shadow @Final
// private Map<Integer, ChunkMap.TrackedEntity> entityMap;
// @Shadow @Final private ServerLevel level;
//
// @Inject(method = "addEntity", at = @At("HEAD"), cancellable = true)
// private void onAddEntity(Entity entity, CallbackInfo ci) {
// if (!(entity instanceof EnderDragonPart)) {
// EntityType<?> entityType = entity.getType();
// int trackingRange = entityType.clientTrackingRange() * 16;
//
// if (trackingRange != 0) {
// String entityTypeName = entityType.builtInRegistryHolder().getRegisteredName();
// ConfigWrapper config = KnockbackSyncBase.INSTANCE.getConfigManager().getConfigWrapper();
//
// int defaultInterval = entityType.updateInterval();
// int customInterval = config.getInt("entity_update_intervals." + entityTypeName, defaultInterval);
//
// if (this.entityMap.containsKey(entity.getId())) {
// throw (IllegalStateException) Util.pauseInIde(new IllegalStateException("Entity is already tracked!"));
// } else {
// ChunkMap.TrackedEntity trackedEntity = new ChunkMap.TrackedEntity(entity, trackingRange, customInterval, entityType.trackDeltas());
// this.entityMap.put(entity.getId(), trackedEntity);
// trackedEntity.updatePlayers(this.level.players());
//
// if (entity instanceof ServerPlayer serverPlayer) {
// this.updatePlayerStatus(serverPlayer, true);
//
// for (ChunkMap.TrackedEntity trackedEntity2 : this.entityMap.values()) {
// if (trackedEntity2.entity != serverPlayer) {
// trackedEntity2.updatePlayer(serverPlayer);
// }
// }
// }
// }
// }
// }
//
// ci.cancel();
// }
//
// @Shadow
// private void updatePlayerStatus(ServerPlayer player, boolean track) {
// // This is a shadow method, implementation is provided by Minecraft
// }
//
// @KBSyncEventHandler
// public void onConfigReload(ConfigReloadEvent event) {
// Map<String, Integer> newIntervals = CustomUpdateIntervals.loadEntityIntervalsFromConfig();
//
// for (ChunkMap.TrackedEntity trackedEntity : this.entityMap.values()) {
// Entity entity = trackedEntity.entity;
// String entityTypeName = entity.getType().builtInRegistryHolder().getRegisteredName();
// int newInterval = newIntervals.getOrDefault(entityTypeName, entity.getType().updateInterval());
//
// // Assuming TrackedEntity has a method to update its update interval
// trackedEntity.setUpdateInterval(newInterval);
// }
// }
//}
@@ -1,14 +0,0 @@
package me.caseload.knockbacksync.mixin;
import net.minecraft.commands.CommandSource;
import net.minecraft.commands.CommandSourceStack;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
@Mixin(CommandSourceStack.class)
public interface CommandStackSourceAccessor {
@Accessor("source")
CommandSource getSource();
}
@@ -1,35 +1,34 @@
package me.caseload.knockbacksync.mixin;
import me.caseload.knockbacksync.callback.PlayerVelocityEvent;
import net.minecraft.network.protocol.game.ClientboundSetEntityMotionPacket;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.phys.Vec3;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.network.packet.s2c.play.EntityVelocityUpdateS2CPacket;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.ActionResult;
import net.minecraft.util.math.Vec3d;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(Player.class)
@Mixin(PlayerEntity.class)
public class PlayerMixin {
@Inject(method = "attack", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/protocol/game/ClientboundSetEntityMotionPacket;<init>(Lnet/minecraft/world/entity/Entity;)V"), cancellable = true)
@Inject(method = "attack", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/packet/s2c/play/EntityVelocityUpdateS2CPacket;<init>(Lnet/minecraft/entity/Entity;)V"), cancellable = true)
private void onAttack(Entity target, CallbackInfo ci) {
if (target instanceof ServerPlayer serverPlayer && target.hurtMarked) {
Vec3 velocity = target.getDeltaMovement();
if (target instanceof ServerPlayerEntity serverPlayer && target.velocityModified) {
Vec3d velocity = target.getVelocity();
InteractionResult result = PlayerVelocityEvent.EVENT.invoker().onVelocityChange(serverPlayer, velocity);
ActionResult result = PlayerVelocityEvent.EVENT.invoker().onVelocityChange(serverPlayer, velocity);
if (result == InteractionResult.FAIL) {
target.hurtMarked = false;
if (result == ActionResult.FAIL) {
target.velocityModified = false;
ci.cancel(); // Prevent sending the velocity packet
} else if (result == InteractionResult.SUCCESS) {
} else if (result == ActionResult.SUCCESS) {
// Currently unnecessary since we do this in the handler, will move later
target.setDeltaMovement(velocity);
serverPlayer.connection.send(new ClientboundSetEntityMotionPacket(target));
target.hurtMarked = false;
target.setVelocity(velocity);
serverPlayer.networkHandler.sendPacket(new EntityVelocityUpdateS2CPacket(target));
target.velocityModified = false;
ci.cancel(); // Prevent sending the original velocity packet
}
}
@@ -1,11 +1,11 @@
package me.caseload.knockbacksync.mixin;
import me.caseload.knockbacksync.callback.PlayerVelocityEvent;
import net.minecraft.server.level.ServerEntity;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.phys.Vec3;
import net.minecraft.entity.Entity;
import net.minecraft.server.network.EntityTrackerEntry;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.ActionResult;
import net.minecraft.util.math.Vec3d;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
@@ -13,7 +13,7 @@ import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(ServerEntity.class)
@Mixin(EntityTrackerEntry.class)
public class ServerEntityMixin {
@Shadow
@@ -21,19 +21,19 @@ public class ServerEntityMixin {
private Entity entity;
// Velocity event
@Inject(method = "sendChanges", at = @At(value = "FIELD", target = "Lnet/minecraft/world/entity/Entity;hurtMarked:Z", ordinal = 1), cancellable = true)
@Inject(method = "tick", at = @At(value = "FIELD", target = "Lnet/minecraft/entity/Entity;velocityModified:Z", ordinal = 1), cancellable = true)
private void onSendChanges(CallbackInfo ci) {
if (this.entity.hurtMarked && this.entity instanceof ServerPlayer player) {
Vec3 velocity = player.getDeltaMovement();
if (this.entity.velocityModified && this.entity instanceof ServerPlayerEntity player) {
Vec3d velocity = player.getVelocity();
InteractionResult result = PlayerVelocityEvent.EVENT.invoker().onVelocityChange(player, velocity);
ActionResult result = PlayerVelocityEvent.EVENT.invoker().onVelocityChange(player, velocity);
if (result == InteractionResult.FAIL) {
this.entity.hurtMarked = false;
if (result == ActionResult.FAIL) {
this.entity.velocityModified = false;
ci.cancel();
} else if (result == InteractionResult.SUCCESS) {
} else if (result == ActionResult.SUCCESS) {
// Currently unnecessary since we do this in the handler, will move later
player.setDeltaMovement(velocity);
player.setVelocity(velocity);
}
}
}
@@ -1,22 +1,21 @@
package me.caseload.knockbacksync.mixin;
import me.caseload.knockbacksync.callback.TickRateChangeEvent;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.TickRateManager;
import net.minecraft.world.tick.TickManager;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(TickRateManager.class)
@Mixin(TickManager.class)
public class TickRateManagerMixin {
@Shadow
protected float tickrate;
protected float tickRate;
@Inject(method = "setTickRate", at = @At("HEAD"))
private void onSetTickRate(float tickRate, CallbackInfo ci) {
float oldTickRate = this.tickrate;
float oldTickRate = this.tickRate;
TickRateChangeEvent.EVENT.invoker().onTickRateChange(oldTickRate, tickRate);
}
}
@@ -1,41 +0,0 @@
//package me.caseload.knockbacksync.mixin;
//
//import me.caseload.knockbacksync.ConfigWrapper;
//import me.caseload.knockbacksync.KnockbackSyncBase;
//import net.minecraft.core.SectionPos;
//import net.minecraft.server.level.ChunkMap;
//import net.minecraft.server.level.ServerEntity;
//import net.minecraft.world.entity.Entity;
//import org.spongepowered.asm.mixin.Mixin;
//import org.spongepowered.asm.mixin.Shadow;
//import org.spongepowered.asm.mixin.gen.Accessor;
//import org.spongepowered.asm.mixin.injection.At;
//import org.spongepowered.asm.mixin.injection.Inject;
//import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
//
//@Mixin(ChunkMap.TrackedEntity.class)
//public class TrackedEntityMixin {
// @Shadow
// ServerEntity serverEntity;
// Entity entity;
// int range;
// SectionPos lastSectionPos;
//
// @Inject(method = "<init>", at = @At("HEAD"))
// private void onInit(ChunkMap outer, Entity entity, int range, int updateInterval, boolean trackDelta, CallbackInfo ci) {
//
// String entityTypeName = entity.getType().builtInRegistryHolder().getRegisteredName();
// ConfigWrapper config = KnockbackSyncBase.INSTANCE.getConfigManager().getConfigWrapper();
// int customInterval = config.getInt("entity_update_intervals." + entityTypeName, updateInterval);
//
// this.serverEntity = new ServerEntity(ChunkMap.this.level, entity, customInterval, trackDelta, this::broadcast);
// this.entity = entity;
// this.range = range;
// this.lastSectionPos = SectionPos.of(entity);
// }
//
//// @Accessor("updateInterval")
//// public void setUpdateInterval(int interval) {
// // This method will be implemented by the mixin system
//// }
//}
@@ -4,21 +4,21 @@ import me.caseload.knockbacksync.player.FabricPlayer;
import me.caseload.knockbacksync.player.PlatformPlayer;
import me.caseload.knockbacksync.sender.Sender;
import me.lucko.fabric.api.permissions.v0.Permissions;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.server.command.ServerCommandSource;
public class FabricPermissionChecker implements PermissionChecker {
public boolean hasPermission(CommandSourceStack source, String permission) {
public boolean hasPermission(ServerCommandSource source, String permission) {
return Permissions.check(source, permission, false);
}
public boolean hasPermission(CommandSourceStack source, String permission, boolean defaultIfUnset) {
public boolean hasPermission(ServerCommandSource source, String permission, boolean defaultIfUnset) {
return Permissions.check(source, permission, defaultIfUnset);
}
@Override
public boolean hasPermission(Object nativeType, String s, boolean defaultIfUnset) {
if (nativeType instanceof CommandSourceStack commandSourceStack) {
if (nativeType instanceof ServerCommandSource commandSourceStack) {
return Permissions.check(commandSourceStack, s, defaultIfUnset);
}
throw new IllegalArgumentException();
@@ -6,18 +6,20 @@ import com.github.retrooper.packetevents.protocol.world.BoundingBox;
import com.github.retrooper.packetevents.util.Vector3d;
import me.caseload.knockbacksync.world.FabricWorld;
import me.caseload.knockbacksync.world.PlatformWorld;
import net.minecraft.core.Holder;
import net.minecraft.core.registries.Registries;
import net.minecraft.data.registries.VanillaRegistries;
import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.item.enchantment.Enchantment;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraft.world.item.enchantment.Enchantments;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.enchantment.Enchantments;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.entity.effect.StatusEffects;
import net.minecraft.registry.BuiltinRegistries;
import net.minecraft.registry.Registries;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.RegistryWrapper;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.Vec3d;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -25,19 +27,19 @@ import java.util.Optional;
import java.util.UUID;
public class FabricPlayer implements PlatformPlayer {
public final ServerPlayer fabricPlayer;
public final ServerPlayerEntity fabricPlayer;
public final User user;
private String clientBrand = "vanilla";
public FabricPlayer(ServerPlayer player) {
public FabricPlayer(ServerPlayerEntity player) {
this.fabricPlayer = player;
this.user = PacketEvents.getAPI().getPlayerManager().getUser(fabricPlayer);
}
@Override
public UUID getUUID() {
return fabricPlayer.getUUID();
return fabricPlayer.getUuid();
}
@Override
@@ -62,32 +64,32 @@ public class FabricPlayer implements PlatformPlayer {
@Override
public float getPitch() {
return fabricPlayer.getXRot();
return fabricPlayer.getPitch();
}
@Override
public float getYaw() {
return fabricPlayer.getYRot();
return fabricPlayer.getYaw();
}
@Override
public boolean isOnGround() {
return fabricPlayer.onGround();
return fabricPlayer.isOnGround();
}
@Override
public int getPing() {
return fabricPlayer.connection.latency();
return fabricPlayer.networkHandler.getLatency();
}
@Override
public boolean isGliding() {
return fabricPlayer.isFallFlying();
return fabricPlayer.isGliding();
}
@Override
public PlatformWorld getWorld() {
return new FabricWorld(fabricPlayer.level());
return new FabricWorld(fabricPlayer.getWorld());
}
@Override
@@ -97,13 +99,13 @@ public class FabricPlayer implements PlatformPlayer {
@Override
public void sendMessage(@NotNull String s) {
fabricPlayer.sendSystemMessage(Component.literal(s));
fabricPlayer.sendMessage(Text.literal(s));
}
@Override
public double getAttackCooldown() {
// this is what paper does I have no idea how this works
return fabricPlayer.getAttackStrengthScale(0.5f);
return fabricPlayer.getAttackCooldownProgress(0.5f);
}
@Override
@@ -113,37 +115,33 @@ public class FabricPlayer implements PlatformPlayer {
@Override
public int getMainHandKnockbackLevel() {
Optional<Holder.Reference<Enchantment>>
entry = VanillaRegistries.createLookup().asGetterLookup().get(
Registries.ENCHANTMENT, Enchantments.KNOCKBACK
);
Holder<Enchantment> registryEntry1 = entry.orElseThrow(); // Reference implements RegistryEntry, this is fine
return EnchantmentHelper.getItemEnchantmentLevel(registryEntry1, fabricPlayer.getMainHandItem());
RegistryEntry<Enchantment> knockbackEntry = fabricPlayer.getWorld().getRegistryManager().getOrThrow(RegistryKeys.ENCHANTMENT).getOrThrow(Enchantments.KNOCKBACK);
return EnchantmentHelper.getLevel(knockbackEntry, fabricPlayer.getMainHandStack());
}
@Override
public @Nullable Integer getNoDamageTicks() {
return fabricPlayer.invulnerableTime;
return fabricPlayer.timeUntilRegen;
}
@Override
public void setVelocity(Vector3d adjustedVelocity) {
fabricPlayer.setDeltaMovement(adjustedVelocity.x, adjustedVelocity.y, adjustedVelocity.z);
fabricPlayer.setVelocity(adjustedVelocity.x, adjustedVelocity.y, adjustedVelocity.z);
// TODO
// fix paper-ism? for some reason setVelocity() in paper marks the entity as hurt marked every time its called?
fabricPlayer.hurtMarked = true;
fabricPlayer.velocityModified = true;
}
@Override
public Vector3d getVelocity() {
final Vec3 fabricVelocity = fabricPlayer.getDeltaMovement();
final Vec3d fabricVelocity = fabricPlayer.getVelocity();
return new Vector3d(fabricVelocity.x, fabricVelocity.y, fabricVelocity.z);
}
@Override
public double getJumpPower() {
double jumpVelocity = 0.42;
MobEffectInstance jumpEffect = fabricPlayer.getEffect(MobEffects.JUMP);
StatusEffectInstance jumpEffect = fabricPlayer.getStatusEffect(StatusEffects.JUMP_BOOST);
if (jumpEffect != null) {
int amplifier = jumpEffect.getAmplifier();
jumpVelocity += (amplifier + 1) * 0.1F;
@@ -153,7 +151,7 @@ public class FabricPlayer implements PlatformPlayer {
}
@Override
public BoundingBox getBoundingBox() {
AABB boundingBox = fabricPlayer.getBoundingBox();
Box boundingBox = fabricPlayer.getBoundingBox();
return new BoundingBox(boundingBox.minX, boundingBox.minY, boundingBox.minZ, boundingBox.maxX, boundingBox.minY, boundingBox.maxZ);
}
@@ -19,10 +19,10 @@ public class FabricSchedulerAdapter implements SchedulerAdapter {
Iterator<ScheduledTask> iterator = taskMap.keySet().iterator();
while (iterator.hasNext()) {
ScheduledTask task = iterator.next();
if (server.getTickCount() >= task.nextRunTick) {
if (server.getTicks() >= task.nextRunTick) {
task.task.run();
if (task.isPeriodic) {
task.nextRunTick = server.getTickCount() + task.period;
task.nextRunTick = server.getTicks() + task.period;
} else {
iterator.remove();
}
@@ -32,7 +32,7 @@ public class FabricSchedulerAdapter implements SchedulerAdapter {
@Override
public AbstractTaskHandle runTask(Runnable task) {
ScheduledTask scheduledTask = new ScheduledTask(task, FabricLoaderMod.getServer().getTickCount(), 0, false);
ScheduledTask scheduledTask = new ScheduledTask(task, FabricLoaderMod.getServer().getTicks(), 0, false);
Runnable cancellationTask = () -> taskMap.remove(scheduledTask);
taskMap.put(scheduledTask, cancellationTask);
return new FabricTaskHandle(cancellationTask);
@@ -52,7 +52,7 @@ public class FabricSchedulerAdapter implements SchedulerAdapter {
@Override
public AbstractTaskHandle runTaskLater(Runnable task, long delayTicks) {
ScheduledTask scheduledTask = new ScheduledTask(task, FabricLoaderMod.getServer().getTickCount() + delayTicks, 0, false);
ScheduledTask scheduledTask = new ScheduledTask(task, FabricLoaderMod.getServer().getTicks() + delayTicks, 0, false);
Runnable cancellationTask = () -> taskMap.remove(scheduledTask);
taskMap.put(scheduledTask, cancellationTask);
return new FabricTaskHandle(cancellationTask);
@@ -60,7 +60,7 @@ public class FabricSchedulerAdapter implements SchedulerAdapter {
@Override
public AbstractTaskHandle runTaskTimer(Runnable task, long delayTicks, long periodTicks) {
ScheduledTask scheduledTask = new ScheduledTask(task, FabricLoaderMod.getServer().getTickCount() + delayTicks, periodTicks, true);
ScheduledTask scheduledTask = new ScheduledTask(task, FabricLoaderMod.getServer().getTicks() + delayTicks, periodTicks, true);
Runnable cancellationTask = () -> taskMap.remove(scheduledTask);
taskMap.put(scheduledTask, cancellationTask);
return new FabricTaskHandle(cancellationTask);
@@ -2,18 +2,17 @@ package me.caseload.knockbacksync.sender;
import me.caseload.knockbacksync.FabricBase;
import me.caseload.knockbacksync.Base;
import me.caseload.knockbacksync.mixin.CommandStackSourceAccessor;
import me.caseload.knockbacksync.permission.FabricPermissionChecker;
import net.minecraft.commands.CommandSource;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.network.chat.Component;
import net.minecraft.server.rcon.RconConsoleSource;
import net.minecraft.server.command.CommandOutput;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.rcon.RconCommandOutput;
import net.minecraft.text.Text;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.incendo.cloud.SenderMapper;
import java.util.UUID;
public class FabricSenderFactory extends SenderFactory<FabricBase, CommandSourceStack> implements SenderMapper<CommandSourceStack, Sender> {
public class FabricSenderFactory extends SenderFactory<FabricBase, ServerCommandSource> implements SenderMapper<ServerCommandSource, Sender> {
private final FabricBase plugin;
public FabricSenderFactory(FabricBase kbSyncFabricBase) {
@@ -27,16 +26,16 @@ public class FabricSenderFactory extends SenderFactory<FabricBase, CommandSource
}
@Override
protected UUID getUniqueId(CommandSourceStack commandSource) {
protected UUID getUniqueId(ServerCommandSource commandSource) {
if (commandSource.getEntity() != null) {
return commandSource.getEntity().getUUID();
return commandSource.getEntity().getUuid();
}
return Sender.CONSOLE_UUID;
}
@Override
protected String getName(CommandSourceStack commandSource) {
String name = commandSource.getTextName();
protected String getName(ServerCommandSource commandSource) {
String name = commandSource.getName();
if (commandSource.getEntity() != null && name.equals("Server")) {
return Sender.CONSOLE_NAME;
}
@@ -44,7 +43,7 @@ public class FabricSenderFactory extends SenderFactory<FabricBase, CommandSource
}
@Override
protected void sendMessage(CommandSourceStack sender, String message) {
protected void sendMessage(ServerCommandSource sender, String message) {
// final Locale locale;
// if (sender.getEntity() instanceof ServerPlayer) {
// String language = ((ServerPlayer) sender.getEntity()).clientInformation().language();
@@ -53,39 +52,39 @@ public class FabricSenderFactory extends SenderFactory<FabricBase, CommandSource
// locale = null;
// }
// sender.sendFeedback(() -> toNativeText(TranslationManager.render(message, locale)), false);
sender.sendSuccess(() -> Component.literal(message), false);
sender.sendFeedback(() -> Text.literal(message), false);
}
@Override
protected boolean hasPermission(CommandSourceStack commandSource, String node) {
protected boolean hasPermission(ServerCommandSource commandSource, String node) {
return ((FabricPermissionChecker) Base.INSTANCE.getPermissionChecker()).hasPermission(commandSource, node);
}
@Override
protected boolean hasPermission(CommandSourceStack commandSource, String node, boolean defaultIfUnset) {
protected boolean hasPermission(ServerCommandSource commandSource, String node, boolean defaultIfUnset) {
return ((FabricPermissionChecker) Base.INSTANCE.getPermissionChecker()).hasPermission(commandSource, node, defaultIfUnset);
}
@Override
protected void performCommand(CommandSourceStack sender, String command) {
protected void performCommand(ServerCommandSource sender, String command) {
// sender.getServer().getCommandManager().executeWithPrefix(sender, command);
}
@Override
protected boolean isConsole(CommandSourceStack sender) {
CommandSource output = ((CommandStackSourceAccessor) sender).getSource();
protected boolean isConsole(ServerCommandSource sender) {
CommandOutput output = sender.output;
return output == sender.getServer() || // Console
output.getClass() == RconConsoleSource.class || // Rcon
(output == CommandSource.NULL && sender.getTextName().equals("")); // Functions
output.getClass() == RconCommandOutput.class || // Rcon
(output == CommandOutput.DUMMY && sender.getName().equals("")); // Functions
}
@Override
public @NonNull Sender map(@NonNull CommandSourceStack base) {
public @NonNull Sender map(@NonNull ServerCommandSource base) {
return this.wrap(base);
}
@Override
public @NonNull CommandSourceStack reverse(@NonNull Sender mapped) {
public @NonNull ServerCommandSource reverse(@NonNull Sender mapped) {
return this.unwrap(mapped);
}
@@ -87,8 +87,8 @@ public class MetricsFabric implements Metrics {
private void appendPlatformData(JsonObjectBuilder builder) {
builder.appendField("playerAmount", getPlayerAmount());
builder.appendField("onlineMode", FabricLoaderMod.getServer().usesAuthentication() ? 0 : 1);
builder.appendField("bukkitVersion", "Fabric " + FabricLoader.getInstance().getModContainer("fabricloader").get().getMetadata().getVersion().getFriendlyString() + " (MC: " + FabricLoaderMod.getServer().getServerVersion() + ")");
builder.appendField("onlineMode", FabricLoaderMod.getServer().isOnlineMode() ? 0 : 1);
builder.appendField("bukkitVersion", "Fabric " + FabricLoader.getInstance().getModContainer("fabricloader").get().getMetadata().getVersion().getFriendlyString() + " (MC: " + FabricLoaderMod.getServer().getVersion() + ")");
builder.appendField("bukkitName", "Fabric");
builder.appendField("javaVersion", System.getProperty("java.version"));
builder.appendField("osName", System.getProperty("os.name"));
@@ -103,7 +103,7 @@ public class MetricsFabric implements Metrics {
private int getPlayerAmount() {
if (FabricLoaderMod.getServer().isRunning()) {
return FabricLoaderMod.getServer().getPlayerCount();
return FabricLoaderMod.getServer().getCurrentPlayerCount();
} else {
return 0;
}
@@ -1,46 +1,45 @@
package me.caseload.knockbacksync.util;
import com.mojang.brigadier.context.CommandContext;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.network.chat.Component;
import java.util.function.Supplier;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.text.Text;
public class CommandUtil {
public static void sendSuccessMessage(CommandContext<CommandSourceStack> context, String message) {
public static void sendSuccessMessage(CommandContext<ServerCommandSource> context, String message) {
sendSuccessMessage(context, () -> getComponent(message), false);
}
public static void sendSuccessMessage(CommandContext<CommandSourceStack> context, String message, boolean allowLogging) {
public static void sendSuccessMessage(CommandContext<ServerCommandSource> context, String message, boolean allowLogging) {
sendSuccessMessage(context, () -> getComponent(message), allowLogging);
}
public static void sendSuccessMessage(CommandContext<CommandSourceStack> context, Component message) {
public static void sendSuccessMessage(CommandContext<ServerCommandSource> context, Text message) {
sendSuccessMessage(context, () -> message, false);
}
public static void sendSuccessMessage(CommandContext<CommandSourceStack> context, Component message, boolean allowLogging) {
public static void sendSuccessMessage(CommandContext<ServerCommandSource> context, Text message, boolean allowLogging) {
sendSuccessMessage(context, () -> message, allowLogging);
}
public static void sendSuccessMessage(CommandContext<CommandSourceStack> context, Supplier<Component> messageSupplier) {
public static void sendSuccessMessage(CommandContext<ServerCommandSource> context, Supplier<Text> messageSupplier) {
sendSuccessMessage(context, messageSupplier, false);
}
public static void sendSuccessMessage(CommandContext<CommandSourceStack> context, Supplier<Component> messageSupplier, boolean allowLogging) {
context.getSource().sendSuccess(messageSupplier, allowLogging);
public static void sendSuccessMessage(CommandContext<ServerCommandSource> context, Supplier<Text> messageSupplier, boolean allowLogging) {
context.getSource().sendFeedback(messageSupplier, allowLogging);
}
public static void sendFailureMessage(CommandContext<CommandSourceStack> context, String message) {
public static void sendFailureMessage(CommandContext<ServerCommandSource> context, String message) {
sendFailureMessage(context, getComponent(message));
}
public static void sendFailureMessage(CommandContext<CommandSourceStack> context, Component message) {
context.getSource().sendFailure(message);
public static void sendFailureMessage(CommandContext<ServerCommandSource> context, Text message) {
context.getSource().sendError(message);
}
public static Component getComponent(String message) {
return Component.literal(message);
public static Text getComponent(String message) {
return Text.literal(message);
}
}
@@ -3,12 +3,10 @@ package me.caseload.knockbacksync.util;
import me.caseload.knockbacksync.Base;
import me.caseload.knockbacksync.ConfigWrapper;
import me.caseload.knockbacksync.mixin.UpdateIntervalAccessor;
import net.minecraft.server.level.ChunkMap;
import net.minecraft.server.level.ServerChunkCache;
import net.minecraft.server.level.ServerEntity;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.Entity;
import net.minecraft.entity.Entity;
import net.minecraft.server.world.ServerChunkLoadingManager;
import net.minecraft.server.world.ServerChunkManager;
import net.minecraft.server.world.ServerWorld;
import java.util.HashMap;
import java.util.Map;
@@ -27,11 +25,11 @@ public class CustomUpdateIntervals {
entityIntervals.clear();
}
public static void updateIntervals(ServerLevel level, Map<String, Integer> entityIntervals) {
for (Entity entity : level.getAllEntities()) {
String entityType = entity.getType().builtInRegistryHolder().getRegisteredName();
public static void updateIntervals(ServerWorld level, Map<String, Integer> entityIntervals) {
for (Entity entity : level.iterateEntities()) {
String entityType = entity.getType().getRegistryEntry().getIdAsString();
if (entityIntervals.containsKey(entityType)) {
ChunkMap.TrackedEntity serverEntity = ((ServerChunkCache) entity.level().getChunkSource()).chunkMap.entityMap.get(entity.getId());
ServerChunkLoadingManager.EntityTracker serverEntity = ((ServerChunkManager) entity.getWorld().getChunkManager()).chunkLoadingManager.entityTrackers.get(entity.getId());
if (serverEntity != null) {
((UpdateIntervalAccessor) serverEntity).setUpdateInterval(entityIntervals.get(entityType));
}
@@ -3,26 +3,25 @@ package me.caseload.knockbacksync.world;
import me.caseload.knockbacksync.FabricLoaderMod;
import me.caseload.knockbacksync.player.FabricPlayer;
import me.caseload.knockbacksync.player.PlatformPlayer;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.network.ServerPlayerEntity;
import java.util.Collection;
import java.util.UUID;
import java.util.stream.Collectors;
public class FabricServer implements PlatformServer {
public Collection<PlatformPlayer> getOnlinePlayers() {
return FabricLoaderMod.getServer().getPlayerList().getPlayers().stream()
return FabricLoaderMod.getServer().getPlayerManager().getPlayerList().stream()
.map(FabricPlayer::new)
.collect(Collectors.toList());
}
@Override
public PlatformPlayer getPlayer(UUID uuid) {
return new FabricPlayer(FabricLoaderMod.getServer().getPlayerList().getPlayer(uuid));
return new FabricPlayer(FabricLoaderMod.getServer().getPlayerManager().getPlayer(uuid));
}
@Override
public PlatformPlayer getPlayer(Object nativePlatformPlayer) {
return new FabricPlayer((ServerPlayer) nativePlatformPlayer);
return new FabricPlayer((ServerPlayerEntity) nativePlatformPlayer);
}
}
@@ -6,28 +6,27 @@ import com.github.retrooper.packetevents.util.Vector3d;
import com.github.retrooper.packetevents.util.Vector3i;
import me.caseload.knockbacksync.world.raytrace.FluidHandling;
import me.caseload.knockbacksync.world.raytrace.RayTraceResult;
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.ClipContext;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.HitResult;
import net.minecraft.world.phys.Vec3;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.ShapeContext;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.hit.HitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.RaycastContext;
import net.minecraft.world.World;
public class FabricWorld implements PlatformWorld {
private final Level world;
private final World world;
public FabricWorld(Level world) {
public FabricWorld(World world) {
this.world = world;
}
@Override
public WrappedBlockState getBlockStateAt(int x, int y, int z) {
BlockState blockState = this.world.getBlockState(new BlockPos(x, y, z));
return WrappedBlockState.getByGlobalId(Block.BLOCK_STATE_REGISTRY.getId(blockState));
return WrappedBlockState.getByGlobalId(Block.STATE_IDS.getRawId(blockState));
}
@Override
@@ -37,26 +36,26 @@ public class FabricWorld implements PlatformWorld {
@Override
public RayTraceResult rayTraceBlocks(Vector3d start, Vector3d direction, double maxDistance, FluidHandling fluidHandling, boolean ignorePassableBlocks) {
Vec3 startVec = new Vec3(start.getX(), start.getY(), start.getZ());
Vec3 endVec = startVec.add(direction.getX() * maxDistance, direction.getY() * maxDistance, direction.getZ() * maxDistance);
Vec3d startVec = new Vec3d(start.getX(), start.getY(), start.getZ());
Vec3d endVec = startVec.add(direction.getX() * maxDistance, direction.getY() * maxDistance, direction.getZ() * maxDistance);
BlockHitResult result = world.clip(new ClipContext(
BlockHitResult result = world.raycast(new RaycastContext(
startVec,
endVec,
ClipContext.Block.OUTLINE,
fluidHandling == FluidHandling.NONE ? ClipContext.Fluid.NONE :
fluidHandling == FluidHandling.SOURCE_ONLY ? ClipContext.Fluid.SOURCE_ONLY :
ClipContext.Fluid.ANY,
CollisionContext.empty()
RaycastContext.ShapeType.OUTLINE,
fluidHandling == FluidHandling.NONE ? RaycastContext.FluidHandling.NONE :
fluidHandling == FluidHandling.SOURCE_ONLY ? RaycastContext.FluidHandling.SOURCE_ONLY :
RaycastContext.FluidHandling.ANY,
ShapeContext.absent()
));
if (result.getType() == HitResult.Type.MISS) return null;
Vec3 hitLocation = result.getLocation();
Vec3d hitLocation = result.getPos();
BlockPos blockPos = result.getBlockPos();
return new RayTraceResult(
new Vector3d(hitLocation.x, hitLocation.y, hitLocation.z),
BlockFace.getBlockFaceByValue(result.getDirection().ordinal()),
BlockFace.getBlockFaceByValue(result.getSide().ordinal()),
new Vector3i(blockPos.getX(), blockPos.getY(), blockPos.getZ()),
getBlockStateAt(blockPos.getX(), blockPos.getY(), blockPos.getZ())
);
@@ -1,6 +1,6 @@
accessWidener v2 named
# We don't actually need this right now, but it's useful to keep an access widener around for when we do need one
accessible field net/minecraft/server/level/ChunkMap entityMap Lit/unimi/dsi/fastutil/ints/Int2ObjectMap;
accessible class net/minecraft/server/level/ChunkMap$TrackedEntity
accessible method net/minecraft/server/level/ChunkMap$TrackedEntity updatePlayers (Ljava/util/List;)V
accessible field net/minecraft/server/command/ServerCommandSource output Lnet/minecraft/server/command/CommandOutput;
accessible field net/minecraft/server/world/ServerChunkLoadingManager entityTrackers Lit/unimi/dsi/fastutil/ints/Int2ObjectMap;
accessible class net/minecraft/server/world/ServerChunkLoadingManager$EntityTracker
#accessible method net/minecraft/server/level/ChunkMap$TrackedEntity updatePlayers (Ljava/util/List;)V
@@ -5,7 +5,6 @@
"compatibilityLevel": "JAVA_21",
"mixins": [
"ChunkMapMixin",
"CommandStackSourceAccessor",
"PlayerMixin",
"ServerEntityMixin",
"TickRateManagerMixin"
+4 -6
View File
@@ -4,11 +4,9 @@ org.gradle.parallel=true
# Fabric Properties
# check these on https://modmuss50.me/fabric.html
minecraft_version=1.21
parchment_mappings=2024.11.10
parchment_minecraft_version=1.21
yarn_mappings=1.21+build.9
loader_version=0.16.9
minecraft_version=1.21.4
yarn_mappings=1.21.4+build.8:v2
loader_version=0.16.10
# Mod Properties
maven_group=me.caseload
@@ -16,6 +14,6 @@ archives_base_name=knockbacksync
# Dependencies
# check this on https://modmuss50.me/fabric.html
fabric_version=0.102.0+1.21
fabric_version=0.119.2+1.21.4
githubRepo=CASELOAD7000/knockback-sync