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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
|
package jp.plusplus.fbs.exprop;
import jp.plusplus.fbs.block.BlockCore;
import jp.plusplus.fbs.spirit.ISpiritTool;
import jp.plusplus.fbs.spirit.SpiritManager;
import jp.plusplus.fbs.spirit.SpiritStatus;
import jp.plusplus.fbs.tileentity.TileEntityMagicCore;
import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import net.minecraft.world.WorldProvider;
import net.minecraftforge.common.DimensionManager;
import net.minecraftforge.common.IExtendedEntityProperties;
import java.util.ArrayList;
/**
* Createdby pluslus_Fon 2015/06/05.
*/
public class FBSEntityProperties implements IExtendedEntityProperties {
public final static String EXT_PROP_NAME = "FBSPlayerData";
/**
* 魔術レベルの最大値
*/
public static final int MAGIC_LEVEL_MAX=50;
/**
* 一般人の魔術レベル最大値
*/
public static final int MAGIC_LEVEL_BASIC_MAX=25;
private int san=99;
private int lvMagic=1;
private double exp=0;
private double next=30;
private String spiritToolName="";
private int spiritToolLv=-1;
private ArrayList<WarpPosition> positions=new ArrayList<WarpPosition>();
private ArrayList<String> decodedBooks=new ArrayList<String>();
private ItemStack[] bindInventory=new ItemStack[40];
private ItemStack[] pocketInventory=new ItemStack[72];
public static void register(EntityPlayer player) {
player.registerExtendedProperties(EXT_PROP_NAME, new FBSEntityProperties());
}
public static FBSEntityProperties get(EntityPlayer player) {
return (FBSEntityProperties)player.getExtendedProperties(EXT_PROP_NAME);
}
@Override
public void saveNBTData(NBTTagCompound compound) {
NBTTagCompound nbt=new NBTTagCompound();
nbt.setInteger("SAN", san);
nbt.setInteger("LvMagic", lvMagic);
nbt.setDouble("EXP", exp);
nbt.setDouble("Next", next);
nbt.setString("SpiritToolName", spiritToolName);
nbt.setInteger("SpiritToolLevel", spiritToolLv);
NBTTagList tags=new NBTTagList();
for(WarpPosition pos : positions){
NBTTagCompound n=new NBTTagCompound();
pos.writeToNBT(n);
tags.appendTag(n);
}
nbt.setTag("WarpPositions", tags);
tags=new NBTTagList();
for (int i=0;i<bindInventory.length;i++){
if (bindInventory[i] != null){
NBTTagCompound nbt1 = new NBTTagCompound();
nbt1.setByte("Slot", (byte) i);
bindInventory[i].writeToNBT(nbt1);
tags.appendTag(nbt1);
}
}
nbt.setTag("BindInventory", tags);
tags=new NBTTagList();
for (int i=0;i<pocketInventory.length;i++){
if (pocketInventory[i] != null){
NBTTagCompound nbt1 = new NBTTagCompound();
nbt1.setByte("Slot", (byte) i);
pocketInventory[i].writeToNBT(nbt1);
tags.appendTag(nbt1);
}
}
nbt.setTag("PocketInventory", tags);
tags=new NBTTagList();
for(String s : decodedBooks){
NBTTagCompound nbt1=new NBTTagCompound();
nbt1.setString("Name", s);
tags.appendTag(nbt1);
}
nbt.setTag("DecodedBooks", tags);
compound.setTag(EXT_PROP_NAME, nbt);
}
@Override
public void loadNBTData(NBTTagCompound compound) {
NBTTagCompound nbt=compound.getCompoundTag(EXT_PROP_NAME);
san=nbt.getInteger("SAN");
lvMagic=nbt.getInteger("LvMagic");
exp=nbt.getDouble("EXP");
next=nbt.getDouble("Next");
spiritToolName=nbt.getString("SpiritToolName");
spiritToolLv=nbt.getInteger("SpiritToolLevel");
positions.clear();
if(nbt.hasKey("WarpPositions")){
NBTTagList tags=(NBTTagList)nbt.getTag("WarpPositions");
for(int i=0;i<tags.tagCount();i++){
positions.add(new WarpPosition(tags.getCompoundTagAt(i)));
}
}
NBTTagList nbttaglist = (NBTTagList)nbt.getTag("BindInventory");
bindInventory = new ItemStack[bindInventory.length];
for (int i=0;i<nbttaglist.tagCount();i++){
NBTTagCompound nbt1 = nbttaglist.getCompoundTagAt(i);
byte b0 = nbt1.getByte("Slot");
if (b0>=0 && b0<bindInventory.length){
bindInventory[b0] = ItemStack.loadItemStackFromNBT(nbt1);
}
}
nbttaglist = (NBTTagList)nbt.getTag("PocketInventory");
pocketInventory = new ItemStack[72];
for (int i=0;i<nbttaglist.tagCount();i++){
NBTTagCompound nbt1 = nbttaglist.getCompoundTagAt(i);
byte b0 = nbt1.getByte("Slot");
if (b0>=0 && b0<pocketInventory.length){
pocketInventory[b0] = ItemStack.loadItemStackFromNBT(nbt1);
}
}
if(nbt.hasKey("DecodedBooks")){
decodedBooks=new ArrayList<String>();
nbttaglist=(NBTTagList)nbt.getTag("DecodedBooks");
for(int i=0;i<nbttaglist.tagCount();i++){
NBTTagCompound nbt1=nbttaglist.getCompoundTagAt(i);
decodedBooks.add(nbt1.getString("Name"));
}
}
}
@Override
public void init(Entity entity, World world) {}
public int getMagicLevelMax(){
return MAGIC_LEVEL_BASIC_MAX+(getSpiritToolLevel()+1)/2;
}
public int getMaxSanity(){
int m=100-lvMagic-(spiritToolLv/2);
return m<100?(m>5?m:5):99;
}
public int getSanity(){ return san; }
public void setSanity(int s){
san=s;
if(san>getMaxSanity()){
san=getMaxSanity();
}
if(san<0){
san=0;
}
}
public int getMagicLevel(){ return lvMagic; }
public void setMagicLevel(int s){
if(s<1) s=1;
lvMagic=s;
exp=0;
if(lvMagic==1) next=10;
else next=MathHelper.ceiling_double_int(10+Math.exp(0.25*(lvMagic-1)));
}
public double getEXP(){
return exp;
}
public double getNext(){
return next;
}
public void addEXP(double s){
if(s<=0) return;
exp+=s;
while(exp>=next && lvMagic<getMagicLevelMax()){
LvUp();
}
}
public void LvUp(){
lvMagic++;
if(san>getMaxSanity()){
san=getMaxSanity();
}
exp-=next;
//next=MathHelper.ceiling_double_int(10+Math.exp(0.25*(lvMagic-1)));
next+=15*(lvMagic+1);
}
public String getSpiritToolName(){ return spiritToolName; }
public void setSpiritToolName(String s){ spiritToolName=s; }
public int getSpiritToolLevel(){ return spiritToolLv; }
public void setSpiritToolLevel(int l){
if(l<=0 || l>SpiritStatus.LEVEL_MAX) return;
spiritToolLv =l;
}
public void bindPlayerInventory(EntityPlayer player, boolean spiritOnly){
bindInventory=new ItemStack[player.inventory.getSizeInventory()];
if(spiritOnly && SpiritManager.findSpiritToolIndex(player)!=-1){
for(int i=0;i<player.inventory.getSizeInventory();i++){
ItemStack is=player.inventory.getStackInSlot(i);
if(is!=null){
if(spiritOnly){
if(is.getItem() instanceof ISpiritTool){
bindInventory[i]=is.copy();
}
}
else{
bindInventory[i]=is.copy();
}
}
}
}
}
public void copyFromBindInventory(EntityPlayer player){
int size=player.inventory.getSizeInventory();
for(int i=0;i<size && i<bindInventory.length;i++){
if(bindInventory[i]!=null){
if(player.inventory.getStackInSlot(i)==null){
player.inventory.setInventorySlotContents(i, bindInventory[i]);
}
else{
player.inventory.addItemStackToInventory(bindInventory[i]);
}
}
bindInventory[i]=null;
}
}
public void addDecodedBook(String name){
decodedBooks.add(name);
}
public boolean isDecoded(String name){
return decodedBooks.contains(name);
}
public ArrayList<String> getDecodedBooks(){
return decodedBooks;
}
public ArrayList<WarpPosition> getDestinations(){
return positions;
}
public boolean addDestination(int dimId, int x, int y, int z){
WarpPosition wp=new WarpPosition(dimId, x, y, z);
if(!positions.contains(wp)){
positions.add(wp);
return true;
}
return false;
}
public static class WarpPosition{
public String name;
public int dimId;
public int x,y,z;
public WarpPosition(NBTTagCompound nbt){
readFromNBT(nbt);
}
public WarpPosition(int dimId, int x, int y, int z){
this.dimId=dimId;
this.x=x;
this.y=y;
this.z=z;
name=getDimName()+"("+x+","+y+","+z+")";
}
public void setName(String n){
name=n;
}
public String getName(){ return name; }
public boolean canWarp(){
World w=DimensionManager.getWorld(dimId);
if(w==null) return false;
Block b=w.getBlock(x,y,z);
if(b!=BlockCore.magicCore) return false;
TileEntity te=w.getTileEntity(x,y,z);
if(!(te instanceof TileEntityMagicCore)) return false;
return "fbs.warp".equals(((TileEntityMagicCore) te).getCircleName());
}
public String getDimName(){
WorldProvider wp=WorldProvider.getProviderForDimension(dimId);
if(wp==null) return "";
return wp.getDimensionName();
}
public void writeToNBT(NBTTagCompound nbt){
nbt.setString("Name", name);
nbt.setInteger("Dim", dimId);
nbt.setInteger("x", x);
nbt.setInteger("y", y);
nbt.setInteger("z", z);
}
public void readFromNBT(NBTTagCompound nbt){
name=nbt.getString("Name");
dimId=nbt.getInteger("Dim");
x=nbt.getInteger("x");
y=nbt.getInteger("y");
z=nbt.getInteger("z");
}
@Override
public boolean equals(Object obj){
if(!(obj instanceof WarpPosition)) return false;
WarpPosition wp=(WarpPosition)obj;
return dimId==wp.dimId && x==wp.x && y==wp.y && z==wp.z;
}
}
}
|