Search in sources :

Example 1 with IMailAddress

use of forestry.api.mail.IMailAddress in project ForestryMC by ForestryMC.

the class ContainerCatalogue method rebuildStationsList.

private void rebuildStationsList() {
    stations.clear();
    IPostOffice postOffice = PostManager.postRegistry.getPostOffice(player.world);
    Map<IMailAddress, ITradeStation> tradeStations = postOffice.getActiveTradeStations(player.world);
    for (ITradeStation station : tradeStations.values()) {
        ITradeStationInfo info = station.getTradeInfo();
        // Filter out any trade stations which do not actually offer anything.
        if (FILTERS.get(currentFilter).contains(info.getState())) {
            stations.add(station);
        }
    }
    stationIndex = 0;
    updateTradeInfo();
}
Also used : ITradeStation(forestry.api.mail.ITradeStation) IMailAddress(forestry.api.mail.IMailAddress) IPostOffice(forestry.api.mail.IPostOffice) ITradeStationInfo(forestry.api.mail.ITradeStationInfo)

Example 2 with IMailAddress

use of forestry.api.mail.IMailAddress in project ForestryMC by ForestryMC.

the class ContainerLetter method handleRequestLetterInfo.

public void handleRequestLetterInfo(EntityPlayer player, String recipientName, EnumAddressee type) {
    MinecraftServer server = player.getServer();
    if (server == null) {
        Log.error("Could not get server");
        return;
    }
    IMailAddress recipient = getRecipient(server, recipientName, type);
    getLetter().setRecipient(recipient);
    // Update the trading info
    if (recipient == null || recipient.getType() == EnumAddressee.TRADER) {
        updateTradeInfo(player.world, recipient);
    }
    // Update info on client
    NetworkUtil.sendToPlayer(new PacketLetterInfoResponse(type, tradeInfo, recipient), player);
}
Also used : IMailAddress(forestry.api.mail.IMailAddress) PacketLetterInfoResponse(forestry.mail.network.packets.PacketLetterInfoResponse) MinecraftServer(net.minecraft.server.MinecraftServer)

Example 3 with IMailAddress

use of forestry.api.mail.IMailAddress in project ForestryMC by ForestryMC.

the class EventHandlerMailAlert method handlePlayerLoggedIn.

@SubscribeEvent
public void handlePlayerLoggedIn(PlayerEvent.PlayerLoggedInEvent event) {
    EntityPlayer player = event.player;
    IMailAddress address = PostManager.postRegistry.getMailAddress(player.getGameProfile());
    POBox pobox = PostRegistry.getOrCreatePOBox(player.world, address);
    PacketPOBoxInfoResponse packet = new PacketPOBoxInfoResponse(pobox.getPOBoxInfo());
    NetworkUtil.sendToPlayer(packet, player);
}
Also used : IMailAddress(forestry.api.mail.IMailAddress) PacketPOBoxInfoResponse(forestry.mail.network.packets.PacketPOBoxInfoResponse) EntityPlayer(net.minecraft.entity.player.EntityPlayer) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 4 with IMailAddress

use of forestry.api.mail.IMailAddress in project ForestryMC by ForestryMC.

the class PostOffice method lodgeLetter.

// / DELIVERY
@Override
public IPostalState lodgeLetter(World world, ItemStack itemstack, boolean doLodge) {
    ILetter letter = PostManager.postRegistry.getLetter(itemstack);
    if (letter == null) {
        return EnumDeliveryState.NOT_MAILABLE;
    }
    if (letter.isProcessed()) {
        return EnumDeliveryState.ALREADY_MAILED;
    }
    if (!letter.isPostPaid()) {
        return EnumDeliveryState.NOT_POSTPAID;
    }
    if (!letter.isMailable()) {
        return EnumDeliveryState.NOT_MAILABLE;
    }
    IPostalState state = EnumDeliveryState.NOT_MAILABLE;
    IMailAddress address = letter.getRecipient();
    if (address != null) {
        IPostalCarrier carrier = PostManager.postRegistry.getCarrier(address.getType());
        if (carrier != null) {
            state = carrier.deliverLetter(world, this, address, itemstack, doLodge);
        }
    }
    if (!state.isOk()) {
        return state;
    }
    collectPostage(letter.getPostage());
    markDirty();
    return EnumDeliveryState.OK;
}
Also used : IPostalState(forestry.api.mail.IPostalState) IMailAddress(forestry.api.mail.IMailAddress) ILetter(forestry.api.mail.ILetter) IPostalCarrier(forestry.api.mail.IPostalCarrier)

Example 5 with IMailAddress

use of forestry.api.mail.IMailAddress in project ForestryMC by ForestryMC.

the class TradeStation method handleLetter.

/* ILETTERHANDLER */
@Override
public IPostalState handleLetter(World world, IMailAddress recipient, ItemStack letterstack, boolean doLodge) {
    boolean sendOwnerNotice = doLodge && owner != null;
    ILetter letter = PostManager.postRegistry.getLetter(letterstack);
    if (!isVirtual() && !hasPaper(sendOwnerNotice ? 2 : 1)) {
        return EnumTradeStationState.INSUFFICIENT_PAPER;
    }
    int ordersToFillCount = ItemStackUtil.containsSets(InventoryUtil.getStacks(inventory, SLOT_EXCHANGE_1, SLOT_EXCHANGE_COUNT), letter.getAttachments());
    // Not a single match.
    if (ordersToFillCount <= 0) {
        return EnumTradeStationState.INSUFFICIENT_OFFER;
    }
    if (!isVirtual()) {
        int fillable = countFillableOrders(ordersToFillCount, inventory.getStackInSlot(SLOT_TRADEGOOD));
        // Nothing can be filled.
        if (fillable <= 0) {
            return EnumTradeStationState.INSUFFICIENT_TRADE_GOOD;
        }
        if (fillable < ordersToFillCount) {
            ordersToFillCount = fillable;
        }
        // Check for sufficient output buffer
        int storable = countStorablePayment(ordersToFillCount, InventoryUtil.getStacks(inventory, SLOT_EXCHANGE_1, SLOT_EXCHANGE_COUNT));
        if (storable <= 0) {
            return EnumTradeStationState.INSUFFICIENT_BUFFER;
        }
        if (storable < ordersToFillCount) {
            ordersToFillCount = storable;
        }
    }
    // Prepare the letter
    ILetter mail = new Letter(this.address, letter.getSender());
    mail.setText(Translator.translateToLocal("for.gui.mail.order.attached"));
    for (int i = 0; i < ordersToFillCount; i++) {
        mail.addAttachment(inventory.getStackInSlot(SLOT_TRADEGOOD).copy());
    }
    mail.addAttachments(getSurplusAttachments(ordersToFillCount, letter.getAttachments()));
    // Check for necessary postage
    int requiredPostage = mail.requiredPostage();
    if (!isVirtual()) {
        if (!canPayPostage(requiredPostage + (sendOwnerNotice ? 1 : 0))) {
            return EnumTradeStationState.INSUFFICIENT_STAMPS;
        }
    }
    // Attach necessary postage
    int[] stampCount = getPostage(requiredPostage, isVirtual());
    for (int i = 0; i < stampCount.length; i++) {
        int count = stampCount[i];
        if (count > 0) {
            EnumPostage postage = EnumPostage.values()[i];
            EnumStampDefinition stampDefinition = EnumStampDefinition.getFromPostage(postage);
            mail.addStamps(ModuleMail.getItems().stamps.get(stampDefinition, count));
        }
    }
    // Send the letter
    NBTTagCompound nbttagcompound = new NBTTagCompound();
    mail.writeToNBT(nbttagcompound);
    ItemStack mailstack = LetterProperties.createStampedLetterStack(mail);
    mailstack.setTagCompound(nbttagcompound);
    IPostalState responseState = PostManager.postRegistry.getPostOffice(world).lodgeLetter(world, mailstack, doLodge);
    if (!responseState.isOk()) {
        return new ResponseNotMailable(responseState);
    }
    // Store received items
    for (int i = 0; i < ordersToFillCount; i++) {
        for (ItemStack stack : InventoryUtil.getStacks(inventory, SLOT_EXCHANGE_1, SLOT_EXCHANGE_COUNT)) {
            if (stack == null) {
                continue;
            }
            InventoryUtil.tryAddStack(inventory, stack.copy(), SLOT_RECEIVE_BUFFER, SLOT_RECEIVE_BUFFER_COUNT, false);
        }
    }
    // Remove resources
    removePaper();
    removeStamps(stampCount);
    removeTradegood(ordersToFillCount);
    // Send confirmation message to seller
    if (sendOwnerNotice) {
        nbttagcompound = new NBTTagCompound();
        ILetter confirm = new Letter(this.address, new MailAddress(this.owner));
        String orderFilledMessage;
        if (ordersToFillCount == 1) {
            orderFilledMessage = Translator.translateToLocal("for.gui.mail.order.filled.one");
        } else {
            orderFilledMessage = Translator.translateToLocal("for.gui.mail.order.filled.multiple");
            orderFilledMessage = orderFilledMessage.replace("%COUNT", Integer.toString(ordersToFillCount));
        }
        orderFilledMessage = orderFilledMessage.replace("%SENDER", letter.getSender().getName());
        confirm.setText(orderFilledMessage);
        confirm.addStamps(ModuleMail.getItems().stamps.get(EnumStampDefinition.P_1, 1));
        confirm.writeToNBT(nbttagcompound);
        ItemStack confirmstack = LetterProperties.createStampedLetterStack(confirm);
        confirmstack.setTagCompound(nbttagcompound);
        PostManager.postRegistry.getPostOffice(world).lodgeLetter(world, confirmstack, doLodge);
        removePaper();
        removeStamps(new int[] { 0, 1 });
    }
    markDirty();
    return EnumDeliveryState.OK;
}
Also used : IMailAddress(forestry.api.mail.IMailAddress) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ILetter(forestry.api.mail.ILetter) IPostalState(forestry.api.mail.IPostalState) ILetter(forestry.api.mail.ILetter) EnumStampDefinition(forestry.mail.items.EnumStampDefinition) ItemStack(net.minecraft.item.ItemStack) EnumPostage(forestry.api.mail.EnumPostage)

Aggregations

IMailAddress (forestry.api.mail.IMailAddress)9 ILetter (forestry.api.mail.ILetter)3 IPostalState (forestry.api.mail.IPostalState)2 EnumPostage (forestry.api.mail.EnumPostage)1 IPostOffice (forestry.api.mail.IPostOffice)1 IPostalCarrier (forestry.api.mail.IPostalCarrier)1 ITradeStation (forestry.api.mail.ITradeStation)1 ITradeStationInfo (forestry.api.mail.ITradeStationInfo)1 GuiTextBox (forestry.core.gui.GuiTextBox)1 EnumStampDefinition (forestry.mail.items.EnumStampDefinition)1 PacketLetterInfoResponse (forestry.mail.network.packets.PacketLetterInfoResponse)1 PacketPOBoxInfoResponse (forestry.mail.network.packets.PacketPOBoxInfoResponse)1 PacketTraderAddressResponse (forestry.mail.network.packets.PacketTraderAddressResponse)1 GuiTextField (net.minecraft.client.gui.GuiTextField)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 ItemStack (net.minecraft.item.ItemStack)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 MinecraftServer (net.minecraft.server.MinecraftServer)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)1