Делаю мод "ChromaCraft"

1,087
2
Начал делать "глобальный" мод. Мод на магию. В самом моде сделал систему изучений. Вот пример из книжки:
dFOCTBn.png

На картинке всё объяснил. Никита сделает текстуры.
Одно изучение и категорию я сделал для примера (Это эти вот блэйзовые палки).
Код огромный. Очень. Так что скидывать не буду. Дам только куски апи:
Код:
public class ApiCore {

    /**
     * All categories the Chromaticum can have
     */
    public static List<CategoryEntry> categories = new ArrayList<CategoryEntry>();

    /**
     * A list of all discoveries bound to generic ItemStack
     */
    public static Hashtable<String, DiscoveryEntry> discoveriesByIS = new Hashtable<String, DiscoveryEntry>();

    /**
     * Finds a DiscoveryEntry by the given ItemStack. The ItemStack would either be in the list of items at one of the pages, or will be a crafting result.
     * @param referal - the ItemStack to lookup.
     * @return A valid DiscoveryEntry if was found, null otherwise
     */
    public static DiscoveryEntry findDiscoveryByIS(ItemStack referal)
    {
        if(referal == null)return null;
        int size = referal.stackSize;
        referal.stackSize = 0;
        DiscoveryEntry de = ApiCore.discoveriesByIS.get(referal.toString());
        referal.stackSize = size;
        return de;
    }

}
//Это не весь код. Я покажу только самое главное.
Код:
public class CategoryEntry {

    public List<DiscoveryEntry> discoveries = new ArrayList<DiscoveryEntry>();

    public String id;

    public ItemStack displayStack;

    public String name;

    public String shortDescription;

    public ResourceLocation displayTexture;

    public int reqTier;

    public ResourceLocation specificBookTextures;

    public int textColor = 0x222222;

    public CategoryEntry(String i)
    {
        id = i;
    }

    public CategoryEntry setName(String s)
    {
        name = s;
        return this;
    }

    public CategoryEntry setTier(int i)
    {
        reqTier = i;
        return this;
    }

    public CategoryEntry setTextColor(int i)
    {
        textColor = i;
        return this;
    }

    public CategoryEntry setDisplayStack(Object obj)
    {
        if(obj instanceof ItemStack)
            displayStack = (ItemStack) obj;
        if(obj instanceof Block)
            displayStack = new ItemStack((Block) obj,1,0);
        if(obj instanceof Item)
            displayStack = new ItemStack((Item) obj,1,0);
        if(obj instanceof ResourceLocation)
            displayTexture = (ResourceLocation) obj;
        return this;
    }

    public CategoryEntry setDesc(String s)
    {
        shortDescription = s;
        return this;
    }

    public CategoryEntry setSpecificTexture(ResourceLocation l)
    {
        specificBookTextures = l;
        return this;
    }

    public CategoryEntry apendDiscovery(DiscoveryEntry disc)
    {
        discoveries.add(disc);
        return this;
    }

}
Код:
public class DiscoveryEntry {

    public List<PageEntry> pages = new ArrayList<PageEntry>();

    public String id;

    public ItemStack displayStack;

    public List<ItemStack> referalItemStackLst = new ArrayList<ItemStack>();

    public String name;

    public String shortDescription;

    public ResourceLocation displayTexture;

    public boolean isNew = false;

    public DiscoveryEntry(String i)
    {
        id = i;
    }

    public DiscoveryEntry setName(String s)
    {
        name = s;
        return this;
    }

    public DiscoveryEntry setNew()
    {
        isNew = true;
        return this;
    }

    public DiscoveryEntry setDisplayStack(Object obj)
    {
        if(obj instanceof ItemStack)
            displayStack = (ItemStack) obj;
        if(obj instanceof Block)
            displayStack = new ItemStack((Block) obj,1,0);
        if(obj instanceof Item)
            displayStack = new ItemStack((Item) obj,1,0);
        if(obj instanceof ResourceLocation)
            displayTexture = (ResourceLocation) obj;
        return this;
    }

    public DiscoveryEntry setDesc(String s)
    {
        shortDescription = s;
        return this;
    }

    public DiscoveryEntry apendPage(PageEntry page)
    {
        pages.add(page);
        return this;
    }

    public DiscoveryEntry setReferal(ItemStack... stk)
    {
        referalItemStackLst.addAll(Arrays.asList(stk));
        for(int i = 0;i < stk.length; ++i)
        {
            ItemStack is = stk[i];
            is.stackSize = 0;
            ApiCore.discoveriesByIS.put(is.toString(), this);
        }
        return this;
    }

}
Код:
public class PageEntry {

    public String pageTitle;

    public String pageText;

    public ResourceLocation pageImgLink;

    public String pageID;

    public IRecipe pageRecipe;

    public ItemStack[] displayedItems;

    public PageEntry setTitle(String title)
    {
        pageTitle = title;
        return this;
    }

    public PageEntry setText(String txt)
    {
        pageText = txt;
        return this;
    }

    public PageEntry setImg(ResourceLocation img)
    {
        pageImgLink = img;
        return this;
    }

    public PageEntry setRecipe(IRecipe rec)
    {
        pageRecipe = rec;
        return this;
    }

    public PageEntry setDisplayStacks(ItemStack... rec)
    {
        displayedItems = rec;
        return this;
    }

    public PageEntry(String id)
    {
        pageID = id;
    }

}
Код:
public class StructureRecipe implements IRecipe{

    public List<StructureBlock> structure = new ArrayList<StructureBlock>();
    public ItemStack referal;

    public StructureRecipe(ItemStack ref, StructureBlock... positions)
    {
        referal = ref;
        structure = Arrays.asList(positions);
    }

    @Override
    public boolean matches(InventoryCrafting p_77569_1_, World p_77569_2_) {
        return false;
    }

    @Override
    public ItemStack getCraftingResult(InventoryCrafting p_77572_1_) {
        return referal;
    }

    @Override
    public int getRecipeSize() {
        // TODO Auto-generated method stub
        return structure.size();
    }

    @Override
    public ItemStack getRecipeOutput() {
        // TODO Auto-generated method stub
        return referal;
    }



}
//Это возможность показыват то, как делать структуры, в книге
Код:
public class StructureBlock {

    public Block blk;
    public int metadata;
    public int x,y,z;

    public StructureBlock(Block b, int meta, int i, int j, int k)
    {
        blk = b;
        metadata = meta;
        x = i;
        y = j;
        z = k;
    }

}
Это весь апи для книги. Вскоре он будет пополняться. Будет возможность крафтить на том, чего я ещё не сделал.
P.S. Код гуи от книжки = 2300 строк...
 
Сверху