Skip to content

Commit

Permalink
fix weather data being sent to all dimensions, fix hammerheads spawni…
Browse files Browse the repository at this point in the history
…ng for sharnado
  • Loading branch information
Corosauce committed Nov 22, 2024
1 parent f86ad8c commit cc34488
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/main/java/weather2/ServerTickHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public static void processIMCMessages() {
wm.addStormObject(stormObject);
wm.syncStormNew(stormObject);

CULog.dbg("processed imc message: " + tag);
CULog.dbg("processed imc message: " + tag + " - " + msg + " - " + wm.dimension);
} else if (msg.method().equals("firenado")) {
StormObject stormObject = new StormObject(wm);

Expand Down
16 changes: 15 additions & 1 deletion src/main/java/weather2/weathersystem/WeatherManagerClient.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package weather2.weathersystem;

import com.corosus.coroutil.util.CULog;
import com.corosus.coroutil.util.CoroUtilMisc;
import extendedrenderer.particle.entity.ParticleCube;
import net.minecraft.client.Minecraft;
Expand Down Expand Up @@ -73,10 +74,23 @@ public void nbtSyncFromServer(CompoundTag parNBT) {
String command = parNBT.getString("command");

if (command.equals("syncStormNew")) {

CULog.dbg("nbtSyncFromServer: " + parNBT);

//Weather.dbg("creating client side storm");
CompoundTag stormNBT = parNBT.getCompound("data");
long ID = stormNBT.getLong("ID");
Weather.dbg("syncStormNew, ID: " + ID);
Weather.dbg("syncStormNewsss, ID: " + ID);

//new check to workaround weird bug of WeatherNetworkingv2.instance().serverSendToClientsInDimension sending to every client no matter what
//turns out it was IDEA caching builds for some ungodly reason, remove this code
String dimID = stormNBT.getString("dimID");

/*CULog.dbg(dimID + " vs " + this.dimension.toString());
if (!dimID.equals(this.dimension.toString())) {
CULog.dbg("dimensions dont match, aborting sync of new tornado");
return;
}*/

EnumWeatherObjectType weatherObjectType = EnumWeatherObjectType.get(stormNBT.getInt("weatherObjectType"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -677,10 +677,10 @@ public void syncStormNew(WeatherObject parStorm, @Nullable ServerPlayer entP) {
data.put("data", cache.getNewNBT());

if (entP == null) {
//WeatherNetworking.HANDLER.send(PacketDistributor.DIMENSION.with(() -> getWorld().dimension()), new PacketNBTFromServer(data));
WeatherNetworkingv2.instance().serverSendToClientAll(data);
CULog.dbg("sending syncStormNew to " + getWorld().dimension());
WeatherNetworkingv2.instance().serverSendToClientsInDimension(data, getWorld());
} else {
//WeatherNetworking.HANDLER.sendTo(new PacketNBTFromServer(data), entP.connection.connection, NetworkDirection.PLAY_TO_CLIENT);
CULog.dbg("sending syncStormNew to " + entP.getName());
WeatherNetworkingv2.instance().serverSendToClientPlayer(data, entP);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2428,7 +2428,7 @@ public void spinEntityv2(Entity entity) {
}

if (entity.isInWater()) {
entity.getPersistentData().putBoolean("tornado_shoot", false);
//entity.getPersistentData().putBoolean("tornado_shoot", false);
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/weather2/weathersystem/storm/WeatherObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ public void nbtSyncForClient() {
nbt.putInt("size", size);
nbt.putInt("maxSize", maxSize);
nbt.putInt("weatherObjectType", this.weatherObjectType.ordinal());

/*if (manager != null && manager.getWorld() != null) {
nbt.putString("dimID", manager.getWorld().dimension().toString());
}*/
}

public CachedNBTTagCompound getNbtCache() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import net.minecraft.client.ParticleStatus;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
Expand All @@ -15,6 +17,9 @@
import net.minecraft.world.phys.Vec3;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.api.distmarker.OnlyIn;
import net.neoforged.neoforge.common.NeoForge;
import net.tropicraft.core.common.entity.TropicraftEntities;
import net.tropicraft.core.common.entity.underdasea.SharkEntity;
import weather2.Weather;
import weather2.weathersystem.storm.StormObject;
import weather2.weathersystem.tornado.ActiveTornadoConfig;
Expand Down Expand Up @@ -108,7 +113,7 @@ public void tick() {
double dist = posLayer.distanceTo(posLayerLower);
//easy way to fix the spawning at 0,0 issue
if (dist > 50) {
CULog.dbg("teleporting tornado layer to lower piece");
//CULog.dbg("teleporting tornado layer to lower piece");
listLayers.get(i).setPos(new Vec3(posLayerLower.x, posLayerLower.y, posLayerLower.z));
} else if (dist > 0.1F * (radius / radiusMax)) {
double dynamicSpeed = 15F * (Math.min(30F, dist) / 30F);
Expand All @@ -126,19 +131,20 @@ public void tick() {
if (level.getGameTime() % 20 == 0) {
Entity ent = null;
if (Weather.isLoveTropicsInstalled()) {
/**
* TODO: for LT, turn back on when LT is needed, activates dependency on LTWeather / Tropicraft
*/
//ent = new SharkEntity(TropicraftEntities.HAMMERHEAD.get(), level);
}
if (ent == null) {
ent = new Dolphin(EntityType.DOLPHIN, level);
EntityType type = BuiltInRegistries.ENTITY_TYPE.get(ResourceLocation.parse("tropicraft:hammerhead"));
if (type != null) {
ent = new SharkEntity(type, level);
}

}
if (ent == null) {
CULog.log("SharkEntity not spawned, enable in weather mod");
if (Weather.isLoveTropicsInstalled()) {
CULog.dbg("failed to create shark, falling back to dolphin");
}

ent = new Dolphin(EntityType.DOLPHIN, level);
}
Vec3 posRand = new Vec3(pos.x + 0, pos.y + 3, pos.z - 5);
Vec3 posRand = new Vec3(pos.x + 0, pos.y + 25, pos.z - 5);
ent.setPos(posRand);
ent.setDeltaMovement(3F, 0, 0);
level.addFreshEntity(ent);
Expand Down

0 comments on commit cc34488

Please sign in to comment.