Search in sources :

Example 1 with ContainerMerchant

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();
    }
}
Also used : Entity(net.minecraft.entity.Entity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) TraderOffer(team.cqr.cqrepoured.entity.trade.TraderOffer) ContainerMerchant(team.cqr.cqrepoured.inventory.ContainerMerchant) AbstractEntityCQR(team.cqr.cqrepoured.entity.bases.AbstractEntityCQR)

Example 2 with ContainerMerchant

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)));
    }
}
Also used : CPacketContainerClickButton(team.cqr.cqrepoured.network.client.packet.CPacketContainerClickButton) INumericIDButton(team.cqr.cqrepoured.client.gui.INumericIDButton) ContainerMerchant(team.cqr.cqrepoured.inventory.ContainerMerchant)

Example 3 with ContainerMerchant

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();
        }
    }
}
Also used : ListNBT(net.minecraft.nbt.ListNBT) AbstractEntityCQR(team.cqr.cqrepoured.entity.bases.AbstractEntityCQR) Container(net.minecraft.inventory.container.Container) Constants(net.minecraftforge.common.util.Constants) CompoundNBT(net.minecraft.nbt.CompoundNBT) ContainerMerchant(team.cqr.cqrepoured.inventory.ContainerMerchant) Faction(team.cqr.cqrepoured.faction.Faction) ArrayList(java.util.ArrayList) Objects(java.util.Objects) PacketDistributor(net.minecraftforge.fml.network.PacketDistributor) List(java.util.List) Minecraft(net.minecraft.client.Minecraft) SPacketSyncTrades(team.cqr.cqrepoured.network.server.packet.SPacketSyncTrades) CQRMain(team.cqr.cqrepoured.CQRMain) Collections(java.util.Collections) INBT(net.minecraft.nbt.INBT) Container(net.minecraft.inventory.container.Container) Objects(java.util.Objects) ContainerMerchant(team.cqr.cqrepoured.inventory.ContainerMerchant) SPacketSyncTrades(team.cqr.cqrepoured.network.server.packet.SPacketSyncTrades)

Aggregations

ContainerMerchant (team.cqr.cqrepoured.inventory.ContainerMerchant)3 AbstractEntityCQR (team.cqr.cqrepoured.entity.bases.AbstractEntityCQR)2 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 List (java.util.List)1 Objects (java.util.Objects)1 Minecraft (net.minecraft.client.Minecraft)1 Entity (net.minecraft.entity.Entity)1 PlayerEntity (net.minecraft.entity.player.PlayerEntity)1 Container (net.minecraft.inventory.container.Container)1 CompoundNBT (net.minecraft.nbt.CompoundNBT)1 INBT (net.minecraft.nbt.INBT)1 ListNBT (net.minecraft.nbt.ListNBT)1 Constants (net.minecraftforge.common.util.Constants)1 PacketDistributor (net.minecraftforge.fml.network.PacketDistributor)1 CQRMain (team.cqr.cqrepoured.CQRMain)1 INumericIDButton (team.cqr.cqrepoured.client.gui.INumericIDButton)1 TraderOffer (team.cqr.cqrepoured.entity.trade.TraderOffer)1 Faction (team.cqr.cqrepoured.faction.Faction)1 CPacketContainerClickButton (team.cqr.cqrepoured.network.client.packet.CPacketContainerClickButton)1