mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-20 20:12:19 +00:00
Fix sync issues with researched mutations, use smaller packets
This commit is contained in:
1 parent
f3ee4f8694
commit
1ceccddbd0
10 files changed
+80
-73
No files matched your search
@@ -12,9 +12,6 @@ package forestry.apiculture.genetics;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
import forestry.api.apiculture.BeeManager;
|
||||
import forestry.api.apiculture.EnumBeeChromosome;
|
||||
@@ -27,13 +24,8 @@ import forestry.core.genetics.BreedingTracker;
|
||||
public class ApiaristTracker extends BreedingTracker implements IApiaristTracker {
|
||||
|
||||
/** Required for creation from map storage */
|
||||
@SuppressWarnings("unused")
|
||||
public ApiaristTracker(String s) {
|
||||
this(s, null, null);
|
||||
}
|
||||
|
||||
public ApiaristTracker(String s, GameProfile player, World world) {
|
||||
super(s, player, world);
|
||||
super(s);
|
||||
}
|
||||
|
||||
private int queensTotal = 0;
|
||||
|
||||
@@ -328,10 +328,13 @@ public class BeeHelper extends SpeciesRoot implements IBeeRoot {
|
||||
|
||||
// Create a tracker if there is none yet.
|
||||
if (tracker == null) {
|
||||
tracker = new ApiaristTracker(filename, player, world);
|
||||
tracker = new ApiaristTracker(filename);
|
||||
world.setItemData(filename, tracker);
|
||||
}
|
||||
|
||||
tracker.setUsername(player);
|
||||
tracker.setWorld(world);
|
||||
|
||||
return tracker;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,9 +11,6 @@
|
||||
package forestry.arboriculture.genetics;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
import forestry.api.arboriculture.IArboristTracker;
|
||||
import forestry.api.arboriculture.TreeManager;
|
||||
@@ -25,11 +22,7 @@ public class ArboristTracker extends BreedingTracker implements IArboristTracker
|
||||
|
||||
/** Required for creation from map storage */
|
||||
public ArboristTracker(String s) {
|
||||
this(s, null, null);
|
||||
}
|
||||
|
||||
public ArboristTracker(String s, GameProfile player, World world) {
|
||||
super(s, player, world);
|
||||
super(s);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -272,10 +272,13 @@ public class TreeHelper extends SpeciesRoot implements ITreeRoot {
|
||||
|
||||
// Create a tracker if there is none yet.
|
||||
if (tracker == null) {
|
||||
tracker = new ArboristTracker(filename, player, world);
|
||||
tracker = new ArboristTracker(filename);
|
||||
world.setItemData(filename, tracker);
|
||||
}
|
||||
|
||||
tracker.setUsername(player);
|
||||
tracker.setWorld(world);
|
||||
|
||||
return tracker;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ package forestry.core.genetics;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
@@ -34,7 +35,7 @@ import forestry.api.genetics.IBreedingTracker;
|
||||
import forestry.api.genetics.IIndividual;
|
||||
import forestry.api.genetics.IMutation;
|
||||
import forestry.api.genetics.ISpeciesRoot;
|
||||
import forestry.core.network.packets.PacketGenomeTrackerUpdate;
|
||||
import forestry.core.network.packets.PacketGenomeTrackerSync;
|
||||
import forestry.core.proxy.Proxies;
|
||||
|
||||
public abstract class BreedingTracker extends WorldSavedData implements IBreedingTracker {
|
||||
@@ -47,6 +48,7 @@ public abstract class BreedingTracker extends WorldSavedData implements IBreedin
|
||||
private static final String RESEARCHED_KEY = "RD";
|
||||
private static final String MODE_NAME_KEY = "BMS";
|
||||
private static final String MUTATION_FORMAT = "%s-%s=%s";
|
||||
private static final Collection<String> emptyStringCollection = Collections.emptyList();
|
||||
|
||||
public static final String TYPE_KEY = "TYPE";
|
||||
|
||||
@@ -56,13 +58,19 @@ public abstract class BreedingTracker extends WorldSavedData implements IBreedin
|
||||
private String modeName;
|
||||
|
||||
@Nullable
|
||||
private final GameProfile username;
|
||||
private GameProfile username;
|
||||
@Nullable
|
||||
private final World world;
|
||||
private World world;
|
||||
|
||||
protected BreedingTracker(String s, @Nullable GameProfile username, @Nullable World world) {
|
||||
protected BreedingTracker(String s) {
|
||||
super(s);
|
||||
}
|
||||
|
||||
public void setUsername(@Nullable GameProfile username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public void setWorld(@Nullable World world) {
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
@@ -90,13 +98,6 @@ public abstract class BreedingTracker extends WorldSavedData implements IBreedin
|
||||
*/
|
||||
protected abstract String speciesRootUID();
|
||||
|
||||
private void syncToPlayer() {
|
||||
if (world != null && username != null) {
|
||||
EntityPlayer player = world.getPlayerEntityByName(username.getName());
|
||||
synchToPlayer(player);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void synchToPlayer(EntityPlayer player) {
|
||||
if (player instanceof EntityPlayerMP && !(player instanceof FakePlayer)) {
|
||||
@@ -106,7 +107,24 @@ public abstract class BreedingTracker extends WorldSavedData implements IBreedin
|
||||
|
||||
NBTTagCompound nbttagcompound = new NBTTagCompound();
|
||||
encodeToNBT(nbttagcompound);
|
||||
Proxies.net.sendToPlayer(new PacketGenomeTrackerUpdate(nbttagcompound), player);
|
||||
PacketGenomeTrackerSync packet = new PacketGenomeTrackerSync(nbttagcompound);
|
||||
Proxies.net.sendToPlayer(packet, player);
|
||||
}
|
||||
}
|
||||
|
||||
private void syncToPlayer(Collection<String> discoveredSpecies, Collection<String> discoveredMutations, Collection<String> researchedMutations) {
|
||||
if (world != null && username != null) {
|
||||
EntityPlayer player = world.getPlayerEntityByName(username.getName());
|
||||
if (player instanceof EntityPlayerMP && !(player instanceof FakePlayer)) {
|
||||
IBreedingTracker breedingTracker = getBreedingTracker(player);
|
||||
String modeName = breedingTracker.getModeName();
|
||||
setModeName(modeName);
|
||||
|
||||
NBTTagCompound nbtTagCompound = new NBTTagCompound();
|
||||
writeToNBT(nbtTagCompound, discoveredSpecies, discoveredMutations, researchedMutations);
|
||||
PacketGenomeTrackerSync packet = new PacketGenomeTrackerSync(nbtTagCompound);
|
||||
Proxies.net.sendToPlayer(packet, player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,20 +153,22 @@ public abstract class BreedingTracker extends WorldSavedData implements IBreedin
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbttagcompound) {
|
||||
|
||||
if (modeName != null && !modeName.isEmpty()) {
|
||||
nbttagcompound.setString(MODE_NAME_KEY, modeName);
|
||||
}
|
||||
|
||||
nbttagcompound.setString(TYPE_KEY, speciesRootUID());
|
||||
|
||||
writeValuesToNBT(nbttagcompound, discoveredSpecies, SPECIES_COUNT_KEY, SPECIES_KEY);
|
||||
writeValuesToNBT(nbttagcompound, discoveredMutations, MUTATIONS_COUNT_KEY, MUTATIONS_KEY);
|
||||
writeValuesToNBT(nbttagcompound, researchedMutations, RESEARCHED_COUNT_KEY, RESEARCHED_KEY);
|
||||
writeToNBT(nbttagcompound, discoveredSpecies, discoveredMutations, researchedMutations);
|
||||
}
|
||||
|
||||
private static void readValuesFromNBT(NBTTagCompound nbttagcompound, Collection<String> values, String countKey, String key) {
|
||||
values.clear();
|
||||
private void writeToNBT(NBTTagCompound nbtTagCompound, Collection<String> discoveredSpecies, Collection<String> discoveredMutations, Collection<String> researchedMutations) {
|
||||
if (modeName != null && !modeName.isEmpty()) {
|
||||
nbtTagCompound.setString(MODE_NAME_KEY, modeName);
|
||||
}
|
||||
|
||||
nbtTagCompound.setString(TYPE_KEY, speciesRootUID());
|
||||
|
||||
writeValuesToNBT(nbtTagCompound, discoveredSpecies, SPECIES_COUNT_KEY, SPECIES_KEY);
|
||||
writeValuesToNBT(nbtTagCompound, discoveredMutations, MUTATIONS_COUNT_KEY, MUTATIONS_KEY);
|
||||
writeValuesToNBT(nbtTagCompound, researchedMutations, RESEARCHED_COUNT_KEY, RESEARCHED_KEY);
|
||||
}
|
||||
|
||||
private static void readValuesFromNBT(NBTTagCompound nbttagcompound, Set<String> values, String countKey, String key) {
|
||||
if (nbttagcompound.hasKey(countKey)) {
|
||||
final int count = nbttagcompound.getInteger(countKey);
|
||||
for (int i = 0; i < count; i++) {
|
||||
@@ -190,14 +210,14 @@ public abstract class BreedingTracker extends WorldSavedData implements IBreedin
|
||||
ForestryEvent event = new ForestryEvent.MutationDiscovered(speciesRoot, username, mutation, this);
|
||||
MinecraftForge.EVENT_BUS.post(event);
|
||||
|
||||
syncToPlayer();
|
||||
syncToPlayer(emptyStringCollection, Collections.singleton(mutationString), emptyStringCollection);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDiscovered(IMutation mutation) {
|
||||
String mutationString = getMutationString(mutation);
|
||||
return discoveredMutations.contains(mutationString);
|
||||
return discoveredMutations.contains(mutationString) || researchedMutations.contains(mutationString);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -225,7 +245,7 @@ public abstract class BreedingTracker extends WorldSavedData implements IBreedin
|
||||
ForestryEvent event = new ForestryEvent.SpeciesDiscovered(speciesRoot, username, species, this);
|
||||
MinecraftForge.EVENT_BUS.post(event);
|
||||
|
||||
syncToPlayer();
|
||||
syncToPlayer(Collections.singleton(species.getUID()), emptyStringCollection, emptyStringCollection);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -237,6 +257,8 @@ public abstract class BreedingTracker extends WorldSavedData implements IBreedin
|
||||
markDirty();
|
||||
|
||||
registerMutation(mutation);
|
||||
|
||||
syncToPlayer(emptyStringCollection, emptyStringCollection, Collections.singleton(mutationString));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@ import java.util.Map;
|
||||
import java.util.Stack;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.text.WordUtils;
|
||||
|
||||
import net.minecraft.client.renderer.RenderHelper;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
@@ -163,14 +162,6 @@ public abstract class GuiAlyzer extends GuiForestry<ContainerAlyzer, IInventory>
|
||||
textLayout.newLine();
|
||||
textLayout.drawLine("IV : " + StringUtil.localize("gui.evolution"), COLUMN_0 + 4);
|
||||
|
||||
textLayout.newLine();
|
||||
|
||||
String mode = breedingTracker.getModeName();
|
||||
if (mode != null && !mode.isEmpty()) {
|
||||
String rules = StringUtil.localize(guiName + ".behaviour") + ": " + WordUtils.capitalize(mode);
|
||||
textLayout.drawCenteredLine(rules, 8, 208, fontColor.get(guiName + ".binomial"));
|
||||
}
|
||||
|
||||
textLayout.endPage();
|
||||
}
|
||||
|
||||
@@ -278,7 +269,7 @@ public abstract class GuiAlyzer extends GuiForestry<ContainerAlyzer, IInventory>
|
||||
x += columnWidth;
|
||||
if (x >= columnWidth * 4) {
|
||||
x = 0;
|
||||
textLayout.newLine();
|
||||
textLayout.newLine(16);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -290,7 +281,7 @@ public abstract class GuiAlyzer extends GuiForestry<ContainerAlyzer, IInventory>
|
||||
ItemStack partnerBee = iconStacks.get(combination.getPartner(species).getUID());
|
||||
widgetManager.add(new ItemStackWidget(widgetManager, x, textLayout.getLineY(), partnerBee));
|
||||
|
||||
drawProbabilityArrow(combination.getBaseChance(), guiLeft + x + 18, guiTop + textLayout.getLineY() + 4);
|
||||
drawProbabilityArrow(combination, guiLeft + x + 18, guiTop + textLayout.getLineY() + 4);
|
||||
|
||||
IAllele result = combination.getTemplate()[EnumBeeChromosome.SPECIES.ordinal()];
|
||||
ItemStack resultBee = iconStacks.get(result.getUID());
|
||||
@@ -301,7 +292,7 @@ public abstract class GuiAlyzer extends GuiForestry<ContainerAlyzer, IInventory>
|
||||
|
||||
drawQuestionMark(guiLeft + x, guiTop + textLayout.getLineY());
|
||||
|
||||
drawProbabilityArrow(combination.getBaseChance(), guiLeft + x + 18, guiTop + textLayout.getLineY() + 4);
|
||||
drawProbabilityArrow(combination, guiLeft + x + 18, guiTop + textLayout.getLineY() + 4);
|
||||
|
||||
drawQuestionMark(guiLeft + x + 32, guiTop + textLayout.getLineY());
|
||||
}
|
||||
@@ -311,7 +302,8 @@ public abstract class GuiAlyzer extends GuiForestry<ContainerAlyzer, IInventory>
|
||||
drawTexturedModalRect(x, y, 78, 240, 16, 16);
|
||||
}
|
||||
|
||||
private void drawProbabilityArrow(float chance, int x, int y) {
|
||||
private void drawProbabilityArrow(IMutation combination, int x, int y) {
|
||||
float chance = combination.getBaseChance();
|
||||
int line = 247;
|
||||
int column = 100;
|
||||
switch (EnumMutateChance.rateChance(chance)) {
|
||||
@@ -339,6 +331,12 @@ public abstract class GuiAlyzer extends GuiForestry<ContainerAlyzer, IInventory>
|
||||
// Probability arrow
|
||||
Proxies.render.bindTexture(textureFile);
|
||||
drawTexturedModalRect(x, y, column, line, 15, 9);
|
||||
|
||||
boolean researched = breedingTracker.isResearched(combination);
|
||||
if (researched) {
|
||||
fontRendererObj.drawString("+", x + 9, y + 1, 0);
|
||||
GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
}
|
||||
}
|
||||
|
||||
protected void drawToleranceInfo(IAlleleTolerance toleranceAllele, int x) {
|
||||
|
||||
@@ -18,7 +18,7 @@ import forestry.core.network.packets.PacketChipsetClick;
|
||||
import forestry.core.network.packets.PacketErrorUpdate;
|
||||
import forestry.core.network.packets.PacketErrorUpdateEntity;
|
||||
import forestry.core.network.packets.PacketFXSignal;
|
||||
import forestry.core.network.packets.PacketGenomeTrackerUpdate;
|
||||
import forestry.core.network.packets.PacketGenomeTrackerSync;
|
||||
import forestry.core.network.packets.PacketGuiEnergy;
|
||||
import forestry.core.network.packets.PacketGuiLayoutSelect;
|
||||
import forestry.core.network.packets.PacketGuiSelectRequest;
|
||||
@@ -47,7 +47,7 @@ public class PacketRegistryCore extends PacketRegistry {
|
||||
registerClientPacket(new PacketItemStackDisplay());
|
||||
registerClientPacket(new PacketFXSignal());
|
||||
registerClientPacket(new PacketTankLevelUpdate());
|
||||
registerClientPacket(new PacketGenomeTrackerUpdate());
|
||||
registerClientPacket(new PacketGenomeTrackerSync());
|
||||
|
||||
registerServerPacket(new PacketGuiSelectRequest());
|
||||
registerServerPacket(new PacketPipetteClick());
|
||||
|
||||
+3
-3
@@ -27,12 +27,12 @@ import forestry.core.network.IForestryPacketClient;
|
||||
import forestry.core.network.PacketIdClient;
|
||||
import forestry.core.proxy.Proxies;
|
||||
|
||||
public class PacketGenomeTrackerUpdate extends PacketNBT implements IForestryPacketClient {
|
||||
public class PacketGenomeTrackerSync extends PacketNBT implements IForestryPacketClient {
|
||||
|
||||
public PacketGenomeTrackerUpdate() {
|
||||
public PacketGenomeTrackerSync() {
|
||||
}
|
||||
|
||||
public PacketGenomeTrackerUpdate(NBTTagCompound nbtTagCompound) {
|
||||
public PacketGenomeTrackerSync(NBTTagCompound nbtTagCompound) {
|
||||
super(nbtTagCompound);
|
||||
}
|
||||
|
||||
@@ -236,10 +236,13 @@ public class ButterflyHelper extends SpeciesRoot implements IButterflyRoot {
|
||||
|
||||
// Create a tracker if there is none yet.
|
||||
if (tracker == null) {
|
||||
tracker = new LepidopteristTracker(filename, player, world);
|
||||
tracker = new LepidopteristTracker(filename);
|
||||
world.setItemData(filename, tracker);
|
||||
}
|
||||
|
||||
tracker.setUsername(player);
|
||||
tracker.setWorld(world);
|
||||
|
||||
return tracker;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,9 +11,6 @@
|
||||
package forestry.lepidopterology.genetics;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
import forestry.api.genetics.IBreedingTracker;
|
||||
import forestry.api.genetics.IIndividual;
|
||||
@@ -26,11 +23,7 @@ public class LepidopteristTracker extends BreedingTracker implements ILepidopter
|
||||
|
||||
/** Required for creation from map storage */
|
||||
public LepidopteristTracker(String s) {
|
||||
this(s, null, null);
|
||||
}
|
||||
|
||||
public LepidopteristTracker(String s, GameProfile player, World world) {
|
||||
super(s, player, world);
|
||||
super(s);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in new issue
Block a user