diff --git a/gradle.properties b/gradle.properties index 3b3a170..07dad90 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,7 +1,7 @@ # Done to increase the memory available to gradle. org.gradle.jvmargs=-Xmx1G org.gradle.parallel=true -org.gradle.configuration-cache=true +org.gradle.configuration-cache=false # Fabric Properties # check these on https://fabricmc.net/develop @@ -10,7 +10,7 @@ loader_version=0.20.1 loom_version=1.19-SNAPSHOT # Mod Properties -version=1.0.0 +version=26.3.0 group=net.almtesh.stickyparrots # Dependencies diff --git a/src/main/java/net/almtesh/stickyparrots/mixin/ParrotMixin.java b/src/main/java/net/almtesh/stickyparrots/mixin/ParrotMixin.java index dba25a2..3d03498 100644 --- a/src/main/java/net/almtesh/stickyparrots/mixin/ParrotMixin.java +++ b/src/main/java/net/almtesh/stickyparrots/mixin/ParrotMixin.java @@ -1,15 +1,41 @@ package net.almtesh.stickyparrots.mixin; -import net.minecraft.server.MinecraftServer; +import net.minecraft.server.level.ServerPlayer; 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(MinecraftServer.class) -public class ParrotMixin { - @Inject(at = @At("HEAD"), method = "loadLevel") - private void init(CallbackInfo info) { - // This code is injected into the start of MinecraftServer.loadLevel()V +@Mixin(ServerPlayer.class) +public abstract class ParrotMixin { + @Shadow + private long timeEntitySatOnShoulder; + + @Inject ( + method = "removeEntitiesOnShoulder", + at = @At ("HEAD"), + cancellable = true + ) + private void stickyparrots$filterShoulderRelease (CallbackInfo ci) { + ServerPlayer player = (ServerPlayer) (Object) this; + + boolean allowed = + player.isUnderWater () + || player.isInPowderSnow + || player.isSleeping () + || player.isDeadOrDying () + || player.isSpectator () + || (!player.onGround () + && player.isCrouching () + && player.fallDistance > 0.75F); + + if (!allowed) { + ci.cancel(); + return; + } + + // Skip the 20 ticks delay to parrot release + this.timeEntitySatOnShoulder = player.level ().getGameTime () - 21L; } } \ No newline at end of file