Search in sources :

Example 1 with AmadronOfferCustom

use of pneumaticCraft.common.recipes.AmadronOfferCustom in project PneumaticCraft by MineMaarten.

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);
    NBTTagCompound inv = new NBTTagCompound();
    // Write the ItemStacks in the inventory to NBT
    NBTTagList tagList = new NBTTagList();
    for (int currentIndex = 0; currentIndex < inventory.getSizeInventory(); ++currentIndex) {
        if (inventory.getStackInSlot(currentIndex) != null) {
            NBTTagCompound tagCompound = new NBTTagCompound();
            tagCompound.setByte("Slot", (byte) currentIndex);
            inventory.getStackInSlot(currentIndex).writeToNBT(tagCompound);
            tagList.appendTag(tagCompound);
        }
    }
    inv.setTag("Inv", tagList);
    NBTTagList upgradeList = new NBTTagList();
    for (int i = 0; i < 9; i++) {
        if (upgradeInventory[i] != null) {
            NBTTagCompound slotEntry = new NBTTagCompound();
            slotEntry.setByte("Slot", (byte) i);
            upgradeInventory[i].writeToNBT(slotEntry);
            upgradeList.appendTag(slotEntry);
        }
    }
    // save content in Inventory->Items
    inv.setTag("Items", upgradeList);
    tag.setTag("Inventory", inv);
    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 : NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) PathPoint(net.minecraft.pathfinding.PathPoint) AmadronOfferCustom(pneumaticCraft.common.recipes.AmadronOfferCustom)

Example 2 with AmadronOfferCustom

use of pneumaticCraft.common.recipes.AmadronOfferCustom in project PneumaticCraft by MineMaarten.

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(pneumaticCraft.common.recipes.AmadronOffer) IOException(java.io.IOException) AmadronOfferCustom(pneumaticCraft.common.recipes.AmadronOfferCustom) PacketAmadronTradeRemoved(pneumaticCraft.common.network.PacketAmadronTradeRemoved)

Example 3 with AmadronOfferCustom

use of pneumaticCraft.common.recipes.AmadronOfferCustom in project PneumaticCraft by MineMaarten.

the class GuiAmadronAddTrade method actionPerformed.

@Override
public void actionPerformed(GuiButton button) {
    EntityPlayer player = FMLClientHandler.instance().getClient().thePlayer;
    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) != null) {
            input = container.getStack(0).copy();
            ((ItemStack) input).stackSize = inputNumber.getValue();
        } else {
            input = new FluidStack(inputFluid.getFluid(), inputNumber.getValue());
        }
        Object output;
        if (container.getStack(1) != null) {
            output = container.getStack(1).copy();
            ((ItemStack) output).stackSize = outputNumber.getValue();
        } else {
            output = new FluidStack(outputFluid.getFluid(), outputNumber.getValue());
        }
        AmadronOfferCustom trade = new AmadronOfferCustom(input, output, player);
        ChunkPosition 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(pneumaticCraft.common.inventory.ContainerAmadronAddTrade) FluidStack(net.minecraftforge.fluids.FluidStack) ChunkPosition(net.minecraft.world.ChunkPosition) EntityPlayer(net.minecraft.entity.player.EntityPlayer) PacketAmadronTradeAdd(pneumaticCraft.common.network.PacketAmadronTradeAdd) GuiLogisticsLiquidFilter(pneumaticCraft.client.gui.semiblock.GuiLogisticsLiquidFilter) ItemStack(net.minecraft.item.ItemStack) AmadronOfferCustom(pneumaticCraft.common.recipes.AmadronOfferCustom)

Example 4 with AmadronOfferCustom

use of pneumaticCraft.common.recipes.AmadronOfferCustom in project PneumaticCraft by MineMaarten.

the class WidgetAmadronOffer method render.

@Override
public void render(int mouseX, int mouseY, float partialTick) {
    GL11.glDisable(GL11.GL_LIGHTING);
    if (renderBackground) {
        Minecraft.getMinecraft().getTextureManager().bindTexture(Textures.WIDGET_AMADRON_OFFER);
        GL11.glColor4d(1, canBuy ? 1 : 0.4, canBuy ? 1 : 0.4, 1);
        Gui.func_146110_a(x, y, 0, 0, getBounds().width, getBounds().height, 256, 256);
    }
    for (IGuiWidget widget : widgets) {
        widget.render(mouseX, mouseY, partialTick);
    }
    Minecraft.getMinecraft().fontRenderer.drawString(offer.getVendor(), x + 2, y + 2, 0xFF000000);
    boolean customOffer = offer instanceof AmadronOfferCustom;
    if (shoppingAmount > 0) {
        Minecraft.getMinecraft().fontRenderer.drawString(shoppingAmount + "", x + 36 - Minecraft.getMinecraft().fontRenderer.getStringWidth("" + shoppingAmount) / 2, y + (customOffer ? 15 : 20), 0xFF000000);
    }
    if (customOffer) {
        AmadronOfferCustom custom = (AmadronOfferCustom) offer;
        Minecraft.getMinecraft().fontRenderer.drawString(EnumChatFormatting.DARK_BLUE.toString() + custom.getStock() + "", x + 36 - Minecraft.getMinecraft().fontRenderer.getStringWidth("" + custom.getStock()) / 2, y + 25, 0xFF000000);
    }
}
Also used : AmadronOfferCustom(pneumaticCraft.common.recipes.AmadronOfferCustom)

Example 5 with AmadronOfferCustom

use of pneumaticCraft.common.recipes.AmadronOfferCustom in project PneumaticCraft by MineMaarten.

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.stackSize * drone.getOfferTimes();
            List<ItemStack> stacks = new ArrayList<ItemStack>();
            while (producedItems > 0) {
                ItemStack stack = offeringItems.copy();
                stack.stackSize = Math.min(producedItems, stack.getMaxStackSize());
                stacks.add(stack);
                producedItems -= stack.stackSize;
            }
            ChunkPosition pos = ItemAmadronTablet.getItemProvidingLocation(usedTablet);
            if (pos != null) {
                World world = PneumaticCraftUtils.getWorldForDimension(ItemAmadronTablet.getItemProvidingDimension(usedTablet));
                PneumaticRegistry.getInstance().deliverItemsAmazonStyle(world, pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ, stacks.toArray(new ItemStack[stacks.size()]));
            }
        } else {
            FluidStack offeringFluid = ((FluidStack) offer.getOutput()).copy();
            offeringFluid.amount *= drone.getOfferTimes();
            ChunkPosition pos = ItemAmadronTablet.getLiquidProvidingLocation(usedTablet);
            if (pos != null) {
                World world = PneumaticCraftUtils.getWorldForDimension(ItemAmadronTablet.getLiquidProvidingDimension(usedTablet));
                PneumaticRegistry.getInstance().deliverFluidAmazonStyle(world, pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ, offeringFluid);
            }
        }
    }
}
Also used : EntityDrone(pneumaticCraft.common.entity.living.EntityDrone) FluidStack(net.minecraftforge.fluids.FluidStack) ChunkPosition(net.minecraft.world.ChunkPosition) AmadronOffer(pneumaticCraft.common.recipes.AmadronOffer) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) World(net.minecraft.world.World) AmadronOfferCustom(pneumaticCraft.common.recipes.AmadronOfferCustom) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Aggregations

AmadronOfferCustom (pneumaticCraft.common.recipes.AmadronOfferCustom)7 AmadronOffer (pneumaticCraft.common.recipes.AmadronOffer)3 IOException (java.io.IOException)2 ItemStack (net.minecraft.item.ItemStack)2 ChunkPosition (net.minecraft.world.ChunkPosition)2 FluidStack (net.minecraftforge.fluids.FluidStack)2 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)1 ArrayList (java.util.ArrayList)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 NBTTagList (net.minecraft.nbt.NBTTagList)1 PathPoint (net.minecraft.pathfinding.PathPoint)1 ChatComponentTranslation (net.minecraft.util.ChatComponentTranslation)1 World (net.minecraft.world.World)1 GuiLogisticsLiquidFilter (pneumaticCraft.client.gui.semiblock.GuiLogisticsLiquidFilter)1 EntityDrone (pneumaticCraft.common.entity.living.EntityDrone)1 ContainerAmadronAddTrade (pneumaticCraft.common.inventory.ContainerAmadronAddTrade)1 PacketAmadronTradeAdd (pneumaticCraft.common.network.PacketAmadronTradeAdd)1 PacketAmadronTradeRemoved (pneumaticCraft.common.network.PacketAmadronTradeRemoved)1