Skip to content

Commit

Permalink
Polished the new wind force code, vanilla motion dampening was interf…
Browse files Browse the repository at this point in the history
…ering, now an option to disable it in EntityRotFX, Added low wind command, readded advanced GUI button to weather2, had only half reenabled it, cleaned up tasks
  • Loading branch information
Corosauce committed Nov 3, 2016
1 parent 63cfcde commit b003c2b
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 39 deletions.
22 changes: 22 additions & 0 deletions src/main/java/weather2/CommandWeather2.java
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,28 @@ public void execute(MinecraftServer server, ICommandSender var1, String[] var2)
wm.windMan.stopHighWindEvent();
CoroUtil.sendPlayerMsg((EntityPlayerMP) var1, "stopped high wind event");
}
} else if (var2[1].equals("low")) {
boolean doLowOn = false;
boolean doLowOff = false;
if (var2.length > 2) {
if (var2[2].equals("start")) {
doLowOn = true;
} else if (var2[2].equals("stop")) {
doLowOff = true;
}
} else {
doLowOn = true;
}
WeatherManagerServer wm = ServerTickHandler.getWeatherSystemForDim(player.worldObj.provider.getDimension());
if (doLowOn) {
wm.windMan.startLowWindEvent();
//cancel any low wind state if there is one
wm.windMan.lowWindTimer = 0;
CoroUtil.sendPlayerMsg((EntityPlayerMP) var1, "started low wind event");
} else if (doLowOff) {
wm.windMan.stopLowWindEvent();
CoroUtil.sendPlayerMsg((EntityPlayerMP) var1, "stopped low wind event");
}
}
} else {
CoroUtil.sendPlayerMsg((EntityPlayerMP) var1, helpMsgStorm);
Expand Down
85 changes: 59 additions & 26 deletions src/main/java/weather2/client/SceneEnhancer.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public void tickClient() {
//tickTest();
//tickTestFog();
tickSandstorm();
tickTestSandstormParticles();
//tickTestSandstormParticles();
}
}

Expand Down Expand Up @@ -1182,7 +1182,7 @@ else if (WeatherUtilParticle.getParticleAge((Particle)entity1) % 2 == 0)
}
}

System.out.println("particles moved: " + handleCount);
//System.out.println("particles moved: " + handleCount);

WindManager windMan = ClientTickHandler.weatherManager.windMan;

Expand Down Expand Up @@ -1249,7 +1249,8 @@ else if (WeatherUtilParticle.getParticleAge((Particle)entity1) % 2 == 0)
//entity1.motionY += -0.04 + rand.nextDouble() * 0.04;
//if (canPushEntity(entity1)) {
//if (!(entity1 instanceof EntityFlameFX)) {
applyWindForce(entity1);
//applyWindForce(entity1);
applyWindForceNew(entity1, 1F/20F, 0.5F);
}
}
}
Expand Down Expand Up @@ -1303,6 +1304,10 @@ else if (WeatherUtilParticle.getParticleAge((Particle)entity1) % 2 == 0)
}*/
}

public static void applyWindForceNew(Object ent) {
applyWindForceNew(ent, 1F/20F, 0.5F);
}

/**
*
* To solve the problem of speed going overkill due to bad formulas
Expand All @@ -1319,39 +1324,58 @@ else if (WeatherUtilParticle.getParticleAge((Particle)entity1) % 2 == 0)
* @param ent
*/
public static void applyWindForceNew(Object ent, float multiplier, float maxSpeed) {

/**
* Wind acceleration = wind speed and direction - obj speed and direction
* Wind mass = ???, 1?
* Wind force = mass * acceleration
*
*
*
*
*/

boolean debugParticle = false;
if (ent instanceof EntityRotFX) {
EntityRotFX part = (EntityRotFX) ent;
if (part.debugID == 1) {
debugParticle = true;
}
}

WindManager windMan = ClientTickHandler.weatherManager.windMan;

float windSpeed = windMan.getWindSpeedForPriority();
float windAngle = windMan.getWindAngleForPriority();

float windX = (float) -Math.sin(Math.toRadians(windAngle));
float windZ = (float) Math.cos(Math.toRadians(windAngle));
Random rand = new Random();

//temp
//windSpeed = 1F;
//windAngle = -90;//rand.nextInt(360);

float windX = (float) -Math.sin(Math.toRadians(windAngle)) * windSpeed;
float windZ = (float) Math.cos(Math.toRadians(windAngle)) * windSpeed;

float objX = (float) CoroUtilEntOrParticle.getMotionX(ent);
float objZ = (float) CoroUtilEntOrParticle.getMotionZ(ent);

float windWeight = 1F;
float objWeight = WeatherUtilEntity.getWeight(ent);

//divide by zero protection
if (objWeight <= 0) {
objWeight = 0.001F;
}

//TEMP
//objWeight = 1F;

float weightDiff = windWeight / objWeight;

float vecX = (objX - windX) * weightDiff * multiplier;
float vecZ = (objZ - windZ) * weightDiff * multiplier;
float vecX = (objX - windX) * weightDiff;
float vecZ = (objZ - windZ) * weightDiff;

vecX *= multiplier;
vecZ *= multiplier;

if (debugParticle) {
System.out.println(windX + " vs " + objX);
System.out.println("diff: " + String.format("%.5g%n", vecX));
}

double speedCheck = (Math.abs(vecX) + Math.abs(vecZ)) / 2D;
if (speedCheck < maxSpeed) {
//minus? why minus?!
CoroUtilEntOrParticle.setMotionX(ent, objX - vecX);
CoroUtilEntOrParticle.setMotionZ(ent, objZ - vecZ);
}
Expand Down Expand Up @@ -1475,16 +1499,25 @@ public static void tickTestFog() {

particleBehaviorFog = new ParticleBehaviorFogGround(new Vec3(mc.thePlayer.posX, mc.thePlayer.posY, mc.thePlayer.posZ));
} else {
//particleBehaviorFog.coordSource = new Vec3(mc.thePlayer.posX, mc.thePlayer.posY + 0.5D, mc.thePlayer.posZ);
particleBehaviorFog.coordSource = new Vec3(mc.thePlayer.posX, mc.thePlayer.posY + 0.5D, mc.thePlayer.posZ);
}

if (/*true || */particleBehaviorFog.particles.size() <= 10000) {
for (int i = 0; i < 1; i++) {
ParticleTexFX part = new ParticleTexFX(mc.theWorld, particleBehaviorFog.coordSource.xCoord, particleBehaviorFog.coordSource.yCoord, particleBehaviorFog.coordSource.zCoord
, 0, 0, 0, ParticleRegistry.cloud256);
particleBehaviorFog.initParticle(part);
particleBehaviorFog.particles.add(part);
part.spawnAsWeatherEffect();
if (mc.theWorld.getTotalWorldTime() % 300 == 0) {
if (/*true || */particleBehaviorFog.particles.size() <= 10000) {
for (int i = 0; i < 1; i++) {
ParticleTexFX part = new ParticleTexFX(mc.theWorld, particleBehaviorFog.coordSource.xCoord, particleBehaviorFog.coordSource.yCoord, particleBehaviorFog.coordSource.zCoord
, 0, 0, 0, ParticleRegistry.cloud256);
part.setMotionX(-1);
part.setMotionY(0.1);
particleBehaviorFog.initParticle(part);
//particleBehaviorFog.particles.add(part);
part.spawnAsWeatherEffect();
part.windWeight = 5F;
part.debugID = 1;
part.setMaxAge(280);
part.setVanillaMotionDampen(false);
ClientTickHandler.weatherManager.addWeatheredParticle(part);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,6 @@ public float getWindWeight() {

@Override
public int getParticleDecayExtra() {
// TODO Auto-generated method stub
return 0;
}
}
8 changes: 4 additions & 4 deletions src/main/java/weather2/client/gui/GuiEZConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
import java.util.Iterator;
import java.util.List;

import modconfig.gui.GuiConfigEditor;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.VertexBuffer;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.common.FMLCommonHandler;

Expand Down Expand Up @@ -506,7 +507,7 @@ public void initGui()


addButton(new GuiButton(CMD_CLOSE, xStart + xSize - guiPadding - btnWidth, yStart + ySize - guiPadding - btnHeight, btnWidth, btnHeight, "Save & Close"));
//addButton(new GuiButton(CMD_ADVANCED, xStart + xSize - guiPadding - btnWidth - btnWidthAndPadding, yStart + ySize - guiPadding - btnHeight, btnWidth, btnHeight, "Advanced"));
addButton(new GuiButton(CMD_ADVANCED, xStart + xSize - guiPadding - btnWidth - btnWidthAndPadding, yStart + ySize - guiPadding - btnHeight, btnWidth, btnHeight, "Advanced"));

addButton(new GuiButton(CMD_SUBGUI_PERFORMANCE, xStartPadded+btnWidthAndPadding*0, yStartPadded, btnWidth, btnHeight, (guiCur.equals(GUI_SUBGUI_PERFORMANCE) ? "\u00A7" + '2' : "") + GUI_SUBGUI_PERFORMANCE));
addButton(new GuiButton(CMD_SUBGUI_COMPATIBILITY, xStartPadded+btnWidthAndPadding*1, yStartPadded, btnWidth, btnHeight, (guiCur.equals(GUI_SUBGUI_COMPATIBILITY) ? "\u00A7" + '2' : "") + GUI_SUBGUI_COMPATIBILITY));
Expand Down Expand Up @@ -633,8 +634,7 @@ protected void actionPerformed(GuiButton var1)
initGui();
}*/
} else if (var1.id == CMD_ADVANCED) {
//TODO: 1.8 readd
//Minecraft.getMinecraft().displayGuiScreen(new GuiConfigEditor());
Minecraft.getMinecraft().displayGuiScreen(new GuiConfigEditor());
} else {
//at this point the remaining Ids not covered should be the dimension feature enable buttons

Expand Down
1 change: 0 additions & 1 deletion src/main/java/weather2/util/WeatherUtilEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ public static float getWeight(Object entity1, boolean forTornado)
return ((IWindHandler) entity1).getWindWeight();
}

//commented out for weather2 copy
if (entity1 instanceof EntityMovingBlock)
{
return 1F + ((float)((EntityMovingBlock) entity1).age / 200);
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/weather2/weathersystem/storm/StormObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -371,9 +371,6 @@ public void tick() {
super.tick();
//Weather.dbg("ticking storm " + ID + " - manager: " + manager);


//TODO: 1.10.2 TEMP OFF REENABLE
//if (true) return;

//adjust posGround to be pos with the ground Y pos for convinient usage
posGround = new Vec3(pos.xCoord, pos.yCoord, pos.zCoord);
Expand Down Expand Up @@ -1857,7 +1854,6 @@ public void spinEntity(Object entity1) {

boolean forTornado = true;//entT != null;

//TODO: 1.10.2 will this break client code?
World world = CoroUtilEntOrParticle.getWorld(entity1);
long worldTime = world.getTotalWorldTime();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,6 @@ public NBTTagCompound nbtSyncForClient(NBTTagCompound nbt) {

@Override
public void nbtSyncFromServer(NBTTagCompound parNBT) {
// TODO Auto-generated method stub
super.nbtSyncFromServer(parNBT);

posSpawn = new Vec3(parNBT.getDouble("posSpawnX"), parNBT.getDouble("posSpawnY"), parNBT.getDouble("posSpawnZ"));
Expand Down
12 changes: 10 additions & 2 deletions src/main/java/weather2/weathersystem/wind/WindManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ public void tick() {
if (highWindTimer <= 0) {
if (ConfigMisc.Wind_NoWindEvents) {
if (rand.nextInt(lowWindOddsTo1) == 0) {
lowWindTimer = lowWindTimerEnableAmountBase + rand.nextInt(lowWindTimerEnableAmountRnd);
Weather.dbg("no wind event, for ticks: " + lowWindTimer);
startLowWindEvent();
Weather.dbg("low wind event, for ticks: " + lowWindTimer);
}
}
}
Expand Down Expand Up @@ -320,6 +320,14 @@ public void startHighWindEvent() {
public void stopHighWindEvent() {
highWindTimer = 0;
}

public void startLowWindEvent() {
lowWindTimer = lowWindTimerEnableAmountBase + (new Random()).nextInt(lowWindTimerEnableAmountRnd);
}

public void stopLowWindEvent() {
lowWindTimer = 0;
}

@SideOnly(Side.CLIENT)
public void tickClient() {
Expand Down

0 comments on commit b003c2b

Please sign in to comment.