summaryrefslogtreecommitdiff
path: root/src/main/java/jp/plusplus/fbs/pottery/PotteryRegistry.java
blob: 8cc6ae7e4989294b78d494862f0e43084b8724aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
package jp.plusplus.fbs.pottery;

import cpw.mods.fml.common.FMLLog;
import jp.plusplus.fbs.FBS;
import jp.plusplus.fbs.api.IPottery;
import jp.plusplus.fbs.block.BlockCore;
import jp.plusplus.fbs.item.ItemCore;
import jp.plusplus.fbs.pottery.usable.*;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;

import java.util.ArrayList;

/**
 * Created by plusplus_F on 2016/03/30.
 */
public class PotteryRegistry {
    private static PotteryRegistry instance=new PotteryRegistry();

    private ArrayList<PotteryPair> potteries=new ArrayList<PotteryRegistry.PotteryPair>();
    private ArrayList<PotteryBase> potteryEffects=new ArrayList<PotteryBase>();
    private PotteryBase cachedPotteryEffect;
    public PotteryPair cachedPottery;


    public static void register(){

        //------------------------------------陶芸----------------------------------------------

        RegisterPotteryCrafting(BlockCore.pot.getItemStack(IPottery.PotteryState.MOLDED, IPottery.PotteryGrade.NORMAL, IPottery.PotterySize.SMALL, (byte)0, false), "","",""," c c ","  c  ");
        RegisterPotteryCrafting(BlockCore.pot.getItemStack(IPottery.PotteryState.MOLDED, IPottery.PotteryGrade.NORMAL, IPottery.PotterySize.SMALL, (byte)1, false), "","",""," csc ","  c  ");
        RegisterPotteryCrafting(BlockCore.pot.getItemStack(IPottery.PotteryState.MOLDED, IPottery.PotteryGrade.NORMAL, IPottery.PotterySize.SMALL, (byte)2, false), "","",""," cbc ","  c  ");
        RegisterPotteryCrafting(BlockCore.pot.getItemStack(IPottery.PotteryState.MOLDED, IPottery.PotteryGrade.NORMAL, IPottery.PotterySize.SMALL, (byte)3, false), "","",""," cfc ","  c  ");

        RegisterPotteryCrafting(BlockCore.pot.getItemStack(IPottery.PotteryState.MOLDED, IPottery.PotteryGrade.NORMAL, IPottery.PotterySize.SMALL, (byte)0, true), "","",""," g g ","  g  ");
        RegisterPotteryCrafting(BlockCore.pot.getItemStack(IPottery.PotteryState.MOLDED, IPottery.PotteryGrade.NORMAL, IPottery.PotterySize.SMALL, (byte)1, true), "","",""," gsg ","  g  ");
        RegisterPotteryCrafting(BlockCore.pot.getItemStack(IPottery.PotteryState.MOLDED, IPottery.PotteryGrade.NORMAL, IPottery.PotterySize.SMALL, (byte)2, true), "","",""," gbg ","  g  ");
        RegisterPotteryCrafting(BlockCore.pot.getItemStack(IPottery.PotteryState.MOLDED, IPottery.PotteryGrade.NORMAL, IPottery.PotterySize.SMALL, (byte)3, true), "","",""," gfg ","  g  ");

        RegisterPotteryCrafting(BlockCore.pot.getItemStack(IPottery.PotteryState.MOLDED, IPottery.PotteryGrade.NORMAL, IPottery.PotterySize.MEDIUM, (byte)0, false), "",""," c c "," c c "," ccc ");
        RegisterPotteryCrafting(BlockCore.pot.getItemStack(IPottery.PotteryState.MOLDED, IPottery.PotteryGrade.NORMAL, IPottery.PotterySize.MEDIUM, (byte)1, false), "",""," c c "," csc "," ccc ");
        RegisterPotteryCrafting(BlockCore.pot.getItemStack(IPottery.PotteryState.MOLDED, IPottery.PotteryGrade.NORMAL, IPottery.PotterySize.MEDIUM, (byte)2, false), "",""," c c "," cbc "," ccc ");
        RegisterPotteryCrafting(BlockCore.pot.getItemStack(IPottery.PotteryState.MOLDED, IPottery.PotteryGrade.NORMAL, IPottery.PotterySize.MEDIUM, (byte)3, false), "",""," c c "," cfc "," ccc ");

        RegisterPotteryCrafting(BlockCore.pot.getItemStack(IPottery.PotteryState.MOLDED, IPottery.PotteryGrade.NORMAL, IPottery.PotterySize.MEDIUM, (byte)0, true), "",""," g g "," g g "," ggg ");
        RegisterPotteryCrafting(BlockCore.pot.getItemStack(IPottery.PotteryState.MOLDED, IPottery.PotteryGrade.NORMAL, IPottery.PotterySize.MEDIUM, (byte)1, true), "",""," g g "," gsg "," ggg ");
        RegisterPotteryCrafting(BlockCore.pot.getItemStack(IPottery.PotteryState.MOLDED, IPottery.PotteryGrade.NORMAL, IPottery.PotterySize.MEDIUM, (byte)2, true), "",""," g g "," gbg "," ggg ");
        RegisterPotteryCrafting(BlockCore.pot.getItemStack(IPottery.PotteryState.MOLDED, IPottery.PotteryGrade.NORMAL, IPottery.PotterySize.MEDIUM, (byte)3, true), "",""," g g "," gfg "," ggg ");

        RegisterPotteryCrafting(BlockCore.pot.getItemStack(IPottery.PotteryState.MOLDED, IPottery.PotteryGrade.NORMAL, IPottery.PotterySize.LARGE, (byte)0, false), " c c "," c c ","c   c","c   c"," ccc ");
        RegisterPotteryCrafting(BlockCore.pot.getItemStack(IPottery.PotteryState.MOLDED, IPottery.PotteryGrade.NORMAL, IPottery.PotterySize.LARGE, (byte)1, false), " c c "," c c ","c   c","c s c"," ccc ");
        RegisterPotteryCrafting(BlockCore.pot.getItemStack(IPottery.PotteryState.MOLDED, IPottery.PotteryGrade.NORMAL, IPottery.PotterySize.LARGE, (byte)2, false), " c c "," c c ","c   c","c b c"," ccc ");
        RegisterPotteryCrafting(BlockCore.pot.getItemStack(IPottery.PotteryState.MOLDED, IPottery.PotteryGrade.NORMAL, IPottery.PotterySize.LARGE, (byte)3, false), " c c "," c c ","c   c","c f c"," ccc ");

        RegisterPotteryCrafting(BlockCore.pot.getItemStack(IPottery.PotteryState.MOLDED, IPottery.PotteryGrade.NORMAL, IPottery.PotterySize.LARGE, (byte)0, true), " g g "," g g ","g   g","g   g"," ggg ");
        RegisterPotteryCrafting(BlockCore.pot.getItemStack(IPottery.PotteryState.MOLDED, IPottery.PotteryGrade.NORMAL, IPottery.PotterySize.LARGE, (byte)1, true), " g g "," g g ","g   g","g s g"," ggg ");
        RegisterPotteryCrafting(BlockCore.pot.getItemStack(IPottery.PotteryState.MOLDED, IPottery.PotteryGrade.NORMAL, IPottery.PotterySize.LARGE, (byte)2, true), " g g "," g g ","g   g","g b g"," ggg ");
        RegisterPotteryCrafting(BlockCore.pot.getItemStack(IPottery.PotteryState.MOLDED, IPottery.PotteryGrade.NORMAL, IPottery.PotterySize.LARGE, (byte)3, true), " g g "," g g ","g   g","g f g"," ggg ");

        registerPotteryEffect(new PotteryKeep());
        registerPotteryEffect(new PotterySenaka());
        registerPotteryEffect(new PotteryVoid());
        registerPotteryEffect(new PotteryChange());
        registerPotteryEffect(new PotteryCrucible());
        registerPotteryEffect(new PotteryLottery());
        registerPotteryEffect(new PotteryTaboo());
        registerPotteryEffect(new PotteryUnbreakable());
        registerPotteryEffect(new PotteryEnchantment());
        registerPotteryEffect(new PotteryTaboo());
        registerPotteryEffect(new PotteryFurnace());
        registerPotteryEffect(new PotteryAppraisal());
    }

    /*
    ####################################################
                    Potter's Wheel

                    クラフト処理は現在クソ以外の何者でもない(Registry.PotteryPair.isMatch参照)ですが仮実装なので・・・
                    要望があればキチンとした感じに作り直します
    ####################################################
    */

    public static void RegisterPotteryCrafting(ItemStack prod, String ... str){
        instance.potteries.add(new PotteryRegistry.PotteryPair(prod, str));
    }
    public static ItemStack GetPotteryCrafting(ItemStack[] r){
        if(instance.cachedPottery!=null && instance.cachedPottery.isMatch(r)){
            return instance.cachedPottery.product;
        }

        for(PotteryRegistry.PotteryPair pp : instance.potteries){
            if(pp.isMatch(r)){
                instance.cachedPottery=pp;
                return pp.product;
            }
        }
        return null;
    }
    public static ArrayList<PotteryRegistry.PotteryPair> GetPotteryCrafting(){ return instance.potteries; }


    public static int registerPotteryEffect(PotteryBase p){
        instance.potteryEffects.add(p);
        return instance.potteryEffects.size()-1;
    }
    public static PotteryBase getPotteryEffect(int id){
        return instance.potteryEffects.get(id);
    }
    public static PotteryBase getPotteryEffect(String unlocalizedName){
        if(instance.cachedPotteryEffect!=null && instance.cachedPotteryEffect.getUnlocalizedName().equals(unlocalizedName)){
            return instance.cachedPotteryEffect;
        }

        for(PotteryBase pb : instance.potteryEffects){
            if(pb.getUnlocalizedName().equals(unlocalizedName)){
                instance.cachedPotteryEffect=pb;
                return pb;
            }
        }
        return null;
    }
    public static int getPotteryEffectId(String unlocalizedName){
        int s=instance.potteryEffects.size();
        for(int i=0;i<s;i++){
            PotteryBase pb=instance.potteryEffects.get(i);
            if(pb.getUnlocalizedName().equals(unlocalizedName)){
                instance.cachedPotteryEffect=pb;
                return i;
            }
        }
        return -1;
    }


    public static class PotteryPair{
        public ItemStack product;
        public boolean[] clays=new boolean[25];
        public char[] materials=new char[25];
        public boolean isEnable;

        public PotteryPair(ItemStack prod, String ... str){
            product=prod;
            isEnable=true;

            if(str==null || str.length!=5){
                FMLLog.severe("Failed to parse Pottery Recipe : Craft Matrix has invalid size");
                isEnable=false;
                return;
            }
            for(int k=0;k<str.length;k++){
                if(str[k].length()==0){
                    for(int i=0;i<5;i++) materials[k*5+i]=' ';
                    continue;
                }

                if(str[k].length()!=5){
                    FMLLog.severe("Failed to parse Pottery Recipe : Craft Matrix has invalid size");
                    isEnable=false;
                    return;
                }

                for(int i=0;i<str[k].length();i++){
                    char c=str[k].charAt(i);
                    clays[k*5+i]=(c!=' ');
                    materials[k*5+i]=c;
                }
            }
        }
        public boolean isMatch(ItemStack[] r){
            if(!isEnable || r.length!=25) return false;
            for(int i=0;i<25;i++){
                if(materials[i]==' '){
                    if(r[i]!=null) return false;
                    continue;
                }
                else{
                    //何か文句があれば変える
                    if(materials[i]=='c'){
                        if(r[i]==null) return false;
                        Item item=r[i].getItem();
                        if(item!= ItemCore.clayWet) return false;
                    }
                    else if(materials[i]=='g'){
                        if(r[i]==null) return false;
                        Item item=r[i].getItem();
                        if(item!=ItemCore.clayGlow) return false;
                    }
                    else if(materials[i]=='f'){
                        if(r[i]==null) return false;
                        Item item=r[i].getItem();
                        if(item!=Item.getItemFromBlock(Blocks.red_flower) && item!=Item.getItemFromBlock(Blocks.yellow_flower)) return false;
                    }
                    else if(materials[i]=='s'){
                        if(r[i]==null) return false;
                        Item item=r[i].getItem();
                        if(item!= Items.stick) return false;
                    }
                    else if(materials[i]=='b'){
                        if(r[i]==null) return false;
                        Item item=r[i].getItem();
                        if(item!=Item.getItemFromBlock(Blocks.iron_bars)) return false;
                    }

                }
                /*
                if(clays[i]){
                    if(r[i]==null) return false;
                    Item item=r[i].getItem();
                    if(item!=ItemCore.clayWet && item!=ItemCore.clayGlow) return false;
                }
                else if(r[i]!=null) return false;
                */
            }
            return true;
        }
    }
}