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
|
package jp.plusplus.fbs.pottery.usable;
import jp.plusplus.fbs.api.IPottery;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.world.World;
import javax.annotation.Nullable;
/**
* Created by plusplus_F on 2016/03/30.
* 魔法の壺の基底クラス
*/
public abstract class PotteryBase {
public static final String ITEM_STACKS="ItemStacks";
public NBTTagCompound getPotteryNBT(ItemStack pottery){
if(!pottery.hasTagCompound()){
pottery.setTagCompound(new NBTTagCompound());
}
return pottery.getTagCompound();
}
/**
* 壺のUnlocalizedNameを返す<br>
* ここで返した文字列がそのままローカライズに使用される
* @return UnlocalizedName
*/
public abstract String getUnlocalizedName();
/**
* 名前の後ろにつく付加的な情報を返す
* @param pottery 壺のアイテムスタック
* @return
*/
public String getNameModifier(ItemStack pottery){
IPottery ip=(IPottery)((ItemBlock)pottery.getItem()).field_150939_a;
int slot;
switch (ip.getSize(pottery.getTagCompound())){
case SMALL: slot=9; break;
case LARGE: slot=27; break;
default: slot=18; break;
}
if(pottery.getTagCompound().hasKey(ITEM_STACKS)){
NBTTagList list=(NBTTagList)pottery.getTagCompound().getTag(ITEM_STACKS);
slot-=list.tagCount();
}
return "["+slot+"]";
}
/**
* 売却値にかかる補正を返す
* @param pottery 壺のアイテムスタック
* @return 売却値補正
*/
public float getPriceScale(ItemStack pottery){
return 1.f;
}
/**
* 壺が焼かれた時に呼び出される
* @param pottery 壺のアイテムスタック
*/
public void onBaked(ItemStack pottery){}
/**
* この壺が使用できるか判定する
* @param player 所有者
* @param pottery 壺のアイテムスタック
* @return
*/
public boolean canUse(EntityPlayer player, ItemStack pottery){
return true;
}
/**
* 壺を使用したときの処理
* @param player 所有者
* @param pottery 壺のアイテムスタック
* @return
*/
public abstract ItemStack onUse(EntityPlayer player, ItemStack pottery);
/**
* 壺が破壊されたときの処理
* @param player 所有者
* @param pottery 壺のアイテムスタック
*/
public void onCrash(EntityPlayer player, ItemStack pottery){
NBTTagCompound nbt=getPotteryNBT(pottery);
if(nbt.hasKey(ITEM_STACKS)){
NBTTagList list=(NBTTagList)nbt.getTag(ITEM_STACKS);
for(int i=0;i<list.tagCount();i++){
NBTTagCompound tag=list.getCompoundTagAt(i);
ItemStack itemStack=ItemStack.loadItemStackFromNBT(tag);
player.entityDropItem(itemStack, player.getEyeHeight());
}
}
}
/**
* 魔法の壺のインベントリが開く際に全てのスロットに対して行われる処理
* @param player 所有者
* @param pottery 壺のアイテムスタック
* @param index スロットインデックス
* @param itemStack 何か処理するアイテムスタック
* @return スロットに格納されるItemStack
*/
public ItemStack onInventoryOpening(EntityPlayer player, ItemStack pottery, int index, @Nullable ItemStack itemStack){
return itemStack;
}
/**
* 魔法の壺のインベントリが閉じる際に全てのスロットに対して行われる処理
* @param player 所有者
* @param pottery 壺のアイテムスタック
* @param index スロットインデックス
* @param itemStack 何か処理するアイテムスタック
* @return NBTに書き込まれるItemStack
*/
public ItemStack onInventoryClosing(EntityPlayer player, ItemStack pottery, int index, @Nullable ItemStack itemStack){
return itemStack;
}
/**
* 魔法の壺のインベントリがそのアイテムが適しているか
* @param player 所有者
* @param pottery 壺のアイテムスタック
* @param index スロットインデックス
* @param itemStack 判定アイテムスタック
* @return スロットに入るかどうか
*/
public boolean isItemValid(EntityPlayer player, ItemStack pottery, int index, ItemStack itemStack){
return true;
}
/**
* 魔法の壺のインベントリからそのアイテムを取り出せるか
* @param player 所有者
* @param pottery 壺のアイテムスタック
* @param index スロットインデックス
* @param itemStack 判定アイテムスタック
* @return 取り出せるかどうか
*/
public boolean canTakeStack(EntityPlayer player, ItemStack pottery, int index, ItemStack itemStack){
return true;
}
}
|