Skip to content

Commit

Permalink
v2.8.1. Implemented dynamic wind speeds based on relative height arou…
Browse files Browse the repository at this point in the history
…nd nearby chunks mainly for server side, client side uses a cached value based on player position. Turbine generates more energy and more constantly at higher altitudes. Fix particle breaking for model based blocks. Switch to using global rate for storms by default. Switch to having an initial delay before a deadly storm can start, prevents a tornado bearing down on you within minutes of world start.
  • Loading branch information
Corosauce committed Dec 5, 2023
1 parent 592abc0 commit 1d1fbc6
Show file tree
Hide file tree
Showing 30 changed files with 423 additions and 131 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ mod_name=Weather2
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
mod_license=All Rights Reserved
# The mod version. See https://semver.org/
mod_version=1.20.1-2.8.0
mod_version=1.20.1-2.8.1
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
# This should match the base package used for the mod sources.
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import weather2.ClientWeatherProxy;
import weather2.client.SceneEnhancer;
import weather2.datatypes.PrecipitationType;
import weather2.util.WeatherUtilParticle;

@OnlyIn(Dist.CLIENT)
public class ParticleBehaviors {
Expand Down Expand Up @@ -498,7 +499,7 @@ public void initParticleDustGround(EntityRotFX particle, boolean spawnInside, bo
}

public void initParticleLeaf(EntityRotFX particle, float particleAABB) {
Vec3 windForce = ClientTickHandler.getClientWeather().getWindManager().getWindForce();
Vec3 windForce = ClientTickHandler.getClientWeather().getWindManager().getWindForce(WeatherUtilParticle.getPos(particle));
particle.setMotionX(windForce.x / 2);
particle.setMotionZ(windForce.z / 2);
particle.setMotionY(windForce.y / 2);
Expand All @@ -516,7 +517,7 @@ public void initParticleLeaf(EntityRotFX particle, float particleAABB) {

public void initParticleSnowstormCloudDust(EntityRotFX particle) {
boolean farSpawn = Minecraft.getInstance().player.isSpectator() || !SceneEnhancer.isPlayerOutside;
Vec3 windForce = ClientTickHandler.getClientWeather().getWindManager().getWindForce();
Vec3 windForce = ClientTickHandler.getClientWeather().getWindManager().getWindForce(null);
particle.setMotionX(windForce.x * 0.3);
particle.setMotionZ(windForce.z * 0.3);
particle.setFacePlayer(false);
Expand All @@ -541,7 +542,7 @@ public void initParticleSnowstormCloudDust(EntityRotFX particle) {
}

public void initParticleSandstormDust(EntityRotFX particle) {
Vec3 windForce = ClientTickHandler.getClientWeather().getWindManager().getWindForce();
Vec3 windForce = ClientTickHandler.getClientWeather().getWindManager().getWindForce(null);
particle.setMotionX(windForce.x);
particle.setMotionZ(windForce.z);
particle.setFacePlayer(false);
Expand All @@ -564,7 +565,7 @@ public void initParticleSandstormDust(EntityRotFX particle) {
}

public void initParticleSandstormTumbleweed(EntityRotFX particle) {
Vec3 windForce = ClientTickHandler.getClientWeather().getWindManager().getWindForce();
Vec3 windForce = ClientTickHandler.getClientWeather().getWindManager().getWindForce(null);
particle.setMotionX(windForce.x);
particle.setMotionZ(windForce.z);
particle.setFacePlayer(false);
Expand Down Expand Up @@ -592,7 +593,7 @@ public void initParticleSandstormTumbleweed(EntityRotFX particle) {
}

public void initParticleSandstormDebris(EntityRotFX particle) {
Vec3 windForce = ClientTickHandler.getClientWeather().getWindManager().getWindForce();
Vec3 windForce = ClientTickHandler.getClientWeather().getWindManager().getWindForce(null);
particle.setMotionX(windForce.x);
particle.setMotionZ(windForce.z);
particle.setFacePlayer(false);
Expand Down
13 changes: 11 additions & 2 deletions src/main/java/extendedrenderer/particle/entity/EntityRotFX.java
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ public String toString() {
private static final AABB INITIAL_AABB = new AABB(0.0D, 0.0D, 0.0D, 0.0D, 0.0D, 0.0D);
private AABB bbRender = INITIAL_AABB;
private float renderDistanceCull = -1;
private boolean useDynamicWindSpeed = true;

public EntityRotFX(ClientLevel par1World, double par2, double par4, double par6, double par8, double par10, double par12)
{
Expand Down Expand Up @@ -419,9 +420,9 @@ public void tickExtraRotations() {
if (this instanceof PivotingParticle) return;
//particles on ground shouldnt get blown as hard (idea for hail)
if (onGround) {
windMan.applyWindForceNew(this, (1F / 20F) * 0.3F, 0.5F);
windMan.applyWindForceNew(this, (1F / 20F) * 0.3F, 0.5F, useDynamicWindSpeed);
} else {
windMan.applyWindForceNew(this, 1F / 20F, 0.5F);
windMan.applyWindForceNew(this, 1F / 20F, 0.5F, useDynamicWindSpeed);
}

/*if (!quatControl) {
Expand Down Expand Up @@ -983,4 +984,12 @@ public float getRenderDistanceCull() {
public void setRenderDistanceCull(float renderDistanceCull) {
this.renderDistanceCull = renderDistanceCull;
}

public boolean isUseDynamicWindSpeed() {
return useDynamicWindSpeed;
}

public void setUseDynamicWindSpeed(boolean useDynamicWindSpeed) {
this.useDynamicWindSpeed = useDynamicWindSpeed;
}
}
2 changes: 1 addition & 1 deletion src/main/java/weather2/ClientTickHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public void onTickInGame()

//TODO: evaluate if best here
float windDir = WindReader.getWindAngle(world);
float windSpeed = WindReader.getWindSpeed(world);
float windSpeed = WindReader.getWindSpeed(world, mc.player != null ? mc.player.blockPosition() : null);

//windDir = 0;
//TODO: ???????????? what is all this even affecting now
Expand Down
1 change: 1 addition & 0 deletions src/main/java/weather2/Weather.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ public Weather() {
ConfigMod.addConfigFile(MODID, addConfig(new ConfigTornado()));
ConfigMod.addConfigFile(MODID, addConfig(new ConfigParticle()));
ConfigMod.addConfigFile(MODID, addConfig(new ConfigDebug()));
ConfigMod.addConfigFile(MODID, addConfig(new ConfigSound()));
//ConfigMod.addConfigFile(MODID, addConfig(new ConfigFoliage()));
//WeatherUtilConfig.nbtLoadDataAll();

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/weather2/block/WindTurbineBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.Component;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.BaseEntityBlock;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.RenderShape;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityTicker;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ public void tick(Level level, BlockPos pos, BlockState state) {
}

if (isOutsideCached) {
float windSpeed = WindReader.getWindSpeed(level);
//do not cache for this, the amp value used will mess with the turbines amp, design oversight
float windSpeed = WindReader.getWindSpeed(level, pos, 1);
float rotMax = 50F;
float maxSpeed = (windSpeed / 1.2F) * rotMax;
if (smoothAngleRotationalVel < maxSpeed) {
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/weather2/blockentity/SirenBlockEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import weather2.WeatherBlocks;
import weather2.config.ConfigMisc;
import weather2.config.ConfigSand;
import weather2.config.ConfigSound;
import weather2.util.WeatherUtilSound;
import weather2.weathersystem.storm.StormObject;
import weather2.weathersystem.storm.WeatherObjectParticleStorm;
Expand Down Expand Up @@ -47,7 +48,7 @@ public void tickClient() {
if (so != null)
{
this.lastPlayTime = System.currentTimeMillis() + 13000L;
WeatherUtilSound.playNonMovingSound(pos, "streaming.siren", 1.0F, 1.0F, 120);
WeatherUtilSound.playNonMovingSound(pos, "streaming.siren", (float) ConfigSound.sirenVolume, 1.0F, 120);
} else {
if (!ConfigSand.Sandstorm_Siren_PleaseNoDarude) {
WeatherObjectParticleStorm storm = ClientTickHandler.weatherManager.getClosestParticleStormByIntensity(pos, WeatherObjectParticleStorm.StormType.SANDSTORM);
Expand All @@ -63,10 +64,10 @@ public void tickClient() {
soundToPlay = "siren_sandstorm_6_extra";
}

float distScale = Math.max(0.1F, 1F - (float) ((pos.distanceTo(storm.pos)) / storm.getSize()));
float distScaleFunnyPitchChangeHaha = Math.max(0.1F, 1F - (float) ((pos.distanceTo(storm.pos)) / storm.getSize()));

this.lastPlayTime = System.currentTimeMillis() + 15000L;//WeatherUtilSound.soundToLength.get(soundToPlay) - 500L;
WeatherUtilSound.playNonMovingSound(pos, "streaming." + soundToPlay, 1F, distScale, storm.getSize());
WeatherUtilSound.playNonMovingSound(pos, "streaming." + soundToPlay, (float) ConfigSound.sirenVolume, distScaleFunnyPitchChangeHaha, storm.getSize());
}
}
}
Expand Down
38 changes: 22 additions & 16 deletions src/main/java/weather2/blockentity/WindTurbineBlockEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.util.Mth;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
Expand All @@ -13,12 +12,12 @@
import net.minecraftforge.common.util.LazyOptional;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import weather2.Weather;
import weather2.WeatherBlocks;
import weather2.WeatherItems;
import weather2.config.ConfigWind;
import weather2.energy.EnergyManager;
import weather2.util.WeatherUtilEntity;
import weather2.util.WindReader;
import weather2.weathersystem.WeatherManager;

public class WindTurbineBlockEntity extends BlockEntity {

Expand All @@ -36,7 +35,7 @@ public class WindTurbineBlockEntity extends BlockEntity {
private EnergyManager energyManager;

//amount generated at windspeed of 1, theoretical max windspeed is 2 when tornado right on top of it
private int maxNormalGenerated = 10;
private int maxNormalGenerated = ConfigWind.Wind_Turbine_FE_Generated_Per_Tick;
private int capacity = maxNormalGenerated * 2;
private int maxTransfer = capacity;

Expand All @@ -59,22 +58,29 @@ public static void tick(Level level, BlockPos pos, BlockState state, WindTurbine
}

public void tick(Level level, BlockPos pos, BlockState state) {
if (needsInit) {
needsInit = false;
updateIsOutside();
}
if (level.getGameTime() % 100 == 0) {
updateIsOutside();
}
if (isOutsideCached) {
if (level.getGameTime() % 20 == 0) {
WeatherManager weatherManager = WindReader.getWeatherManagerFor(level);
if (weatherManager != null) {
lastWindSpeed = weatherManager.getWindManager().getWindSpeedPositional(getBlockPos(), 2, false);
}
}
}
if (!level.isClientSide) {
if (level.getGameTime() % 100 == 0) {
lastWindSpeed = WindReader.getWindSpeed(level, getBlockPos());
if (isOutsideCached) {
this.energyManager.addEnergy((int) (maxNormalGenerated * lastWindSpeed));
outputEnergy();
}
this.energyManager.addEnergy((int) (maxNormalGenerated * lastWindSpeed));
outputEnergy();
} else {
if (needsInit) {
needsInit = false;
updateIsOutside();
}
if (level.getGameTime() % 100 == 0) {
updateIsOutside();
}
if (isOutsideCached) {
float windSpeed = WindReader.getWindSpeed(level);
float windSpeed = lastWindSpeed;//WindReader.getWindSpeed(level);
float rotMax = 100F;
float maxSpeed = (windSpeed / 2F) * rotMax;
if (smoothAngleRotationalVel < maxSpeed) {
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/weather2/blockentity/WindVaneBlockEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ public void tick(Level level, BlockPos pos, BlockState state) {

if (isOutsideCached) {
float targetAngle = WindReader.getWindAngle(level, new Vec3(getBlockPos().getX(), getBlockPos().getY(), getBlockPos().getZ()));
float windSpeed = WindReader.getWindSpeed(level);
//do not cache for this, the amp value used will mess with the turbines amp, design oversight
float windSpeed = WindReader.getWindSpeed(level, pos, 1);
if (smoothAngle > 180) smoothAngle -= 360;
if (smoothAngle < -180) smoothAngle += 360;

Expand Down
Loading

0 comments on commit 1d1fbc6

Please sign in to comment.