mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-12 02:37:27 +00:00
Balance Prediction Client Side Trader
This commit is contained in:
1 parent
db7ae16ee9
commit
b719856762
1 file changed
+17
@@ -3,6 +3,7 @@ package noppes.npcs.client.gui.player;
|
||||
import kamkeel.npcs.network.PacketClient;
|
||||
import kamkeel.npcs.network.packets.player.GetTraderData;
|
||||
import net.minecraft.client.renderer.RenderHelper;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
@@ -332,6 +333,22 @@ public class GuiNPCTrader extends GuiContainerNPCInterface implements IGuiData {
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleMouseClick(Slot slot, int slotId, int mouseButton, int modifier) {
|
||||
// Client-side balance prediction: immediately subtract currency cost on click
|
||||
// so the displayed balance updates instantly without waiting for server response.
|
||||
if (slotId >= 0 && slotId < 18 && mouseButton == 0) {
|
||||
long cost = currencyCost[slotId];
|
||||
if (cost > 0 && playerBalance >= cost) {
|
||||
ItemStack sold = role.inventorySold.items.get(slotId);
|
||||
if (sold != null && container.canBuy(slotId, player)) {
|
||||
playerBalance -= cost;
|
||||
}
|
||||
}
|
||||
}
|
||||
super.handleMouseClick(slot, slotId, mouseButton, modifier);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save() {
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user