Search in sources :

Example 1 with AmadronOffer

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

the class ItemAmadronTablet method setShoppingCart.

public static void setShoppingCart(ItemStack tablet, Map<AmadronOffer, Integer> cart) {
    NBTTagList list = new NBTTagList();
    for (Map.Entry<AmadronOffer, Integer> entry : cart.entrySet()) {
        NBTTagCompound tag = new NBTTagCompound();
        entry.getKey().writeToNBT(tag);
        tag.setInteger("amount", entry.getValue());
        list.appendTag(tag);
    }
    NBTUtil.setCompoundTag(tablet, "shoppingCart", list);
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) AmadronOffer(me.desht.pneumaticcraft.common.recipes.AmadronOffer) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with AmadronOffer

use of me.desht.pneumaticcraft.common.recipes.AmadronOffer 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 3 with AmadronOffer

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

the class ContainerAmadron method handleGUIButtonPress.

@Override
public void handleGUIButtonPress(int guiID, EntityPlayer player) {
    super.handleGUIButtonPress(guiID, player);
    if (guiID == 1) {
        for (int i = 0; i < shoppingItems.length; i++) {
            if (shoppingItems[i] >= 0) {
                AmadronOffer offer = offers.get(shoppingItems[i]);
                BlockPos itemPos = ItemAmadronTablet.getItemProvidingLocation(player.getHeldItemMainhand());
                World itemWorld;
                if (itemPos == null) {
                    itemPos = new BlockPos((int) player.posX, (int) player.posY, (int) player.posZ);
                    itemWorld = player.world;
                } else {
                    itemWorld = DimensionManager.getWorld(ItemAmadronTablet.getItemProvidingDimension(player.getHeldItemMainhand()));
                }
                BlockPos liquidPos = ItemAmadronTablet.getLiquidProvidingLocation(player.getHeldItemMainhand());
                World liquidWorld = null;
                if (liquidPos != null) {
                    liquidWorld = DimensionManager.getWorld(ItemAmadronTablet.getLiquidProvidingDimension(player.getHeldItemMainhand()));
                }
                EntityDrone drone = retrieveOrderItems(offer, shoppingAmounts[i], itemWorld, itemPos, liquidWorld, liquidPos);
                if (drone != null)
                    drone.setHandlingOffer(offer, shoppingAmounts[i], player.getHeldItemMainhand(), player.getName());
            }
        }
        Arrays.fill(shoppingAmounts, 0);
        Arrays.fill(shoppingItems, -1);
    } else if (guiID == 2) {
        player.openGui(PneumaticCraftRepressurized.instance, CommonProxy.EnumGuiId.AMADRON_ADD_TRADE.ordinal(), player.world, 0, 0, 0);
    }
}
Also used : EntityDrone(me.desht.pneumaticcraft.common.entity.living.EntityDrone) AmadronOffer(me.desht.pneumaticcraft.common.recipes.AmadronOffer) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World)

Example 4 with AmadronOffer

use of me.desht.pneumaticcraft.common.recipes.AmadronOffer 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 5 with AmadronOffer

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

the class AmadronOfferConfig method readFromJson.

@Override
protected final void readFromJson(JsonObject json) {
    readFromJsonCustom(json);
    JsonArray array = (JsonArray) json.get("offers");
    Collection<AmadronOffer> offers = getOffers();
    offers.clear();
    for (JsonElement element : array) {
        AmadronOffer offer = ((JsonObject) element).has("inStock") ? AmadronOfferCustom.fromJson((JsonObject) element) : AmadronOffer.fromJson((JsonObject) element);
        if (offer != null) {
            offers.add(offer);
        }
    }
}
Also used : JsonArray(com.google.gson.JsonArray) JsonElement(com.google.gson.JsonElement) AmadronOffer(me.desht.pneumaticcraft.common.recipes.AmadronOffer) JsonObject(com.google.gson.JsonObject)

Aggregations

AmadronOffer (me.desht.pneumaticcraft.common.recipes.AmadronOffer)10 EntityDrone (me.desht.pneumaticcraft.common.entity.living.EntityDrone)3 AmadronOfferCustom (me.desht.pneumaticcraft.common.recipes.AmadronOfferCustom)3 ItemStack (net.minecraft.item.ItemStack)3 JsonArray (com.google.gson.JsonArray)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 NBTTagList (net.minecraft.nbt.NBTTagList)2 BlockPos (net.minecraft.util.math.BlockPos)2 World (net.minecraft.world.World)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 IOException (java.io.IOException)1 Map (java.util.Map)1 AmadronRetrievalEvent (me.desht.pneumaticcraft.api.drone.AmadronRetrievalEvent)1 WidgetAmadronOffer (me.desht.pneumaticcraft.client.gui.widget.WidgetAmadronOffer)1 ContainerAmadron (me.desht.pneumaticcraft.common.inventory.ContainerAmadron)1 PacketAmadronInvSync (me.desht.pneumaticcraft.common.network.PacketAmadronInvSync)1