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
|
package jp.plusplus.fbs.tileentity;
import jp.plusplus.fbs.Registry;
import net.minecraft.block.BlockEndPortal;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.Packet;
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.biome.BiomeGenBase;
import net.minecraftforge.common.BiomeManager;
import java.util.Random;
/**
* Created by plusplus_F on 2015/11/09.
* 10秒ごとに1つ成長する
*/
public class TileEntityHavestable extends TileEntity {
public int glowingTicks;
public int age;
public int ageMax;
public int meta;
public TileEntityHavestable(){
ageMax=60;
}
public TileEntityHavestable(int ageMax, int meta){
this();
this.ageMax=ageMax;
this.meta=meta;
}
//---------------------------------------------------------------------------------------------------------
public boolean canGlow(){
if(age>=ageMax) return false;
BiomeGenBase bgb=worldObj.getBiomeGenForCoords(xCoord, zCoord);
boolean flag=false;
if(meta==0){
//ベースハーブはどこでも育つ
flag=true;
}
else if(meta==4){
//ソウルハーブは狭間なら育つ
flag=bgb==Registry.biomeCrack;
}
else if(meta==5){
//マンドレイクはy=32未満で育つ
flag=yCoord<32 && yCoord!=worldObj.getHeightValue(xCoord, zCoord);
}
else if(meta==6){
//ゴールドハーブはy=20未満で育つ
flag=yCoord<20 && yCoord!=worldObj.getHeightValue(xCoord, zCoord);
}
else if(meta==7){
//エンダーハーブはエンドなら育つ
flag=worldObj.provider.dimensionId==1;
}
else if(meta==8){
//エクスプローシブハーブはネザーなら育つ
flag=worldObj.provider.dimensionId==-1;
}
else{
//直射日光があたらなければ育つ
flag=yCoord!=worldObj.getHeightValue(xCoord, zCoord);
if(!flag){
switch (meta){
case 1:
//ブラッディハーブは温暖なら育つ
for(BiomeManager.BiomeEntry be : BiomeManager.getBiomes(BiomeManager.BiomeType.WARM)){
if(bgb==be.biome){
flag=true;
break;
}
}
break;
case 2:
//マナハーブは秋なら育つ
flag=bgb==Registry.biomeAutumn;
break;
case 3:
//スタミナハーブは砂漠なら育つ
flag=(bgb==BiomeGenBase.desert || bgb==BiomeGenBase.desertHills || bgb==BiomeGenBase.savanna || bgb==BiomeGenBase.savannaPlateau || bgb==BiomeGenBase.mesa || bgb==BiomeGenBase.mesaPlateau|| bgb==BiomeGenBase.mesaPlateau_F);
if(!flag){
for(BiomeManager.BiomeEntry be : BiomeManager.getBiomes(BiomeManager.BiomeType.DESERT)){
if(bgb==be.biome){
flag=true;
break;
}
}
}
break;
}
}
}
return flag;
}
public boolean canHarvest(){
return age>=ageMax;
}
public void glow(Random rand){
age+=1+rand.nextInt(3);
}
public void onHarvest(){
age=0;
markDirty();
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
//---------------------------------------------------------------------------------------------------------
@Override
public void readFromNBT(NBTTagCompound par1NBTTagCompound){
super.readFromNBT(par1NBTTagCompound);
age=par1NBTTagCompound.getInteger("Age");
ageMax=par1NBTTagCompound.getInteger("AgeMax");
glowingTicks=par1NBTTagCompound.getInteger("GlowingTicks");
meta=par1NBTTagCompound.getInteger("Meta");
}
@Override
public void writeToNBT(NBTTagCompound par1NBTTagCompound){
super.writeToNBT(par1NBTTagCompound);
par1NBTTagCompound.setInteger("Age", age);
par1NBTTagCompound.setInteger("AgeMax", ageMax);
par1NBTTagCompound.setInteger("GlowingTicks", glowingTicks);
par1NBTTagCompound.setInteger("Meta", meta);
}
@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(){
if(!worldObj.isRemote) {
glowingTicks++;
if (glowingTicks >= 200) {
glowingTicks = 0;
if (canGlow()) {
age++;
if (age > ageMax) {
age = ageMax;
}
markDirty();
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
}
}
}
}
|