make owned allays not able to pickup locked items or if claim disables it close #223

This commit is contained in:
Flemmli97 2023-03-10 23:47:26 +01:00
parent 060e888ab4
commit a1ead799cf
4 changed files with 45 additions and 3 deletions

View File

@ -0,0 +1,41 @@
package io.github.flemmli97.flan.mixin;
import io.github.flemmli97.flan.api.permission.PermissionRegistry;
import io.github.flemmli97.flan.claim.Claim;
import io.github.flemmli97.flan.claim.ClaimStorage;
import io.github.flemmli97.flan.player.IOwnedItem;
import net.minecraft.world.entity.animal.allay.Allay;
import net.minecraft.world.entity.animal.allay.AllayAi;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.item.ItemStack;
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;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(Allay.class)
public abstract class AllayMixin {
@Inject(method = "wantsToPickUp", at = @At("HEAD"), cancellable = true)
private void onWantingPickup(ItemStack stack, CallbackInfoReturnable<Boolean> info) {
Allay allay = (Allay) (Object) this;
if (AllayAi.getLikedPlayer(allay).map(p -> {
Claim claim = ClaimStorage.get(p.getLevel()).getClaimAt(allay.blockPosition());
return claim != null && (!claim.canInteract(p, PermissionRegistry.PICKUP, allay.blockPosition(), false));
}).orElse(false))
info.setReturnValue(false);
}
@Inject(method = "pickUpItem", at = @At("HEAD"), cancellable = true)
private void onPickupItem(ItemEntity itemEntity, CallbackInfo info) {
if (AllayAi.getLikedPlayer((Allay) (Object) this).map(p -> {
IOwnedItem ownedItem = (IOwnedItem) itemEntity;
if (p.getUUID().equals(ownedItem.getPlayerOrigin()))
return true;
Claim claim = ClaimStorage.get(p.getLevel()).getClaimAt(itemEntity.blockPosition());
return claim != null && !claim.canInteract(p, PermissionRegistry.PICKUP, itemEntity.blockPosition(), false);
}).orElse(false))
info.cancel();
}
}

View File

@ -21,7 +21,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(DragonEggBlock.class) @Mixin(DragonEggBlock.class)
public class DragonEggBlockMixin { public abstract class DragonEggBlockMixin {
@Unique @Unique
private Player flanTempPlayer; private Player flanTempPlayer;

View File

@ -10,7 +10,7 @@ import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(BoneMealItem.class) @Mixin(BoneMealItem.class)
public class MossBlockCheckMixin { public abstract class MossBlockCheckMixin {
@Inject(method = "useOn", at = @At("HEAD"), cancellable = true) @Inject(method = "useOn", at = @At("HEAD"), cancellable = true)
private void check(UseOnContext context, CallbackInfoReturnable<InteractionResult> info) { private void check(UseOnContext context, CallbackInfoReturnable<InteractionResult> info) {

View File

@ -29,7 +29,8 @@
"EnderMitePearlCheck", "EnderMitePearlCheck",
"SculkSensorMixin", "SculkSensorMixin",
"SculkShriekerMixin", "SculkShriekerMixin",
"DragonEggBlockMixin" "DragonEggBlockMixin",
"AllayMixin"
], ],
"server": [ "server": [
], ],