fix: fix various Fabric issues

Adjusted a mixin
Fixed Uniform being relocated causing a ClassNotFound exception (it's a JiJ mod now)
feat/data-edit-commands
William 5 months ago
parent 8ed6869aad
commit 91bbe05851
No known key found for this signature in database

@ -54,7 +54,6 @@ shadowJar {
relocate 'org.intellij', 'net.william278.husksync.libraries' relocate 'org.intellij', 'net.william278.husksync.libraries'
relocate 'com.zaxxer', 'net.william278.husksync.libraries' relocate 'com.zaxxer', 'net.william278.husksync.libraries'
relocate 'de.exlll', 'net.william278.husksync.libraries' relocate 'de.exlll', 'net.william278.husksync.libraries'
relocate 'net.william278.uniform', 'net.william278.husksync.libraries.uniform'
relocate 'net.william278.desertwell', 'net.william278.husksync.libraries.desertwell' relocate 'net.william278.desertwell', 'net.william278.husksync.libraries.desertwell'
relocate 'net.william278.paginedown', 'net.william278.husksync.libraries.paginedown' relocate 'net.william278.paginedown', 'net.william278.husksync.libraries.paginedown'
relocate 'org.json', 'net.william278.husksync.libraries.json' relocate 'org.json', 'net.william278.husksync.libraries.json'

@ -69,7 +69,7 @@ public class FabricEventListener extends EventListener implements LockedHandler
WorldSaveCallback.EVENT.register(this::handleWorldSave); WorldSaveCallback.EVENT.register(this::handleWorldSave);
PlayerDeathDropsCallback.EVENT.register(this::handlePlayerDeathDrops); PlayerDeathDropsCallback.EVENT.register(this::handlePlayerDeathDrops);
// TODO: Events of extra things to cancel if the player has not been set yet // Locked events handling
ItemPickupCallback.EVENT.register(this::handleItemPickup); ItemPickupCallback.EVENT.register(this::handleItemPickup);
ItemDropCallback.EVENT.register(this::handleItemDrop); ItemDropCallback.EVENT.register(this::handleItemDrop);
UseBlockCallback.EVENT.register(this::handleBlockInteract); UseBlockCallback.EVENT.register(this::handleBlockInteract);
@ -94,14 +94,15 @@ public class FabricEventListener extends EventListener implements LockedHandler
} }
private void handleWorldSave(@NotNull ServerWorld world) { private void handleWorldSave(@NotNull ServerWorld world) {
saveOnWorldSave(world.getPlayers().stream() this.saveOnWorldSave(
.map(player -> (OnlineUser) FabricUser.adapt(player, plugin)).collect(Collectors.toList())); world.getPlayers().stream().map(player -> (OnlineUser) FabricUser.adapt(player, plugin)).toList()
);
} }
private void handlePlayerDeathDrops(@NotNull ServerPlayerEntity player, @Nullable ItemStack @NotNull [] toKeep, private void handlePlayerDeathDrops(@NotNull ServerPlayerEntity player, @Nullable ItemStack @NotNull [] toKeep,
@Nullable ItemStack @NotNull [] toDrop) { @Nullable ItemStack @NotNull [] toDrop) {
final SaveOnDeathSettings settings = plugin.getSettings().getSynchronization().getSaveOnDeath(); final SaveOnDeathSettings settings = plugin.getSettings().getSynchronization().getSaveOnDeath();
saveOnPlayerDeath( this.saveOnPlayerDeath(
FabricUser.adapt(player, plugin), FabricUser.adapt(player, plugin),
FabricData.Items.ItemArray.adapt( FabricData.Items.ItemArray.adapt(
settings.getItemsToSave() == SaveOnDeathSettings.DeathItemsMode.DROPS ? toDrop : toKeep settings.getItemsToSave() == SaveOnDeathSettings.DeathItemsMode.DROPS ? toDrop : toKeep

@ -20,22 +20,26 @@
package net.william278.husksync.mixins; package net.william278.husksync.mixins;
import net.minecraft.entity.ItemEntity; import net.minecraft.entity.ItemEntity;
import net.minecraft.entity.player.PlayerInventory; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult; import net.minecraft.util.ActionResult;
import net.william278.husksync.event.ItemPickupCallback; import net.william278.husksync.event.ItemPickupCallback;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(ItemEntity.class) @Mixin(ItemEntity.class)
public class ItemEntityMixin { public class ItemEntityMixin {
@Redirect(at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerInventory;insertStack(Lnet/minecraft/item/ItemStack;)Z"), @Inject(method = "onPlayerCollision", at = @At("HEAD"), cancellable = true)
method = "onPlayerCollision") private void onPlayerPickupItem(PlayerEntity player, CallbackInfo ci) {
public boolean onPlayerCollision(PlayerInventory inventory, ItemStack stack) { final ItemStack stack = ((ItemEntity) (Object) this).getStack();
ActionResult result = ItemPickupCallback.EVENT.invoker().interact(inventory.player, stack); final ActionResult result = ItemPickupCallback.EVENT.invoker().interact(player, stack);
return (result != ActionResult.FAIL && inventory.insertStack(stack));
if (result == ActionResult.FAIL) {
ci.cancel();
}
} }
} }

@ -21,6 +21,7 @@ package net.william278.husksync.mixins;
import net.minecraft.entity.ItemEntity; import net.minecraft.entity.ItemEntity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.ActionResult; import net.minecraft.util.ActionResult;
import net.william278.husksync.event.ItemDropCallback; import net.william278.husksync.event.ItemDropCallback;
@ -35,8 +36,8 @@ public class ServerPlayerEntityMixin {
@Inject(method = "dropItem", at = @At("HEAD"), cancellable = true) @Inject(method = "dropItem", at = @At("HEAD"), cancellable = true)
private void onPlayerDropItem(ItemStack stack, boolean dropAtFeet, boolean saveThrower, private void onPlayerDropItem(ItemStack stack, boolean dropAtFeet, boolean saveThrower,
final CallbackInfoReturnable<ItemEntity> ci) { final CallbackInfoReturnable<ItemEntity> ci) {
ServerPlayerEntity player = (ServerPlayerEntity) (Object) this; final ServerPlayerEntity player = (ServerPlayerEntity) (Object) this;
ActionResult result = ItemDropCallback.EVENT.invoker().interact(player, stack); final ActionResult result = ItemDropCallback.EVENT.invoker().interact(player, stack);
if (result == ActionResult.FAIL) { if (result == ActionResult.FAIL) {
ci.cancel(); ci.cancel();

@ -19,9 +19,12 @@
package net.william278.husksync.mixins; package net.william278.husksync.mixins;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.world.ServerWorld; import net.minecraft.server.world.ServerWorld;
import net.william278.husksync.event.WorldSaveCallback; import net.william278.husksync.event.WorldSaveCallback;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin; 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.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@ -29,8 +32,15 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(ServerWorld.class) @Mixin(ServerWorld.class)
public class ServerWorldMixin { public class ServerWorldMixin {
@Final
@Shadow
private MinecraftServer server;
@Inject(method = "saveLevel", at = @At("HEAD")) @Inject(method = "saveLevel", at = @At("HEAD"))
public void saveLevel(CallbackInfo ci) { public void saveLevel(CallbackInfo ci) {
if (server.isStopping() || server.isStopped()) {
return;
}
WorldSaveCallback.EVENT.invoker().save((ServerWorld) (Object) this); WorldSaveCallback.EVENT.invoker().save((ServerWorld) (Object) this);
} }

Loading…
Cancel
Save