This commit is contained in:
Timo Ley 2021-04-18 18:37:43 +02:00
parent b16580c81b
commit 9f73d5f760
408 changed files with 8708 additions and 2 deletions

View File

@ -18,8 +18,8 @@ buildscript {
apply plugin: 'forge'
version = "1.0"
group= "modgroup"
archivesBaseName = "modid"
group= "ley.modding"
archivesBaseName = "alchemycraft"
minecraft {
version = "1.7.10-10.13.4.1614-1.7.10"

View File

@ -0,0 +1,51 @@
package ley.modding.alchemycraft;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import ley.modding.alchemycraft.alchemy.ElementManager;
import ley.modding.alchemycraft.event.EventHandler;
import ley.modding.alchemycraft.internal.Registry;
import ley.modding.alchemycraft.items.ACItems;
import ley.modding.alchemycraft.tab.ACTab;
import ley.modding.tileralib.api.IRegistry;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraftforge.common.MinecraftForge;
@Mod(modid = Alchemycraft.MODID, name = Alchemycraft.NAME, version = Alchemycraft.VERSION)
public class Alchemycraft {
public static final String MODID = "alchemycraft";
public static final String NAME = "Alchemycraft";
public static final String VERSION = "1.0";
public static CreativeTabs tab = new ACTab();
@Mod.EventHandler
public void preInit(FMLPreInitializationEvent e) {
MinecraftForge.EVENT_BUS.register(new EventHandler());
try {
ElementManager.loadElements();
} catch (Exception exc) {
throw new RuntimeException(exc);
}
}
@Mod.EventHandler
public void init(FMLInitializationEvent e) {
IRegistry registry = new Registry();
ACItems.register(registry);
}
@Mod.EventHandler
public void postInit(FMLPostInitializationEvent e) {
}
}

View File

@ -0,0 +1,15 @@
package ley.modding.alchemycraft.alchemy;
public class DefaultResult implements IResult {
int[] result;
public DefaultResult(int[] result) {
this.result = result;
}
@Override
public int[] getResult() {
return result;
}
}

View File

@ -0,0 +1,11 @@
package ley.modding.alchemycraft.alchemy;
public class Element {
public String name;
public String id;
public String texture;
public int num;
public int signature;
}

View File

@ -0,0 +1,59 @@
package ley.modding.alchemycraft.alchemy;
import ley.modding.alchemycraft.alchemy.json.ElementJson;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class ElementManager {
public static List<Element> elements;
static Map<Integer, Element> signatures;
static Map<Integer, IResult> combinationResults;
public static void loadElements() {
elements = new ArrayList<Element>();
signatures = new HashMap<Integer, Element>();
combinationResults = new HashMap<Integer, IResult>();
InputStreamReader reader = new InputStreamReader(ElementManager.class.getClassLoader().getResourceAsStream("assets/alchemycraft/elements.json"));
ElementJson json = ElementJson.fromJSON(reader);
for (Element e : json.elements) {
elements.add(e.num, e);
signatures.put(e.signature, e);
}
for (String s : json.combinations.keySet()) {
List<ElementJson.CombinationResult> res = json.combinations.get(s);
combinationResults.put(Integer.valueOf(s), new DefaultResult(res.get(0).results)); //TODO Chances
}
}
public static List<Element> combine(Element e1, Element e2) {
List<Element> result = new ArrayList<Element>();
int signature = 0;
if (e1.signature != e2.signature)
signature = e1.signature ^ e2.signature;
else
signature = e1.signature;
if (combinationResults.containsKey(signature)) {
int[] res = combinationResults.get(signature).getResult();
for (int i : res) {
result.add(signatures.get(i));
}
} else {
result.add(e1);
result.add(e2);
}
return result;
}
}

View File

@ -0,0 +1,7 @@
package ley.modding.alchemycraft.alchemy;
public interface IResult {
int[] getResult();
}

View File

@ -0,0 +1,29 @@
package ley.modding.alchemycraft.alchemy.json;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import ley.modding.alchemycraft.alchemy.Element;
import java.io.Reader;
import java.util.List;
import java.util.Map;
public class ElementJson {
static Gson gson = new GsonBuilder().create();
public static ElementJson fromJSON(Reader json) {
return gson.fromJson(json, ElementJson.class);
}
public List<Element> elements;
public Map<String, List<CombinationResult>> combinations;
public static class CombinationResult {
public double chance;
public int[] results;
}
}

View File

@ -0,0 +1,16 @@
package ley.modding.alchemycraft.event;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import ley.modding.alchemycraft.items.ItemElement;
import net.minecraftforge.event.entity.item.ItemTossEvent;
public class EventHandler {
@SubscribeEvent
public void onItemDrop(ItemTossEvent event) {
if (event.entityItem.getEntityItem().getItem() instanceof ItemElement) {
event.entityItem.age = 200;
}
}
}

View File

@ -0,0 +1,36 @@
package ley.modding.alchemycraft.internal;
import ley.modding.tileralib.api.IIngredient;
import net.minecraft.item.Item;
public class ItemIngredient implements IIngredient {
char key;
int count;
Item item;
public ItemIngredient(char key, Item item) {
this.key = key;
this.item = item;
}
public ItemIngredient(int count, Item item) {
this.count = count;
this.item = item;
}
@Override
public char getKey() {
return key;
}
@Override
public int getCount() {
return count;
}
@Override
public Object getIngredient() {
return item;
}
}

View File

@ -0,0 +1,91 @@
package ley.modding.alchemycraft.internal;
import cpw.mods.fml.common.registry.GameRegistry;
import ley.modding.alchemycraft.Alchemycraft;
import ley.modding.tileralib.api.IIngredient;
import ley.modding.tileralib.api.IRegistry;
import ley.modding.tileralib.api.ITEProvider;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import java.util.*;
public class Registry implements IRegistry {
Map<String, Item> items;
Map<String, Block> blocks;
public Registry() {
items = new HashMap<String, Item>();
blocks = new HashMap<String, Block>();
}
@Override
public String getModID() {
return Alchemycraft.MODID;
}
@Override
public Item getItem(String id) {
if (items.containsKey(id)) {
return items.get(id);
}
return GameRegistry.findItem(getModID(), id);
}
@Override
public Block getBlock(String id) {
if (blocks.containsKey(id)) {
return blocks.get(id);
}
return GameRegistry.findBlock(getModID(), id);
}
@Override
public void addShapedRecipe(ItemStack output, String[] pattern, IIngredient[] ingredients) {
List<Object> objects = new ArrayList<Object>(Arrays.asList(pattern));
for (IIngredient i : ingredients) {
objects.add(i.getKey());
objects.add(i.getIngredient());
}
GameRegistry.addShapedRecipe(output, objects.toArray());
}
@Override
public void addShapelessRecipe(ItemStack output, IIngredient[] input) {
List<Object> objects = new ArrayList<Object>();
for (IIngredient ing : input) {
for (int i = 0; i < ing.getCount(); i++) {
objects.add(ing.getIngredient());
}
}
GameRegistry.addShapelessRecipe(output, objects.toArray());
}
@Override
public Item registerItem(Item item) {
if (item != null) {
String id = item.getUnlocalizedName().toLowerCase().split("\\.")[1];
items.put(id, item);
GameRegistry.registerItem(item, id, getModID());
return item;
}
return null;
}
@Override
public Block registerBlock(Block block) {
if (block != null) {
String id = block.getUnlocalizedName().toLowerCase().split("\\.")[1];
blocks.put(id, block);
GameRegistry.registerBlock(block, id);
if (block instanceof ITEProvider) {
GameRegistry.registerTileEntity(((ITEProvider) block).getTEClass(),id);
}
return block;
}
return null;
}
}

View File

@ -0,0 +1,16 @@
package ley.modding.alchemycraft.items;
import ley.modding.tileralib.api.IRegistry;
import net.minecraft.item.Item;
public class ACItems {
public static Item element;
public static void register(IRegistry reg) {
element = reg.registerItem(new ItemElement());
}
}

View File

@ -0,0 +1,110 @@
package ley.modding.alchemycraft.items;
import ley.modding.alchemycraft.Alchemycraft;
import ley.modding.alchemycraft.alchemy.Element;
import ley.modding.alchemycraft.alchemy.ElementManager;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.IIcon;
import java.util.List;
public class ItemElement extends Item {
static IIcon[] icons;
public ItemElement() {
setUnlocalizedName("element");
setTextureName(Alchemycraft.MODID + ":" + "element");
setHasSubtypes(true);
setCreativeTab(Alchemycraft.tab);
}
@Override
public IIcon getIconFromDamage(int meta) {
if (meta < 0 || meta >= icons.length) {
return itemIcon;
}
return icons[meta];
}
@Override
public void registerIcons(IIconRegister reg) {
icons = new IIcon[ElementManager.elements.size()];
for (Element e : ElementManager.elements) {
icons[e.num] = reg.registerIcon(Alchemycraft.MODID + ":" + e.texture);
}
}
@Override
public void getSubItems(Item item, CreativeTabs tab, List list) {
for (Element e : ElementManager.elements) {
list.add(new ItemStack(this, 1, e.num));
}
}
@Override
public String getItemStackDisplayName(ItemStack stack) {
if (stack.getItemDamage() < 0 || stack.getItemDamage() >= ElementManager.elements.size())
return super.getItemStackDisplayName(stack);
return ElementManager.elements.get(stack.getItemDamage()).name;
}
@Override
public boolean onEntityItemUpdate(EntityItem entity) {
if (!entity.worldObj.isRemote && entity.age > 200) {
AxisAlignedBB region = AxisAlignedBB.getBoundingBox(entity.posX - 1, entity.posY - 1, entity.posZ - 1, entity.posX + 1, entity.posY + 1, entity.posZ + 1);
List<Entity> list = entity.worldObj.getEntitiesWithinAABBExcludingEntity(entity, region);
for (Entity e : list) {
if (e instanceof EntityItem && !e.isDead) {
EntityItem ei = (EntityItem) e;
if (ei.getEntityItem().getItem() instanceof ItemElement) {
Element e1 = getElementFromStack(entity.getEntityItem());
Element e2 = getElementFromStack(ei.getEntityItem());
List<Element> res = ElementManager.combine(e1, e2);
if (res.size() == 2 && res.contains(e1) && res.contains(e2)) {
continue;
}
entity.getEntityItem().stackSize--;
ei.getEntityItem().stackSize--;
if (entity.getEntityItem().stackSize <= 0) {
entity.setDead();
}
if (ei.getEntityItem().stackSize <= 0) {
ei.setDead();
}
for (Element el : res) {
ItemStack element = new ItemStack(this, 1, el.num);
EntityItem ent = new EntityItem(entity.worldObj, entity.posX, entity.posY, entity.posZ, element);
entity.worldObj.spawnEntityInWorld(ent);
}
return true;
}
}
}
}
return false;
}
Element getElementFromStack(ItemStack stack) {
if (stack.getItem() instanceof ItemElement) {
int meta = stack.getItemDamage();
if (meta >= 0 && meta < ElementManager.elements.size()) {
return ElementManager.elements.get(meta);
}
}
return null;
}
}

View File

@ -0,0 +1,17 @@
package ley.modding.alchemycraft.tab;
import ley.modding.alchemycraft.items.ACItems;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
public class ACTab extends CreativeTabs {
public ACTab() {
super("Alchemycraft");
}
@Override
public Item getTabIconItem() {
return ACItems.element;
}
}

View File

@ -0,0 +1,11 @@
package ley.modding.tileralib.api;
public interface IIngredient {
char getKey();
int getCount();
Object getIngredient();
}

View File

@ -0,0 +1,24 @@
package ley.modding.tileralib.api;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
public interface IRegistry {
String getModID();
Item registerItem(Item item);
Block registerBlock(Block block);
Item getItem(String id);
Block getBlock(String id);
void addShapedRecipe(ItemStack output, String[] pattern, IIngredient[] ingredients);
void addShapelessRecipe(ItemStack output, IIngredient[] input);
}

View File

@ -0,0 +1,9 @@
package ley.modding.tileralib.api;
import net.minecraft.tileentity.TileEntity;
public interface ITEProvider {
Class<? extends TileEntity> getTEClass();
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1 @@
itemGroup.Alchemycraft=Alchemycraft

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.0 KiB

Some files were not shown because too many files have changed in this diff Show More