Below is a complete Python script for an "Infinite Craft bot." This bot automates playing Infinite Craft by interacting with the game's public API (reverse-engineered from the browser game at neal.fun/infinite-craft). It starts with the basic elements (Water, Fire, Earth, Wind), randomly combines them, discovers new elements, and adds them to its inventory. It runs infinitely, printing new discoveries to the console.
Important Notes:
- How it works: The bot makes API calls to combine two random elements. If a new element is discovered, it's added to the list. This simulates "infinite" crafting without needing a browser.
- Rate limiting: The game's API has some rate limits. I've added a 1-second delay between requests to avoid getting blocked. If you hit limits, increase the delay or run it slower.
- Dependencies: You need Python 3.x and the
requests library. Install it with pip install requests.
- Ethics/Legal: This is for educational purposes. Automating the game might violate the site's terms of service. Use responsibly and don't overload their servers. The API is public but unofficial.
- Customization: You can modify the starting elements, add logging to a file, or implement smarter combination logic (e.g., prioritize new combos).
- Output: It will print new discoveries like "Discovered: Steam from Water + Fire". Run it in a terminal, and stop with Ctrl+C.
Code
import requests
import random
import time
# Starting elements (the basics from Infinite Craft)
elements = ["Water", "Fire", "Earth", "Wind"]
# Track discovered elements to avoid duplicates
discovered = set(elements)
# API endpoint (reverse-engineered from the game)
API_URL = "https://neal.fun/api/infinite-craft/pair"
# Headers to mimic a browser request (helps avoid blocks)
HEADERS = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3",
"Referer": "https://neal.fun/infinite-craft/",
}
def combine_elements(first, second):
"""Call the API to combine two elements."""
params = {
"first": first,
"second": second,
}
try:
response = requests.get(API_URL, params=params, headers=HEADERS)
response.raise_for_status() # Raise error if request fails
data = response.json()
return data.get("result"), data.get("emoji", ""), data.get("isNew", False)
except requests.exceptions.RequestException as e:
print(f"API error: {e}")
return None, None, False
print("Infinite Craft Bot starting... Press Ctrl+C to stop.")
print(f"Starting with {len(elements)} elements: {', '.join(elements)}")
while True:
# Pick two random elements to combine
first = random.choice(elements)
second = random.choice(elements)
# Combine them via API
result, emoji, is_new = combine_elements(first, second)
if result and result not in discovered:
# New discovery!
discovered.add(result)
elements.append(result)
print(f"Discovered: {result} {emoji} from {first} + {second} (Total: {len(elements)})")
elif result:
# Already known, but print occasionally for activity
if random.random() < 0.01: # 1% chance to print repeats
print(f"Repeated: {result} from {first} + {second}")
# Delay to avoid rate limiting (increase if needed)
time.sleep(1)
How to Run It
- Save the code to a file, e.g.,
infinite_craft_bot.py.
- Open a terminal/command prompt.
- Run
python infinite_craft_bot.py.
- Watch it discover elements! It will keep going forever, building a larger and larger list.
Example Output
Infinite Craft Bot starting... Press Ctrl+C to stop.
Starting with 4 elements: Water, Fire, Earth, Wind
Discovered: Steam 💨 from Water + Fire (Total: 5)
Discovered: Plant 🌿 from Earth + Water (Total: 6)
Discovered: Mud 💩 from Earth + Steam (Total: 7)
Discovered: Engine 🚂 from Steam + Fire (Total: 8)
... (continues infinitely)
Enhancements You Could Add
- Smarter Combinations: Instead of random, use a queue to combine new elements with all existing ones systematically.
- Save/Load State: Use
json to save the elements list to a file and load it on restart.
- Search for Specific Element: Add a function to try combining until a target (e.g., "Superman") is found.
- Discord Bot Integration: If you meant a Discord bot, wrap this in discord.py to let users command combinations (e.g.,
!craft Water Fire).
- Error Handling: Add retries if the API fails.
If this isn't what you meant (e.g., you wanted a browser automation script with Selenium, a Discord bot, or something else), provide more details, and I'll adjust!