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 'com.zaxxer', '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.paginedown', 'net.william278.husksync.libraries.paginedown'
relocate 'org.json', 'net.william278.husksync.libraries.json'

@ -69,7 +69,7 @@ public class FabricEventListener extends EventListener implements LockedHandler
WorldSaveCallback.EVENT.register(this::handleWorldSave);
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);
ItemDropCallback.EVENT.register(this::handleItemDrop);
UseBlockCallback.EVENT.register(this::handleBlockInteract);
@ -94,14 +94,15 @@ public class FabricEventListener extends EventListener implements LockedHandler
}
private void handleWorldSave(@NotNull ServerWorld world) {
saveOnWorldSave(world.getPlayers().stream()
.map(player -> (OnlineUser) FabricUser.adapt(player, plugin)).collect(Collectors.toList()));
this.saveOnWorldSave(
world.getPlayers().stream().map(player -> (OnlineUser) FabricUser.adapt(player, plugin)).toList()
);
}
private void handlePlayerDeathDrops(@NotNull ServerPlayerEntity player, @Nullable ItemStack @NotNull [] toKeep,
@Nullable ItemStack @NotNull [] toDrop) {
final SaveOnDeathSettings settings = plugin.getSettings().getSynchronization().getSaveOnDeath();
saveOnPlayerDeath(
this.saveOnPlayerDeath(
FabricUser.adapt(player, plugin),
FabricData.Items.ItemArray.adapt(
settings.getItemsToSave() == SaveOnDeathSettings.DeathItemsMode.DROPS ? toDrop : toKeep

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

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

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

Loading…
Cancel
Save