Search in sources :

Example 1 with AmadronOfferCustom

use of me.desht.pneumaticcraft.common.recipes.AmadronOfferCustom in project pnc-repressurized by TeamPneumatic.

the class ContainerAmadron method clickOffer.

public void clickOffer(int offerId, int mouseButton, boolean sneaking, EntityPlayer player) {
    problemState = EnumProblemState.NO_PROBLEMS;
    int cartSlot = getCartSlot(offerId);
    if (cartSlot >= 0) {
        if (mouseButton == 2) {
            shoppingAmounts[cartSlot] = 0;
        } else if (sneaking) {
            if (mouseButton == 0)
                shoppingAmounts[cartSlot] /= 2;
            else {
                AmadronOffer offer = offers.get(offerId);
                if (offer instanceof AmadronOfferCustom) {
                    AmadronOfferCustom custom = (AmadronOfferCustom) offer;
                    if (custom.getPlayerId().equals(player.getGameProfile().getId().toString())) {
                        if (AmadronOfferManager.getInstance().removeStaticOffer(custom)) {
                            if (AmadronOfferSettings.notifyOfTradeRemoval)
                                NetworkHandler.sendToAll(new PacketAmadronTradeRemoved(custom));
                            custom.returnStock();
                            try {
                                AmadronOfferStaticConfig.INSTANCE.writeToFile();
                            } catch (IOException e) {
                                e.printStackTrace();
                            }
                            player.closeScreen();
                        }
                    }
                }
                shoppingAmounts[cartSlot] *= 2;
                if (shoppingAmounts[cartSlot] == 0)
                    shoppingAmounts[cartSlot] = 1;
            }
        } else {
            if (mouseButton == 0)
                shoppingAmounts[cartSlot]--;
            else
                shoppingAmounts[cartSlot]++;
        }
        if (shoppingAmounts[cartSlot] <= 0) {
            shoppingAmounts[cartSlot] = 0;
            shoppingItems[cartSlot] = -1;
        } else {
            shoppingAmounts[cartSlot] = capShoppingAmount(offerId, shoppingAmounts[cartSlot], player);
            if (shoppingAmounts[cartSlot] > 0)
                shoppingItems[cartSlot] = offerId;
            else
                shoppingItems[cartSlot] = -1;
        }
    }
}
Also used : AmadronOffer(me.desht.pneumaticcraft.common.recipes.AmadronOffer) IOException(java.io.IOException) AmadronOfferCustom(me.desht.pneumaticcraft.common.recipes.AmadronOfferCustom) PacketAmadronTradeRemoved(me.desht.pneumaticcraft.common.network.PacketAmadronTradeRemoved)

Example 2 with AmadronOfferCustom

use of me.desht.pneumaticcraft.common.recipes.AmadronOfferCustom in project pnc-repressurized by TeamPneumatic.

the class EventHandlerPneumaticCraft method onAmadronSuccess.

@SubscribeEvent
public void onAmadronSuccess(AmadronRetrievalEvent event) {
    EntityDrone drone = (EntityDrone) event.drone;
    AmadronOffer offer = drone.getHandlingOffer();
    boolean shouldDeliver = false;
    if (offer instanceof AmadronOfferCustom) {
        AmadronOffer realOffer = AmadronOfferManager.getInstance().get(offer);
        if (realOffer != null) {
            // If we find the non-inverted offer, that means the Drone just has completed trading with a different player.
            ((AmadronOfferCustom) realOffer).addPayment(drone.getOfferTimes());
            ((AmadronOfferCustom) realOffer).addStock(-drone.getOfferTimes());
            realOffer.onTrade(drone.getOfferTimes(), drone.getBuyingPlayer());
            shouldDeliver = true;
        }
        realOffer = AmadronOfferManager.getInstance().get(((AmadronOfferCustom) offer).copy().invert());
        if (realOffer != null) {
            // If we find the inverted offer, that means the Drone has just restocked.
            ((AmadronOfferCustom) realOffer).addStock(drone.getOfferTimes());
        }
    } else {
        shouldDeliver = true;
    }
    if (shouldDeliver) {
        ItemStack usedTablet = drone.getUsedTablet();
        if (offer.getOutput() instanceof ItemStack) {
            ItemStack offeringItems = (ItemStack) offer.getOutput();
            int producedItems = offeringItems.getCount() * drone.getOfferTimes();
            List<ItemStack> stacks = new ArrayList<ItemStack>();
            while (producedItems > 0) {
                ItemStack stack = offeringItems.copy();
                stack.setCount(Math.min(producedItems, stack.getMaxStackSize()));
                stacks.add(stack);
                producedItems -= stack.getCount();
            }
            BlockPos pos = ItemAmadronTablet.getItemProvidingLocation(usedTablet);
            if (pos != null) {
                World world = DimensionManager.getWorld(ItemAmadronTablet.getItemProvidingDimension(usedTablet));
                DroneRegistry.getInstance().deliverItemsAmazonStyle(world, pos, stacks.toArray(new ItemStack[stacks.size()]));
            }
        } else {
            FluidStack offeringFluid = ((FluidStack) offer.getOutput()).copy();
            offeringFluid.amount *= drone.getOfferTimes();
            BlockPos pos = ItemAmadronTablet.getLiquidProvidingLocation(usedTablet);
            if (pos != null) {
                World world = DimensionManager.getWorld(ItemAmadronTablet.getLiquidProvidingDimension(usedTablet));
                DroneRegistry.getInstance().deliverFluidAmazonStyle(world, pos, offeringFluid);
            }
        }
    }
}
Also used : EntityDrone(me.desht.pneumaticcraft.common.entity.living.EntityDrone) FluidStack(net.minecraftforge.fluids.FluidStack) AmadronOffer(me.desht.pneumaticcraft.common.recipes.AmadronOffer) ArrayList(java.util.ArrayList) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) World(net.minecraft.world.World) AmadronOfferCustom(me.desht.pneumaticcraft.common.recipes.AmadronOfferCustom) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 3 with AmadronOfferCustom

use of me.desht.pneumaticcraft.common.recipes.AmadronOfferCustom in project pnc-repressurized by TeamPneumatic.

the class PacketAmadronTradeAdd method handleServerSide.

@Override
public void handleServerSide(PacketAmadronTradeAdd message, EntityPlayer player) {
    AmadronOfferCustom offer = message.getOffer();
    offer.updatePlayerId();
    if (AmadronOfferManager.getInstance().hasOffer(offer.copy().invert())) {
        player.sendStatusMessage(new TextComponentTranslation("message.amadron.duplicateReversedOffer"), false);
    } else if (AmadronOfferManager.getInstance().addStaticOffer(offer)) {
        if (AmadronOfferSettings.notifyOfTradeAddition)
            NetworkHandler.sendToAll(message);
        try {
            AmadronOfferStaticConfig.INSTANCE.writeToFile();
        } catch (IOException e) {
            e.printStackTrace();
        }
    } else {
        player.sendStatusMessage(new TextComponentTranslation("message.amadron.duplicateOffer"), false);
    }
}
Also used : TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) IOException(java.io.IOException) AmadronOfferCustom(me.desht.pneumaticcraft.common.recipes.AmadronOfferCustom)

Example 4 with AmadronOfferCustom

use of me.desht.pneumaticcraft.common.recipes.AmadronOfferCustom in project pnc-repressurized by TeamPneumatic.

the class GuiAmadronAddTrade method actionPerformed.

@Override
public void actionPerformed(GuiButton button) {
    EntityPlayer player = FMLClientHandler.instance().getClient().player;
    ContainerAmadronAddTrade container = (ContainerAmadronAddTrade) inventorySlots;
    if (button.id < 6 && button.id >= 0) {
        isSettingInput = button.id < 3;
        if (button.id % 3 == 0) {
            searchGui = new GuiSearcher(player);
            searchGui.setSearchStack(container.getStack(isSettingInput ? 0 : 1));
            FMLClientHandler.instance().showGuiScreen(searchGui);
        } else if (button.id % 3 == 1) {
            invSearchGui = new GuiInventorySearcher(player);
            invSearchGui.setSearchStack(container.getStack(isSettingInput ? 0 : 1));
            FMLClientHandler.instance().showGuiScreen(invSearchGui);
        } else if (button.id % 3 == 2) {
            fluidGui = new GuiLogisticsLiquidFilter(this);
            fluidGui.setFilter(isSettingInput ? inputFluid.getFluid() : outputFluid.getFluid());
            FMLClientHandler.instance().showGuiScreen(fluidGui);
        }
    } else if (button.id == 8) {
        Object input;
        if (!container.getStack(0).isEmpty()) {
            input = container.getStack(0).copy();
            ((ItemStack) input).setCount(inputNumber.getValue());
        } else {
            input = new FluidStack(inputFluid.getFluid(), inputNumber.getValue());
        }
        Object output;
        if (!container.getStack(1).isEmpty()) {
            output = container.getStack(1).copy();
            ((ItemStack) output).setCount(outputNumber.getValue());
        } else {
            output = new FluidStack(outputFluid.getFluid(), outputNumber.getValue());
        }
        AmadronOfferCustom trade = new AmadronOfferCustom(input, output, player);
        BlockPos pos = getInputPosition();
        int dimensionId = getInputDimension();
        trade.setProvidingPosition(pos, dimensionId);
        pos = getOutputPosition();
        dimensionId = getOutputDimension();
        trade.setReturningPosition(pos, dimensionId);
        NetworkHandler.sendToServer(new PacketAmadronTradeAdd(trade.invert()));
        player.closeScreen();
    }
    super.actionPerformed(button);
}
Also used : ContainerAmadronAddTrade(me.desht.pneumaticcraft.common.inventory.ContainerAmadronAddTrade) FluidStack(net.minecraftforge.fluids.FluidStack) EntityPlayer(net.minecraft.entity.player.EntityPlayer) PacketAmadronTradeAdd(me.desht.pneumaticcraft.common.network.PacketAmadronTradeAdd) GuiLogisticsLiquidFilter(me.desht.pneumaticcraft.client.gui.semiblock.GuiLogisticsLiquidFilter) BlockPos(net.minecraft.util.math.BlockPos) AmadronOfferCustom(me.desht.pneumaticcraft.common.recipes.AmadronOfferCustom)

Example 5 with AmadronOfferCustom

use of me.desht.pneumaticcraft.common.recipes.AmadronOfferCustom in project pnc-repressurized by TeamPneumatic.

the class EntityDrone method writeEntityToNBT.

@Override
public void writeEntityToNBT(NBTTagCompound tag) {
    super.writeEntityToNBT(tag);
    TileEntityProgrammer.setWidgetsToNBT(progWidgets, tag);
    tag.setBoolean("naturallySpawned", naturallySpawned);
    tag.setFloat("currentAir", currentAir);
    tag.setFloat("propSpeed", propSpeed);
    tag.setBoolean("disabledByHacking", disabledByHacking);
    tag.setBoolean("hackedByOwner", gotoOwnerAI != null);
    tag.setInteger("color", getDroneColor());
    tag.setBoolean("standby", standby);
    tag.setFloat("volume", volume);
    NBTTagCompound variableTag = new NBTTagCompound();
    aiManager.writeToNBT(variableTag);
    tag.setTag("variables", variableTag);
    tag.setTag("Inventory", inventory.serializeNBT());
    tag.setTag(ChargeableItemHandler.NBT_UPGRADE_TAG, upgradeInventory.serializeNBT());
    tank.writeToNBT(tag);
    if (handlingOffer != null) {
        NBTTagCompound subTag = new NBTTagCompound();
        subTag.setBoolean("isCustom", handlingOffer instanceof AmadronOfferCustom);
        handlingOffer.writeToNBT(subTag);
        tag.setTag("amadronOffer", subTag);
        tag.setInteger("offerTimes", offerTimes);
        if (usedTablet != null)
            usedTablet.writeToNBT(subTag);
        tag.setString("buyingPlayer", buyingPlayer);
    }
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) AmadronOfferCustom(me.desht.pneumaticcraft.common.recipes.AmadronOfferCustom)

Aggregations

AmadronOfferCustom (me.desht.pneumaticcraft.common.recipes.AmadronOfferCustom)7 AmadronOffer (me.desht.pneumaticcraft.common.recipes.AmadronOffer)3 IOException (java.io.IOException)2 BlockPos (net.minecraft.util.math.BlockPos)2 FluidStack (net.minecraftforge.fluids.FluidStack)2 ArrayList (java.util.ArrayList)1 GuiLogisticsLiquidFilter (me.desht.pneumaticcraft.client.gui.semiblock.GuiLogisticsLiquidFilter)1 EntityDrone (me.desht.pneumaticcraft.common.entity.living.EntityDrone)1 ContainerAmadronAddTrade (me.desht.pneumaticcraft.common.inventory.ContainerAmadronAddTrade)1 PacketAmadronTradeAdd (me.desht.pneumaticcraft.common.network.PacketAmadronTradeAdd)1 PacketAmadronTradeRemoved (me.desht.pneumaticcraft.common.network.PacketAmadronTradeRemoved)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 ItemStack (net.minecraft.item.ItemStack)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)1 World (net.minecraft.world.World)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1