Skip to content

Commit

Permalink
Made Merlings not lose air on land when raining, prevented Phantom bu…
Browse files Browse the repository at this point in the history
…rning 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
  • Loading branch information
apace100 committed Jul 5, 2020
1 parent 31bedc7 commit 923ea5d
Showing 1 changed file with 29 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<? extends LivingEntity> entityType, World world) {
super(entityType, world);
}
Expand Down Expand Up @@ -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)) {
Expand All @@ -109,27 +113,38 @@ 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()));
}
}
}

// 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<Fluid> fluidTag) {
Expand Down

0 comments on commit 923ea5d

Please sign in to comment.