Skip to content

Commit

Permalink
Don't sync emc and knowledge automatically
Browse files Browse the repository at this point in the history
Release 1.1.4
  • Loading branch information
yzl210 committed Jun 6, 2024
1 parent 6f00b19 commit a98c2be
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 32 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ plugins {
}

group = 'cn.leomc'
version = '1.1.3'
version = '1.1.4'

java {
archivesBaseName = "teamprojecte-${mc_version}"
Expand Down
47 changes: 16 additions & 31 deletions src/main/java/cn/leomc/teamprojecte/TeamKnowledgeProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import moze_intel.projecte.emc.nbt.NBTManager;
import moze_intel.projecte.gameObjs.items.Tome;
import moze_intel.projecte.network.PacketHandler;
import moze_intel.projecte.network.packets.IPEPacket;
import moze_intel.projecte.network.packets.to_client.knowledge.KnowledgeSyncChangePKT;
import moze_intel.projecte.network.packets.to_client.knowledge.KnowledgeSyncEmcPKT;
import moze_intel.projecte.network.packets.to_client.knowledge.KnowledgeSyncInputsAndLocksPKT;
Expand All @@ -20,7 +21,6 @@
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.items.IItemHandlerModifiable;
import net.minecraftforge.items.ItemStackHandler;
import net.minecraftforge.server.ServerLifecycleHooks;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -62,7 +62,6 @@ public void setFullKnowledge(boolean fullKnowledge) {
getTeam().setFullKnowledge(fullKnowledge, playerUUID.get());
if (changed) {
fireChangedEvent();
//sync(playerUUID);
}
}

Expand All @@ -74,7 +73,6 @@ public void clearKnowledge() {
if (hasKnowledge) {
//If we previously had any knowledge fire the fact that our knowledge changed
fireChangedEvent();
//sync(playerUUID);
}
}

Expand Down Expand Up @@ -128,7 +126,6 @@ public boolean addKnowledge(@NotNull ItemInfo info) {
getTeam().addKnowledge(info, playerUUID.get());
getTeam().setFullKnowledge(true, playerUUID.get());
fireChangedEvent();
sync(playerUUID.get());
return true;
}
return tryAdd(NBTManager.getPersistentInfo(info));
Expand All @@ -137,7 +134,6 @@ public boolean addKnowledge(@NotNull ItemInfo info) {
private boolean tryAdd(@NotNull ItemInfo cleanedInfo) {
if (getTeam().addKnowledge(cleanedInfo, playerUUID.get())) {
fireChangedEvent();
//syncKnowledgeChange(playerUUID, cleanedInfo, true);
return true;
}
return false;
Expand All @@ -155,7 +151,6 @@ public boolean removeKnowledge(@NotNull ItemInfo info) {
getTeam().removeKnowledge(info, playerUUID.get());
getTeam().setFullKnowledge(false, playerUUID.get());
fireChangedEvent();
//sync(playerUUID);
return true;
}
//Otherwise check if we have any persistent information, and if so try removing that
Expand All @@ -169,7 +164,6 @@ public boolean removeKnowledge(@NotNull ItemInfo info) {
private boolean tryRemove(@NotNull ItemInfo cleanedInfo) {
if (getTeam().removeKnowledge(cleanedInfo, playerUUID.get())) {
fireChangedEvent();
//syncKnowledgeChange(playerUUID, cleanedInfo, false);
return true;
}
return false;
Expand Down Expand Up @@ -201,22 +195,20 @@ public BigInteger getEmc() {
@Override
public void setEmc(BigInteger emc) {
getTeam().setEmc(emc, playerUUID.get());
syncEmc(playerUUID.get());
}

@Override
public void sync(@NotNull ServerPlayer player) {
sync(TeamProjectE.getPlayerUUID(player));
}

public void sync(UUID uuid) {
if (!getTeam().isSharingEMC() && !getTeam().isSharingKnowledge())
Optional.ofNullable(ServerLifecycleHooks.getCurrentServer().getPlayerList().getPlayer(uuid))
.ifPresent(p -> PacketHandler.sendTo(new KnowledgeSyncPKT(serializeForClient()), p));
sendKnowledgeSync(player);
else
TeamProjectE.getOnlineTeamMembers(uuid)
.forEach(p -> p.getCapability(PECapabilities.KNOWLEDGE_CAPABILITY)
.ifPresent(cap -> PacketHandler.sendTo(new KnowledgeSyncPKT(((TeamKnowledgeProvider) cap).serializeForClient()), p)));
TeamProjectE.getOnlineTeamMembers(TeamProjectE.getPlayerUUID(player))
.forEach(TeamKnowledgeProvider::sendKnowledgeSync);
}

private static void sendKnowledgeSync(ServerPlayer player) {
player.getCapability(PECapabilities.KNOWLEDGE_CAPABILITY)
.ifPresent(cap -> PacketHandler.sendTo(new KnowledgeSyncPKT(((TeamKnowledgeProvider) cap).serializeForClient()), player));
}

private CompoundTag serializeForClient() {
Expand All @@ -235,28 +227,21 @@ private CompoundTag serializeForClient() {

@Override
public void syncEmc(@NotNull ServerPlayer player) {
syncEmc(TeamProjectE.getPlayerUUID(player));
sendPacket(new KnowledgeSyncEmcPKT(getEmc()), player, getTeam().isSharingEMC());
}

public void syncEmc(UUID uuid) {
if (getTeam().isSharingEMC())
TeamProjectE.getOnlineTeamMembers(uuid).forEach(p -> PacketHandler.sendTo(new KnowledgeSyncEmcPKT(getEmc()), p));
else
Optional.ofNullable(ServerLifecycleHooks.getCurrentServer().getPlayerList().getPlayer(uuid))
.ifPresent(p -> PacketHandler.sendTo(new KnowledgeSyncEmcPKT(getEmc()), p));
}

@Override
public void syncKnowledgeChange(@NotNull ServerPlayer player, ItemInfo change, boolean learned) {
syncKnowledgeChange(TeamProjectE.getPlayerUUID(player), change, learned);
sendPacket(new KnowledgeSyncChangePKT(change, learned), player, getTeam().isSharingKnowledge());
}

public void syncKnowledgeChange(UUID uuid, ItemInfo change, boolean learned) {
if (getTeam().isSharingKnowledge())
TeamProjectE.getOnlineTeamMembers(uuid).forEach(p -> PacketHandler.sendTo(new KnowledgeSyncChangePKT(change, learned), p));
private static void sendPacket(IPEPacket packet, ServerPlayer player, boolean team) {
if (team)
TeamProjectE.getOnlineTeamMembers(TeamProjectE.getPlayerUUID(player))
.forEach(p -> PacketHandler.sendTo(packet, p));
else
Optional.ofNullable(ServerLifecycleHooks.getCurrentServer().getPlayerList().getPlayer(uuid))
.ifPresent(p -> PacketHandler.sendTo(new KnowledgeSyncChangePKT(change, learned), p));
PacketHandler.sendTo(packet, player);
}

@Override
Expand Down

0 comments on commit a98c2be

Please sign in to comment.