Skip to content

Commit

Permalink
Fix some remaining sync and GUI bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
62832 committed May 5, 2024
1 parent 3476b56 commit 37799cc
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ private void learnAll(boolean learned) {

if (!learned) {
AppliedE.PACKET_HANDLER.sendToServer(new LearnAllItemsPacket());
menu.learnedLabelTicks = 300;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,16 @@ public void handle(Supplier<NetworkEvent.Context> context) {
return;
}

storage.getInventory().extract(item, 1, Actionable.MODULATE, IActionSource.ofMachine(host));
emcStorage.insertItem(item, 1, Actionable.MODULATE, IActionSource.ofPlayer(sender), true);
var learned = emcStorage.learnNewItem(item, sender);
var meStorage = storage.getInventory();
meStorage.extract(item, learned, Actionable.MODULATE, IActionSource.ofMachine(host));

if (learned > 0) {
menu.showLearned();
}
});
}
});
context.get().setPacketHandled(true);
}
}
22 changes: 19 additions & 3 deletions src/main/java/gripe/_90/appliede/me/service/EMCStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.google.common.primitives.Ints;

import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerPlayer;

import appeng.api.config.Actionable;
import appeng.api.config.PowerMultiplier;
Expand All @@ -21,6 +22,7 @@
import gripe._90.appliede.AppliedE;
import gripe._90.appliede.me.key.EMCKey;

import moze_intel.projecte.api.ItemInfo;
import moze_intel.projecte.api.proxy.IEMCProxy;

public class EMCStorage implements MEStorage {
Expand Down Expand Up @@ -70,7 +72,7 @@ public long insert(AEKey what, long amount, Actionable mode, IActionSource sourc
provider.setEmc(provider.getEmc().add(quotient.add(p < remainder ? BigInteger.ONE : BigInteger.ZERO)));
}

service.sync();
service.syncEmc();
}

return amount;
Expand Down Expand Up @@ -128,7 +130,7 @@ public long extract(AEKey what, long amount, Actionable mode, IActionSource sour
}

if (mode == Actionable.MODULATE) {
service.sync();
service.syncEmc();
}

return extracted;
Expand Down Expand Up @@ -183,7 +185,15 @@ public long insertItem(AEItemKey what, long amount, Actionable mode, IActionSour
}

if (mode == Actionable.MODULATE && mayLearn) {
service.getProviders().forEach(provider -> provider.addKnowledge(what.toStack()));
service.getProviders().forEach(provider -> {
var stack = what.toStack();
provider.addKnowledge(stack);
playerSource.ifPresent(player -> {
if (player instanceof ServerPlayer serverPlayer) {
provider.syncKnowledgeChange(serverPlayer, ItemInfo.fromStack(stack), true);
}
});
});
}

return totalInserted;
Expand Down Expand Up @@ -232,6 +242,12 @@ public long extractItem(AEItemKey what, long amount, Actionable mode, IActionSou
return totalExtracted;
}

public long learnNewItem(AEItemKey what, ServerPlayer player) {
return !service.knowsItem(what)
? insertItem(what, 1, Actionable.MODULATE, IActionSource.ofPlayer(player), true)
: 0;
}

private long getAmountAfterPowerExpenditure(long maxAmount, IEnergySource source) {
var requiredPower = PowerMultiplier.CONFIG.multiply(maxAmount);
var availablePower = source.extractAEPower(requiredPower, Actionable.SIMULATE, PowerMultiplier.CONFIG);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,13 @@ public boolean isTrackingPlayer(UUID uuid) {
return providers.containsKey(uuid) || tpeHandler.isPlayerInTrackedTeam(uuid);
}

void sync() {
void syncEmc() {
if (server != null) {
providers.forEach((uuid, provider) -> {
var id = IPlayerRegistry.getMapping(server).getPlayerId(uuid);
var player = IPlayerRegistry.getConnected(server, id);

if (player != null) {
provider.get().sync(player);
provider.get().syncEmc(player);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ protected long transmuteItem(ItemStack stack, boolean singleItem, ServerPlayer p
var key = AEItemKey.of(stack);

if (!knowledge.knowsItem(key)) {
learnedLabelTicks = 300;
showLearned();
}

var emcStorage = knowledge.getStorage();
Expand All @@ -98,6 +98,11 @@ public void setShiftToTransmute(boolean transmute) {
shiftToTransmute = transmute;
}

public void showLearned() {
learnedLabelTicks = 300;
sendAllDataToRemote();
}

@Override
public ItemStack quickMoveStack(Player player, int idx) {
if (player instanceof ServerPlayer serverPlayer && shiftToTransmute) {
Expand Down

0 comments on commit 37799cc

Please sign in to comment.