Skip to content

Commit

Permalink
fixes server-side evolution displays in watch not working
Browse files Browse the repository at this point in the history
  • Loading branch information
Thutmose committed Sep 11, 2022
1 parent 234dba1 commit e0dffb2
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/main/java/pokecube/api/data/PokedexEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
import pokecube.core.database.pokedex.PokedexEntryLoader.FormeItem;
import pokecube.core.database.pokedex.PokedexEntryLoader.Interact;
import pokecube.core.database.pokedex.PokedexEntryLoader.MegaEvoRule;
import pokecube.core.database.pokedex.PokedexEntryLoader.SpawnRule;
import pokecube.core.database.pokedex.PokedexEntryLoader.XMLMegaRule;
import pokecube.core.database.tags.Tags;
import pokecube.core.entity.pokemobs.DispenseBehaviourInteract;
Expand Down Expand Up @@ -112,6 +113,8 @@ public class PokedexEntry
public static class EvolutionData
{
public SpawnBiomeMatcher matcher = null;
public SpawnRule _match_rule = null;

public Evolution data;
public boolean dayOnly = false;
public final PokedexEntry evolution;
Expand Down Expand Up @@ -185,9 +188,7 @@ else if (this.preset != null)
.translatable("pokemob.description.evolve.move", MovesUtils.getMoveName(this.move).getString()));
if (this.matcher != null)
{
SpawnBiomeMatcher.populateClientValues(matcher);
comps.addAll(SpawnListEntry.makeDescription(null, matcher, null, 100));
SpawnBiomeMatcher.clearClientValues(matcher);
}
return comps;
}
Expand Down Expand Up @@ -241,7 +242,7 @@ private void parse(final Evolution data)
{
this.preset = null;
if (data.level != null) this.level = data.level;
if (data.location != null) this.matcher = SpawnBiomeMatcher.get(data.location);
if (data.location != null) this.matcher = SpawnBiomeMatcher.get(_match_rule = data.location);
if (data.animation != null) this.FX = data.animation;
if (data.item != null) this.item = Tools.getStack(data.item.getValues());
if (data.item_preset != null) this.preset = PokecubeItems.toPokecubeResource(data.item_preset);
Expand Down
60 changes: 60 additions & 0 deletions src/main/java/pokecube/core/network/packets/PacketPokedex.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import net.minecraftforge.api.distmarker.OnlyIn;
import pokecube.api.PokecubeAPI;
import pokecube.api.data.PokedexEntry;
import pokecube.api.data.PokedexEntry.EvolutionData;
import pokecube.api.data.PokedexEntry.SpawnData.SpawnEntry;
import pokecube.api.data.spawns.SpawnBiomeMatcher;
import pokecube.api.data.spawns.SpawnCheck;
Expand Down Expand Up @@ -279,14 +280,46 @@ public static void sendLoginPacket(final ServerPlayer target)
PacketPokedex.ASSEMBLER.sendTo(message, target);
}
final PacketPokedex message = new PacketPokedex(PacketPokedex.CHECKLEGEND);

// Put in the legendaries needing conditions
final ListTag legends = new ListTag();
for (final PokedexEntry e : ISpecialCaptureCondition.captureMap.keySet())
legends.add(StringTag.valueOf(e.getTrimmedName()));
message.getTag().put("legends", legends);

// List of mobs that cannot breed
final ListTag no_breed = new ListTag();
// List of spawn biome matchers for evolutions
final ListTag evo_rules = new ListTag();

// Put in a list of mobs that cannot breed
for (final PokedexEntry e : Database.getSortedFormes())
{
if (!e.breeds) no_breed.add(StringTag.valueOf(e.getTrimmedName()));
CompoundTag tag = new CompoundTag();
final ListTag evos = new ListTag();
tag.putString("id", e.getTrimmedName());
for (EvolutionData d : e.evolutions)
{
if (d._match_rule != null)
{
String msg = PacketPokedex.serialize(d.matcher);
if (msg == null) continue;
CompoundTag sub = new CompoundTag();
sub.putString("old", gson.toJson(d._match_rule));
sub.putString("new", msg);
evos.add(sub);
}
}
if (!evos.isEmpty())
{
tag.put("l", evos);
evo_rules.add(tag);
}
}
message.getTag().put("no_breed", no_breed);
if (!evo_rules.isEmpty()) message.getTag().put("evo_rules", evo_rules);

PacketPokedex.ASSEMBLER.sendTo(message, target);
}

Expand Down Expand Up @@ -377,6 +410,33 @@ protected void onCompleteClient()
final PokedexEntry p = Database.getEntry(no_breed.getString(i));
if (p != null) PacketPokedex.noBreeding.add(p);
}
if (this.getTag().contains("evo_rules"))
{
final ListTag evo_rules = this.getTag().getList("evo_rules", 10);
for (int i = 0; i < evo_rules.size(); i++)
{
CompoundTag tag = evo_rules.getCompound(i);
PokedexEntry e = Database.getEntry(tag.getString("id"));
if (e == null) continue;
final ListTag evos = tag.getList("l", 10);
outer:
for (int ii = 0; ii < evos.size(); ii++)
{
tag = evos.getCompound(ii);
String old = tag.getString("old");
SpawnBiomeMatcher match = PacketPokedex.gson.fromJson(tag.getString("new"),
SpawnBiomeMatcher.class);
for (EvolutionData d : e.evolutions)
{
if (d._match_rule != null && old.equals(gson.toJson(d._match_rule)))
{
d.matcher = match;
continue outer;
}
}
}
}
}
return;
}
}
Expand Down

0 comments on commit e0dffb2

Please sign in to comment.