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
|
package jp.plusplus.fbs.tileentity;
import jp.plusplus.fbs.container.inventory.InventoryMagic;
import jp.plusplus.fbs.entity.EntityButterfly;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.Packet;
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
/**
* Created by pluslus_F on 2015/06/17.
*/
public class TileEntityMagicCore extends TileEntity {
public int ticks;
protected String circleName="null";
protected int circleRadius;
public InventoryMagic inv;
public int progressMax;
public int progress;
public void setInventory(InventoryMagic inv){
this.inv=inv;
}
public void removeInventory(){
inv=null;
}
public void setProgressMax(int p){
progressMax=p;
markDirty();
}
public void resetProgress(){
progress=0;
progressMax=0;
markDirty();
}
@Override
public void readFromNBT(NBTTagCompound par1NBTTagCompound){
super.readFromNBT(par1NBTTagCompound);
circleName=par1NBTTagCompound.getString("CircleName");
circleRadius= par1NBTTagCompound.getInteger("CircleRadius");
progress=par1NBTTagCompound.getInteger("Progress");
progressMax=par1NBTTagCompound.getInteger("ProgressMax");
}
@Override
public void writeToNBT(NBTTagCompound par1NBTTagCompound){
super.writeToNBT(par1NBTTagCompound);
par1NBTTagCompound.setString("CircleName", circleName);
par1NBTTagCompound.setInteger("CircleRadius", circleRadius);
par1NBTTagCompound.setInteger("Progress", progress);
par1NBTTagCompound.setInteger("ProgressMax", progressMax);
}
@Override
public Packet getDescriptionPacket() {
NBTTagCompound nbtTagCompound = new NBTTagCompound();
this.writeToNBT(nbtTagCompound);
return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 1, nbtTagCompound);
}
@Override
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) {
this.readFromNBT(pkt.func_148857_g());
}
@Override
public void updateEntity() {
ticks++;
if(worldObj.isRemote) return;
if(inv!=null && progressMax>0){
progress++;
if(progress>=progressMax){
inv.work();
progress=0;
}
}
if (ticks % 60 != 0) return;
//checking magic
if (circleName.equals("null")) return;
int bx = xCoord - circleRadius, bz = zCoord - circleRadius;
int size = 2 * circleRadius + 1;
for (int i = 0; i < size; i++) {
for (int k = 0; k < size; k++) {
if (i == size / 2 && i == k) continue;
if (!worldObj.isAirBlock(bx + k, yCoord, bz + i) && worldObj.isBlockNormalCubeDefault(bx+k, yCoord, bz+i, false)) {
setMagicCircle("null", 1);
markDirty();
return;
}
}
}
/*
if(ticks%180!=0 || worldObj.rand.nextFloat()<=0.8f) return;
EntityButterfly eb=new EntityButterfly(worldObj, xCoord, yCoord+1, zCoord);
worldObj.spawnEntityInWorld(eb);
*/
}
public void setMagicCircle(String name, int radius){
circleName=(name==null?"null":name);
circleRadius=radius;
markDirty();
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
public void clearCharms() {
if (circleName.equals("null")) return;
int bx = xCoord - circleRadius, bz = zCoord - circleRadius;
int size = 2 * circleRadius + 1;
for (int i = 0; i < size; i++) {
for (int k = 0; k < size; k++) {
if (i == size / 2 && i == k) continue;
worldObj.setBlockToAir(bx + k, yCoord, bz + i);
}
}
}
public String getCircleName(){
return circleName;
}
public int getCircleRadius(){
return circleRadius;
}
}
|