use of team.cqr.cqrepoured.inventory.ContainerMerchant in project ChocolateQuestRepoured by TeamChocoQuest.
the class CPacketHandlerSyncTrades method execHandlePacket.
@Override
protected void execHandlePacket(SPacketSyncTrades message, Supplier<Context> context, World world, PlayerEntity player) {
Entity entity = world.getEntity(message.getEntityId());
if (entity instanceof AbstractEntityCQR) {
TraderOffer trades = ((AbstractEntityCQR) entity).getTrades();
trades.readFromNBT(message.getTrades());
if (player.containerMenu instanceof ContainerMerchant) {
((ContainerMerchant) player.containerMenu).onTradesUpdated();
}
CQRMain.PROXY.updateGui();
}
}
use of team.cqr.cqrepoured.inventory.ContainerMerchant in project ChocolateQuestRepoured by TeamChocoQuest.
the class GuiMerchant method actionPerformed.
protected void actionPerformed(Button button) {
if (button instanceof GuiButtonTrade) {
((ContainerMerchant) this.menu).setCurrentTradeIndex(((GuiButtonTrade) button).getIndex());
((ContainerMerchant) this.menu).updateInputsForTrade(((GuiButtonTrade) button).getIndex());
}
if (button == addNewTradeButton) {
CQRMain.NETWORK.sendToServer(new CPacketContainerClickButton(0));
} else if (button instanceof INumericIDButton) {
INumericIDButton inib = (INumericIDButton) button;
int index = this.buttonStartIndex + (inib.getId() % 10);
CQRMain.NETWORK.sendToServer(new CPacketContainerClickButton(inib.getId(), buf -> buf.writeInt(index)));
}
}
use of team.cqr.cqrepoured.inventory.ContainerMerchant in project ChocolateQuestRepoured by TeamChocoQuest.
the class TraderOffer method onTradesUpdated.
public void onTradesUpdated() {
if (!this.entity.level.isClientSide) {
this.entity.level.players().stream().map(p -> p.containerMenu).filter(Objects::nonNull).filter(ContainerMerchant.class::isInstance).map(ContainerMerchant.class::cast).filter(c -> c.getMerchant() == this.entity).forEach(c -> c.onTradesUpdated());
CQRMain.NETWORK.send(PacketDistributor.TRACKING_ENTITY.with(() -> this.entity), new SPacketSyncTrades(this.entity));
} else {
Container c = Minecraft.getInstance().player.containerMenu;
if (c instanceof ContainerMerchant) {
((ContainerMerchant) c).onTradesUpdated();
}
}
}
Aggregations