From 923ea5dfccf35ceb69f7ede46557810b951042cd Mon Sep 17 00:00:00 2001 From: Apace Date: Sun, 5 Jul 2020 15:23:05 +0200 Subject: [PATCH] Made Merlings not lose air on land when raining, prevented Phantom burning in rain * Merlings no longer lose their breath when standing in rain (but it doesn't fill up either) * Fixed a bug where Phantoms would occasionally catch fire in rain --- .../origins/mixin/PlayerEntityMixin.java | 43 +++++++++++++------ 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/src/main/java/io/github/apace100/origins/mixin/PlayerEntityMixin.java b/src/main/java/io/github/apace100/origins/mixin/PlayerEntityMixin.java index eb2158ff..2c0fa8cb 100644 --- a/src/main/java/io/github/apace100/origins/mixin/PlayerEntityMixin.java +++ b/src/main/java/io/github/apace100/origins/mixin/PlayerEntityMixin.java @@ -7,6 +7,8 @@ import io.github.apace100.origins.power.WaterVulnerabilityPower; import io.github.apace100.origins.registry.ModComponents; import net.minecraft.block.BlockState; +import net.minecraft.entity.EntityDimensions; +import net.minecraft.entity.EntityPose; import net.minecraft.entity.EntityType; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.damage.DamageSource; @@ -37,6 +39,8 @@ public abstract class PlayerEntityMixin extends LivingEntity implements Nameable @Shadow public abstract HungerManager getHungerManager(); + @Shadow public abstract EntityDimensions getDimensions(EntityPose pose); + protected PlayerEntityMixin(EntityType entityType, World world) { super(entityType, world); } @@ -90,7 +94,7 @@ private void tick(CallbackInfo info) { this.getHungerManager().addExhaustion(0.12F); } if(PowerTypes.BURN_IN_DAYLIGHT.isActive(this) && PowerTypes.BURN_IN_DAYLIGHT.get(this).isActive() && !this.hasStatusEffect(StatusEffects.INVISIBILITY)) { - if (this.world.isDay() && !this.world.isClient) { + if (this.world.isDay() && !this.isRainingAtPlayerPosition()) { float f = this.getBrightnessAtEyes(); BlockPos blockPos = this.getVehicle() instanceof BoatEntity ? (new BlockPos(this.getX(), (double)Math.round(this.getY()), this.getZ())).up() : new BlockPos(this.getX(), (double)Math.round(this.getY()), this.getZ()); if (f > 0.5F && this.random.nextFloat() * 30.0F < (f - 0.4F) * 2.0F && this.world.isSkyVisible(blockPos)) { @@ -109,20 +113,25 @@ private void tick(CallbackInfo info) { } if(PowerTypes.WATER_BREATHING.isActive(this)) { if(!this.isSubmergedIn(FluidTags.WATER) && !this.hasStatusEffect(StatusEffects.WATER_BREATHING)) { - int landGain = this.getNextAirOnLand(0); - this.setAir(this.getNextAirUnderwater(this.getAir()) - landGain); - if (this.getAir() == -20) { - this.setAir(0); - Vec3d vec3d = this.getVelocity(); - - for(int i = 0; i < 8; ++i) { - double f = this.random.nextDouble() - this.random.nextDouble(); - double g = this.random.nextDouble() - this.random.nextDouble(); - double h = this.random.nextDouble() - this.random.nextDouble(); - this.world.addParticle(ParticleTypes.BUBBLE, this.getX() + f, this.getY() + g, this.getZ() + h, vec3d.x, vec3d.y, vec3d.z); - } + if(!this.isRainingAtPlayerPosition()) { + int landGain = this.getNextAirOnLand(0); + this.setAir(this.getNextAirUnderwater(this.getAir()) - landGain); + if (this.getAir() == -20) { + this.setAir(0); + Vec3d vec3d = this.getVelocity(); - this.damage(ModDamageSources.NO_WATER_FOR_GILLS, 2.0F); + for(int i = 0; i < 8; ++i) { + double f = this.random.nextDouble() - this.random.nextDouble(); + double g = this.random.nextDouble() - this.random.nextDouble(); + double h = this.random.nextDouble() - this.random.nextDouble(); + this.world.addParticle(ParticleTypes.BUBBLE, this.getX() + f, this.getY() + g, this.getZ() + h, vec3d.x, vec3d.y, vec3d.z); + } + + this.damage(ModDamageSources.NO_WATER_FOR_GILLS, 2.0F); + } + } else { + int landGain = this.getNextAirOnLand(0); + this.setAir(this.getAir() - landGain); } } else if(this.getAir() < this.getMaxAir()){ this.setAir(this.getNextAirOnLand(this.getAir())); @@ -130,6 +139,12 @@ private void tick(CallbackInfo info) { } } + // Copy from Entity#isBeingRainedOn + private boolean isRainingAtPlayerPosition() { + BlockPos blockPos = this.getBlockPos(); + return this.world.hasRain(blockPos) || this.world.hasRain(blockPos.add(0.0D, (double)this.getDimensions(this.getPose()).height, 0.0D)); + } + // WATER_BREATHING @Redirect(at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;isSubmergedIn(Lnet/minecraft/tag/Tag;)Z"), method = "updateTurtleHelmet") public boolean isSubmergedInProxy(PlayerEntity player, Tag fluidTag) {