From bb517f082cbeb84bb0ef0134431ad65465fe26c3 Mon Sep 17 00:00:00 2001 From: DeadlyMC Date: Thu, 6 Jun 2019 17:41:40 +0530 Subject: [PATCH] persistentParrots --- src/main/java/carpet/CarpetSettings.java | 2 +- .../mixins/PlayerEntity_parrotMixin.java | 95 +++++++++++++++++++ src/main/resources/carpet.mixins.json | 1 + 3 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 src/main/java/carpet/mixins/PlayerEntity_parrotMixin.java diff --git a/src/main/java/carpet/CarpetSettings.java b/src/main/java/carpet/CarpetSettings.java index c4a1c43f..203d6ec4 100644 --- a/src/main/java/carpet/CarpetSettings.java +++ b/src/main/java/carpet/CarpetSettings.java @@ -84,7 +84,7 @@ public class CarpetSettings rule("portalCreativeDelay", "creative", "Portals won't let a creative player go through instantly") .extraInfo("Holding obsidian in either hand won't let you through at all"), rule("ctrlQCraftingFix", "fix survival", "Dropping entire stacks works also from on the crafting UI result slot"), - rule("persistentParrots", "survival feature", "Parrots don't get of your shoulders until you receive damage").wip(), + rule("persistentParrots", "survival feature", "Parrots don't get of your shoulders until you receive damage"), //!rule("growingUpWallJump", "fix", "Mobs growing up won't glitch into walls or go through fences"), //!rule("reloadSuffocationFix", "fix experimental", "Won't let mobs glitch into blocks when reloaded.") // .extraInfo("Can cause slight differences in mobs behaviour"), diff --git a/src/main/java/carpet/mixins/PlayerEntity_parrotMixin.java b/src/main/java/carpet/mixins/PlayerEntity_parrotMixin.java new file mode 100644 index 00000000..e950fdbe --- /dev/null +++ b/src/main/java/carpet/mixins/PlayerEntity_parrotMixin.java @@ -0,0 +1,95 @@ +package carpet.mixins; + +import carpet.CarpetSettings; +import net.minecraft.entity.EntityType; +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.damage.DamageSource; +import net.minecraft.entity.player.PlayerAbilities; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.world.World; +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.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(PlayerEntity.class) +public abstract class PlayerEntity_parrotMixin extends LivingEntity +{ + @Shadow @Final public PlayerAbilities abilities; + + @Shadow protected abstract void dropShoulderEntities(); + + @Shadow protected abstract void method_7296(CompoundTag compoundTag_1); + + @Shadow public abstract CompoundTag getShoulderEntityLeft(); + + @Shadow protected abstract void setShoulderEntityLeft(CompoundTag compoundTag_1); + + @Shadow protected abstract void setShoulderEntityRight(CompoundTag compoundTag_1); + + @Shadow public abstract CompoundTag getShoulderEntityRight(); + + protected PlayerEntity_parrotMixin(EntityType entityType_1, World world_1) + { + super(entityType_1, world_1); + } + + @Redirect(method = "tickMovement", at = @At(value = "INVOKE", + target = "Lnet/minecraft/entity/player/PlayerEntity;dropShoulderEntities()V")) + private void cancelDropShoulderEntities1(PlayerEntity playerEntity) + { + + } + + @Inject(method = "tickMovement", at = @At(value = "INVOKE", shift = At.Shift.AFTER, ordinal = 1, + target = "Lnet/minecraft/entity/player/PlayerEntity;updateShoulderEntity(Lnet/minecraft/nbt/CompoundTag;)V")) + private void onTickMovement(CallbackInfo ci) + { + boolean parrots_will_drop = !CarpetSettings.getBool("persistentParrots") || this.abilities.invulnerable; + if (!this.world.isClient && ((parrots_will_drop && this.fallDistance > 0.5F) || this.isInWater() || (parrots_will_drop && this.hasVehicle())) || this.abilities.flying) + { + this.dropShoulderEntities(); + } + } + + @Redirect(method = "damage", at = @At(value = "INVOKE", + target = "Lnet/minecraft/entity/player/PlayerEntity;dropShoulderEntities()V")) + private void cancelDropShoulderEntities2(PlayerEntity playerEntity) + { + + } + + protected void dismount_left() + { + this.method_7296(this.getShoulderEntityLeft()); + this.setShoulderEntityLeft(new CompoundTag()); + } + + protected void dismount_right() + { + this.method_7296(this.getShoulderEntityRight()); + this.setShoulderEntityRight(new CompoundTag()); + } + + @Inject(method = "damage", at = @At(value = "INVOKE", shift = At.Shift.BEFORE, + target = "Lnet/minecraft/entity/player/PlayerEntity;dropShoulderEntities()V")) + private void onDamage(DamageSource damageSource_1, float float_1, CallbackInfoReturnable cir) + { + if (CarpetSettings.getBool("persistentParrots") && !this.isSneaking()) + { + if (this.random.nextFloat() < ((float_1)/15.0) ) + { + this.dismount_left(); + } + if (this.random.nextFloat() < ((float_1)/15.0) ) + { + this.dismount_right(); + } + } + } +} diff --git a/src/main/resources/carpet.mixins.json b/src/main/resources/carpet.mixins.json index 762535d6..a2273004 100644 --- a/src/main/resources/carpet.mixins.json +++ b/src/main/resources/carpet.mixins.json @@ -50,6 +50,7 @@ "GravityStructureProcessorMixin", "ServerPlayNetworkHandler_scarpetEventsMixin", "ServerPlayerInteractionManager_scarpetEventsMixin", + "PlayerEntity_parrotMixin", "SaplingBlockMixin", "EntityMixin", "DirectionMixin",