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
|
package darkknight.jewelrycraft.tileentity;
import java.util.ArrayList;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
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;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import darkknight.jewelrycraft.block.BlockHandPedestal;
import darkknight.jewelrycraft.block.BlockList;
import darkknight.jewelrycraft.config.ConfigHandler;
import darkknight.jewelrycraft.particles.EntityShadowsFX;
import darkknight.jewelrycraft.util.JewelryNBT;
import darkknight.jewelrycraft.util.JewelrycraftUtil;
import darkknight.jewelrycraft.util.PlayerUtils;
import darkknight.jewelrycraft.util.Variables;
public class TileEntityShadowEye extends TileEntity
{
public int opening, timer, t = 20;
public boolean active, shouldAddData;
public ArrayList<ItemStack> pedestalItems = new ArrayList<ItemStack>();
ResourceLocation particleTexture = new ResourceLocation(Variables.MODID, "textures/particle/shadows.png");
public EntityPlayer target;
public TileEntityShadowEye()
{
opening = 1;
timer = 20;
active = false;
}
/**
* @param nbt
*/
@Override
public void writeToNBT(NBTTagCompound nbt)
{
super.writeToNBT(nbt);
nbt.setInteger("opening", opening);
nbt.setInteger("timer", timer);
nbt.setBoolean("active", active);
nbt.setBoolean("shouldAddData", shouldAddData);
}
/**
* @param nbt
*/
@Override
public void readFromNBT(NBTTagCompound nbt)
{
super.readFromNBT(nbt);
opening = nbt.getInteger("opening");
timer = nbt.getInteger("timer");
active = nbt.getBoolean("active");
shouldAddData = nbt.getBoolean("shouldAddData");
}
/**
*
*/
@Override
public void updateEntity()
{
super.updateEntity();
boolean valid = isValidStructure(worldObj, xCoord, yCoord, zCoord, blockMetadata);
if (active) timer--;
if (active && target != null && this.getDistanceFrom(target.posX, target.posY, target.posZ) > 30D){
active = false;
timer = -1;
shouldAddData = false;
}
if (opening == 4 && timer <= 0) active = false;
if (!active && timer <= 0 && opening != 1){
if (t > 0) t--;
if (t <= 0){
opening--;
t = 20;
}
}
if (opening == 2 && timer <= 0 && t == 10 && shouldAddData){
addData(worldObj, xCoord, yCoord, zCoord);
TileEntityHandPedestal target = (TileEntityHandPedestal)worldObj.getTileEntity(xCoord, yCoord - 3, zCoord);
if (target != null && target.getHeldItemStack() != null) JewelryNBT.addModifiers(target.getHeldItemStack(), pedestalItems);
}
if (active && timer <= 0){
if (opening < 4){
opening++;
timer = 20;
}
if (valid && opening == 4) timer = ConfigHandler.RITUAL_TIME;
else if (!valid){
active = false;
timer = -1;
}
}
for(Object player: worldObj.getEntitiesWithinAABB(EntityPlayer.class, getRenderBoundingBox().expand(10D, 10D, 10D)))
if (player != null){
NBTTagCompound persistTag = PlayerUtils.getModPlayerPersistTag((EntityPlayer)player, Variables.MODID);
persistTag.setBoolean("nearStartedRitual", false);
}
if (active && opening == 4){
float din = 6F;
int i = Minecraft.getMinecraft().gameSettings.particleSetting;
for(float x = -din; x <= din; x += 0.2F)
for(float z = -din; z <= din; z += 0.2F)
if (x * x + z * z >= din * din - 1 && x * x + z * z <= din * din + 1) Minecraft.getMinecraft().effectRenderer.addEffect(new EntityShadowsFX(worldObj, xCoord + x + 0.5F, yCoord - 0.5F, zCoord + z + 0.5F, 15F, 0.04F - 0.01F * i, particleTexture));
for(int l = 0; l <= 2 - i; l++)
worldObj.spawnParticle("depthsuspend", xCoord + 6.5F - worldObj.rand.nextInt(9) - worldObj.rand.nextFloat(), yCoord - 2F + worldObj.rand.nextFloat(), zCoord + 6.5F - worldObj.rand.nextInt(9) - worldObj.rand.nextFloat(), 0, 0, 0);
for(Object player: worldObj.getEntitiesWithinAABB(EntityPlayer.class, getRenderBoundingBox().expand(10D, 10D, 10D)))
if (player != null){
NBTTagCompound persistTag = PlayerUtils.getModPlayerPersistTag((EntityPlayer)player, Variables.MODID);
persistTag.setBoolean("nearStartedRitual", true);
}
}
}
/**
* @param world
* @param x
* @param y
* @param z
* @param metadata
* @return
*/
public boolean isValidStructure(World world, int x, int y, int z, int metadata)
{
if (world.getBlockMetadata(x, y, z) == 0 || world.getBlockMetadata(x, y, z) == 2){
// Layers from top to bottom
// 1st Layer
if (world.getBlock(x, y + 1, z) != Blocks.stone_slab || world.getBlockMetadata(x, y + 1, z) != 5) return false;
if (world.getBlock(x + 1, y + 1, z) != Blocks.stone_slab || world.getBlockMetadata(x + 1, y + 1, z) != 5) return false;
if (world.getBlock(x - 1, y + 1, z) != Blocks.stone_slab || world.getBlockMetadata(x - 1, y + 1, z) != 5) return false;
// 2nd Layer
if (world.getBlock(x + 2, y, z) != Blocks.stone_brick_stairs || world.getBlockMetadata(x + 2, y, z) != 1) return false;
if (world.getBlock(x + 1, y, z) != Blocks.stone_brick_stairs || world.getBlockMetadata(x + 1, y, z) != 4) return false;
if (world.getBlock(x - 1, y, z) != Blocks.stone_brick_stairs || world.getBlockMetadata(x - 1, y, z) != 5) return false;
if (world.getBlock(x - 2, y, z) != Blocks.stone_brick_stairs || world.getBlockMetadata(x - 2, y, z) != 0) return false;
// 3rd Layer
if (world.getBlock(x + 2, y - 1, z) != Blocks.stonebrick) return false;
if (world.getBlock(x - 2, y - 1, z) != Blocks.stonebrick) return false;
// 4th Layer
if (world.getBlock(x + 2, y - 2, z) != Blocks.stonebrick) return false;
if (world.getBlock(x - 2, y - 2, z) != Blocks.stonebrick) return false;
// 5th Layer
if (world.getBlock(x + 2, y - 3, z) != Blocks.stonebrick) return false;
if (world.getBlock(x - 2, y - 3, z) != Blocks.stonebrick) return false;
}else if (world.getBlockMetadata(x, y, z) == 1 || world.getBlockMetadata(x, y, z) == 3){
// Layers from top to bottom
// 1st Layer
if (world.getBlock(x, y + 1, z) != Blocks.stone_slab || world.getBlockMetadata(x, y + 1, z) != 5) return false;
if (world.getBlock(x, y + 1, z + 1) != Blocks.stone_slab || world.getBlockMetadata(x, y + 1, z + 1) != 5) return false;
if (world.getBlock(x, y + 1, z - 1) != Blocks.stone_slab || world.getBlockMetadata(x, y + 1, z - 1) != 5) return false;
// 2nd Layer
if (world.getBlock(x, y, z + 2) != Blocks.stone_brick_stairs || world.getBlockMetadata(x, y, z + 2) != 3) return false;
if (world.getBlock(x, y, z + 1) != Blocks.stone_brick_stairs || world.getBlockMetadata(x, y, z + 1) != 6) return false;
if (world.getBlock(x, y, z - 1) != Blocks.stone_brick_stairs || world.getBlockMetadata(x, y, z - 1) != 7) return false;
if (world.getBlock(x, y, z - 2) != Blocks.stone_brick_stairs || world.getBlockMetadata(x, y, z - 2) != 2) return false;
// 3rd Layer
if (world.getBlock(x, y - 1, z + 2) != Blocks.stonebrick) return false;
if (world.getBlock(x, y - 1, z - 2) != Blocks.stonebrick) return false;
// 4th Layer
if (world.getBlock(x, y - 2, z + 2) != Blocks.stonebrick) return false;
if (world.getBlock(x, y - 2, z - 2) != Blocks.stonebrick) return false;
// 5th Layer
if (world.getBlock(x, y - 3, z + 2) != Blocks.stonebrick) return false;
if (world.getBlock(x, y - 3, z - 2) != Blocks.stonebrick) return false;
}
// 3rd Layer
if (world.getBlock(x - 4, y - 1, z - 4) != BlockList.shadowBlock) return false;
if (world.getBlock(x - 4, y - 1, z + 4) != BlockList.shadowBlock) return false;
if (world.getBlock(x + 4, y - 1, z - 4) != BlockList.shadowBlock) return false;
if (world.getBlock(x + 4, y - 1, z + 4) != BlockList.shadowBlock) return false;
// 4th Layer
if (world.getBlock(x - 4, y - 2, z - 4) != Blocks.stonebrick) return false;
if (world.getBlock(x - 4, y - 2, z + 4) != Blocks.stonebrick) return false;
if (world.getBlock(x + 4, y - 2, z - 4) != Blocks.stonebrick) return false;
if (world.getBlock(x + 4, y - 2, z + 4) != Blocks.stonebrick) return false;
// 5th Layer
// Pillars
if (world.getBlock(x - 4, y - 3, z - 4) != Blocks.stonebrick) return false;
if (world.getBlock(x - 4, y - 3, z + 4) != Blocks.stonebrick) return false;
if (world.getBlock(x + 4, y - 3, z - 4) != Blocks.stonebrick) return false;
if (world.getBlock(x + 4, y - 3, z + 4) != Blocks.stonebrick) return false;
// Pedestals
if (!(world.getBlock(x, y - 3, z) instanceof BlockHandPedestal)) return false;
if (world.getBlock(x - 4, y - 3, z + 2) != BlockList.handPedestal || world.getBlockMetadata(x - 4, y - 3, z + 2) != 1) return false;
if (world.getBlock(x - 5, y - 3, z) != BlockList.handPedestal || world.getBlockMetadata(x - 5, y - 3, z) != 2) return false;
if (world.getBlock(x - 4, y - 3, z - 2) != BlockList.handPedestal || world.getBlockMetadata(x - 4, y - 3, z - 2) != 3) return false;
if (world.getBlock(x - 2, y - 3, z - 4) != BlockList.handPedestal || world.getBlockMetadata(x - 2, y - 3, z - 4) != 3) return false;
if (world.getBlock(x, y - 3, z - 5) != BlockList.handPedestal || world.getBlockMetadata(x, y - 3, z - 5) != 4) return false;
if (world.getBlock(x + 2, y - 3, z - 4) != BlockList.handPedestal || world.getBlockMetadata(x + 2, y - 3, z - 4) != 5) return false;
if (world.getBlock(x + 4, y - 3, z - 2) != BlockList.handPedestal || world.getBlockMetadata(x + 4, y - 3, z - 2) != 5) return false;
if (world.getBlock(x + 5, y - 3, z) != BlockList.handPedestal || world.getBlockMetadata(x + 5, y - 3, z) != 6) return false;
if (world.getBlock(x + 4, y - 3, z + 2) != BlockList.handPedestal || world.getBlockMetadata(x + 4, y - 3, z + 2) != 7) return false;
if (world.getBlock(x + 2, y - 3, z + 4) != BlockList.handPedestal || world.getBlockMetadata(x + 2, y - 3, z + 4) != 7) return false;
if (world.getBlock(x, y - 3, z + 5) != BlockList.handPedestal || world.getBlockMetadata(x, y - 3, z + 5) != 0) return false;
if (world.getBlock(x - 2, y - 3, z + 4) != BlockList.handPedestal || world.getBlockMetadata(x - 2, y - 3, z + 4) != 1) return false;
return true;
}
/**
* @param world
* @param x
* @param y
* @param z
*/
public void addData(World world, int x, int y, int z)
{
pedestalItems.clear();
addPedestalInfo((TileEntityHandPedestal)world.getTileEntity(x + 2, y - 3, z - 4));
addPedestalInfo((TileEntityHandPedestal)world.getTileEntity(x - 4, y - 3, z + 2));
addPedestalInfo((TileEntityHandPedestal)world.getTileEntity(x, y - 3, z - 5));
addPedestalInfo((TileEntityHandPedestal)world.getTileEntity(x - 2, y - 3, z - 4));
addPedestalInfo((TileEntityHandPedestal)world.getTileEntity(x - 4, y - 3, z - 2));
addPedestalInfo((TileEntityHandPedestal)world.getTileEntity(x - 5, y - 3, z));
addPedestalInfo((TileEntityHandPedestal)world.getTileEntity(x + 4, y - 3, z - 2));
addPedestalInfo((TileEntityHandPedestal)world.getTileEntity(x + 5, y - 3, z));
addPedestalInfo((TileEntityHandPedestal)world.getTileEntity(x + 4, y - 3, z + 2));
addPedestalInfo((TileEntityHandPedestal)world.getTileEntity(x + 2, y - 3, z + 4));
addPedestalInfo((TileEntityHandPedestal)world.getTileEntity(x, y - 3, z + 5));
addPedestalInfo((TileEntityHandPedestal)world.getTileEntity(x - 2, y - 3, z + 4));
}
/**
* @param pedestal
*/
public void addPedestalInfo(TileEntityHandPedestal pedestal)
{
ItemStack heldItemStack;
if (pedestal != null && (heldItemStack = pedestal.getHeldItemStack()) != null){
if (pedestalItems.isEmpty()) pedestalItems.add(heldItemStack.copy());
else{
boolean hasItem = false;
int index = 0;
for(int ind = 0; ind < pedestalItems.size() && !hasItem; ind++)
if (heldItemStack.getItem().equals(pedestalItems.get(ind).getItem()) && heldItemStack.getItemDamage() == pedestalItems.get(ind).getItemDamage()){
index = ind;
hasItem = true;
if (heldItemStack.hasTagCompound() && pedestalItems.get(ind).hasTagCompound() && !heldItemStack.getTagCompound().equals(pedestalItems.get(ind).getTagCompound())) hasItem = false;
}
if (!hasItem) pedestalItems.add(heldItemStack.copy());
else{
ItemStack object = pedestalItems.get(index).copy();
object.stackSize++;
pedestalItems.set(index, object);
}
}
pedestal.removeHeldItemStack();
pedestal.openHand();
}
else if(pedestal != null && target != null) JewelrycraftUtil.addCursePoints(target, 20);
}
/**
* @return
*/
@Override
public Packet getDescriptionPacket()
{
NBTTagCompound nbttagcompound = new NBTTagCompound();
writeToNBT(nbttagcompound);
return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 1, nbttagcompound);
}
/**
* @param net
* @param packet
*/
@Override
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity packet)
{
readFromNBT(packet.func_148857_g());
worldObj.func_147479_m(xCoord, yCoord, zCoord);
}
}
|