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
|
package fyresmodjam.blocks;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import fyresmodjam.ModjamMod;
import fyresmodjam.blessings.BlessingUtils;
import fyresmodjam.handlers.CommonTickHandler;
import fyresmodjam.handlers.NewPacketHandler;
import fyresmodjam.items.ItemTrap;
import fyresmodjam.misc.ConfigData;
import fyresmodjam.tileentities.TileEntityTrap;
import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.monster.EntityMob;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.server.MinecraftServer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.DamageSource;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.Vec3;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraftforge.common.IShearable;
import net.minecraftforge.common.util.ForgeDirection;
public class BlockTrap extends BlockContainer implements IShearable {
public static int trapTypes = 3;
public BlockTrap() {
super(Material.circuits);
setLightOpacity(0);
}
@Override
@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister par1IconRegister) {
blockIcon = par1IconRegister.registerIcon("fyresmodjam:spikes2");
}
public int idDropped(int par1, Random par2Random, int par3) {
return 0;
}
@Override
public ItemStack getPickBlock(MovingObjectPosition object, World par1World, int par2, int par3, int par4) {
return new ItemStack(ModjamMod.blockTrap);
}
@Override
public boolean canHarvestBlock(EntityPlayer par1EntityPlayer, int par2) {
return false;
}
@Override
public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer,
int par6, float par7, float par8, float par9) {
if (par5EntityPlayer.getHeldItem() == null) {
TileEntity te = par1World.getTileEntity(par2, par3, par4);
if (!par5EntityPlayer.isSneaking() && te != null && te instanceof TileEntityTrap
&& ((TileEntityTrap) te).placedBy != null
&& ((TileEntityTrap) te).placedBy.equals(par5EntityPlayer.getCommandSenderName())) {
if (!par1World.isRemote) {
((TileEntityTrap) te).setting++;
if (((TileEntityTrap) te).setting >= TileEntityTrap.settings.length) {
((TileEntityTrap) te).setting = 0;
}
te.markDirty();
NewPacketHandler.SEND_MESSAGE.sendToPlayer(par5EntityPlayer,
"\u00A7e\u00A7oSet to: " + TileEntityTrap.settings[((TileEntityTrap) te).setting] + ".");
}
} else if (par1World.isRemote) {
NewPacketHandler.DISARM_TRAP.sendToServer(par2, par3, par4,
BlessingUtils.hasBlessing(par5EntityPlayer, "BlessingMechanic"));
}
}
return true;
}
@Override
@SideOnly(Side.CLIENT)
public boolean shouldSideBeRendered(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5) {
return false;
}
@Override
public boolean isOpaqueCube() {
return false;
}
@Override
public boolean hasTileEntity(int metadata) {
return true;
}
@Override
public TileEntity createNewTileEntity(World world, int i) {
return new TileEntityTrap();
}
@Override
public int getMobilityFlag() {
return 2;
}
@Override
public void addCollisionBoxesToList(World par1World, int par2, int par3, int par4, AxisAlignedBB par5AxisAlignedBB,
List par6List, Entity par7Entity) {
}
@Override
public AxisAlignedBB getCollisionBoundingBoxFromPool(World par1World, int par2, int par3, int par4) {
return super.getCollisionBoundingBoxFromPool(par1World, par2, par3, par4);
}
@Override
@SideOnly(Side.CLIENT)
public MovingObjectPosition collisionRayTrace(World par1World, int par2, int par3, int par4, Vec3 par5Vec3,
Vec3 par6Vec3) {
EntityPlayer player = Minecraft.getMinecraft().thePlayer;
TileEntity te = par1World.getTileEntity(par2, par3, par4);
return (player != null && te instanceof TileEntityTrap
&& (((TileEntityTrap) te).placedBy != null || !NewPacketHandler.trapsDisabled)
&& (player.getCommandSenderName().equals(((TileEntityTrap) te).placedBy) || player.isSneaking()
|| (BlessingUtils.hasBlessing(player, "MarkScouting"))))
? super.collisionRayTrace(par1World, par2, par3, par4, par5Vec3, par6Vec3)
: null;
}
@Override
public void onEntityCollidedWithBlock(World par1World, int par2, int par3, int par4, Entity par5Entity) {
TileEntity te = par1World.getTileEntity(par2, par3, par4);
boolean b1 = (((TileEntityTrap) te).placedBy == null
|| !par5Entity.getCommandSenderName().equals(((TileEntityTrap) te).placedBy));
boolean b2 = ((TileEntityTrap) te).setting != 3
&& (!(par5Entity instanceof EntityPlayer) || ((TileEntityTrap) te).setting < 2);
boolean b3 = (ConfigData.spawnTraps || ((TileEntityTrap) te).placedBy != null);
boolean b4 = ((par5Entity instanceof EntityPlayer && !((EntityPlayer) par5Entity).capabilities.isCreativeMode)
|| par5Entity instanceof EntityMob);
if (!par1World.isRemote && par5Entity.ridingEntity == null && te != null && te instanceof TileEntityTrap && b1
&& b2 && b3 && b4) {
int type = par1World.getBlockMetadata(par2, par3, par4);
boolean scout = BlessingUtils.hasBlessing(par5Entity, "MarkScouting");
if (par5Entity instanceof EntityPlayer) {
if (type % trapTypes == 0) {
par5Entity.attackEntityFrom(DamageSource.cactus, 8.0F + (scout ? 2.0F : 0.0F));
if (ModjamMod.r.nextInt(8 - (scout ? 2 : 0)) == 0) {
((EntityLivingBase) par5Entity)
.addPotionEffect(new PotionEffect(Potion.poison.id, 100 + (scout ? 25 : 0), 1));
}
} else if (type % trapTypes == 1) {
if (!par5Entity.isBurning()) {
par5Entity.setFire(10 + (scout ? 2 : 0));
}
} else if (type % trapTypes == 2) {
((EntityLivingBase) par5Entity)
.addPotionEffect(new PotionEffect(Potion.blindness.id, 200 + (scout ? 50 : 0), 1));
((EntityLivingBase) par5Entity)
.addPotionEffect(new PotionEffect(Potion.moveSlowdown.id, 200 + (scout ? 50 : 0), 1));
}
if (CommonTickHandler.worldData.getDisadvantage().equals("Explosive Traps")) {
par5Entity.worldObj.setBlockToAir(par2, par3, par4);
par5Entity.worldObj.createExplosion(null, par2 + 0.5F, par3 + 0.5F, par4 + 0.5F, 1.33F, true);
}
par1World.setBlockToAir(par2, par3, par4);
NewPacketHandler.SEND_MESSAGE.sendToPlayer((EntityPlayer) par5Entity,
"\u00A7c\u00A7oYou triggered a " + ItemTrap.names[type % trapTypes].toLowerCase() + "!");
} else {
if (type % trapTypes == 0) {
par5Entity.attackEntityFrom(DamageSource.cactus, 2.0F);
if (ModjamMod.r.nextInt(32) == 0) {
((EntityLivingBase) par5Entity).addPotionEffect(new PotionEffect(Potion.poison.id, 100, 1));
}
} else if (type % trapTypes == 1) {
if (!par5Entity.isBurning()) {
par5Entity.setFire(5);
}
} else if (type % trapTypes == 2) {
((EntityLivingBase) par5Entity).addPotionEffect(new PotionEffect(Potion.blindness.id, 100, 1));
((EntityLivingBase) par5Entity).addPotionEffect(new PotionEffect(Potion.moveSlowdown.id, 100, 1));
}
}
}
}
@Override
public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, Block par5) {
super.onNeighborBlockChange(par1World, par2, par3, par4, par5);
if (!par1World.isRemote && !par1World.isSideSolid(par2, par3 - 1, par4, ForgeDirection.SOUTH, true)) {
par1World.setBlockToAir(par2, par3, par4);
TileEntity te = par1World.getTileEntity(par2, par3, par4);
if ((ConfigData.spawnTraps
|| (te != null && te instanceof TileEntityTrap && ((TileEntityTrap) te).placedBy != null))
&& CommonTickHandler.worldData != null
&& CommonTickHandler.worldData.getDisadvantage().equals("Explosive Traps")) {
par1World.createExplosion(null, par2 + 0.5F, par3 + 0.5F, par4 + 0.5F, 1.33F, true);
}
}
}
@Override
public boolean isReplaceable(IBlockAccess world, int x, int y, int z) {
TileEntity te = world.getTileEntity(x, y, z);
return super.isReplaceable(world, x, y, z)
|| (((world instanceof World && ((World) world).isRemote) ? NewPacketHandler.trapsDisabled
: !ConfigData.spawnTraps)
&& (te == null || !(te instanceof TileEntityTrap) || ((TileEntityTrap) te).placedBy == null));
}
@Override
@SideOnly(Side.CLIENT)
public boolean isCollidable() {
return super.isCollidable();
}
@Override
public boolean canPlaceBlockAt(World world, int x, int y, int z) {
return super.canPlaceBlockAt(world, x, y, z) && (y == 0 || world.getBlock(x, y - 1, z) != ModjamMod.blockTrap);
}
@Override
public int damageDropped(int par1) {
return par1 % trapTypes;
}
@Override
@SideOnly(Side.CLIENT)
public void getSubBlocks(Item par1, CreativeTabs par2CreativeTabs, List par3List) {
for (int i = 0; i < trapTypes; i++) {
par3List.add(new ItemStack(par1, 1, i));
}
}
@Override
public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLivingBase par5EntityLivingBase,
ItemStack par6ItemStack) {
super.onBlockPlacedBy(par1World, par2, par3, par4, par5EntityLivingBase, par6ItemStack);
par1World.setBlockMetadataWithNotify(par2, par3, par4, par6ItemStack.getItemDamage(), 0);
if (par5EntityLivingBase != null && par5EntityLivingBase instanceof EntityPlayer) {
EntityPlayer player = (EntityPlayer) par5EntityLivingBase;
if (!player.capabilities.isCreativeMode || NewPacketHandler.trapsDisabled) {
TileEntity te = par1World.getTileEntity(par2, par3, par4);
if (te != null && te instanceof TileEntityTrap) {
((TileEntityTrap) te).placedBy = player.getCommandSenderName();
}
}
}
}
@Override
public boolean isShearable(ItemStack item, IBlockAccess blockAccess, int x, int y, int z) {
return true;
}
@Override
public ArrayList<ItemStack> onSheared(ItemStack item, IBlockAccess blockAccess, int x, int y, int z, int fortune) {
if (blockAccess instanceof World) {
World world = (World) blockAccess;
world.setBlockToAir(x, y, z);
if (!world.isRemote) {
MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();
for (int i = 0; i < server.worldServers.length; i++) {
WorldServer s = FMLCommonHandler.instance().getMinecraftServerInstance().worldServers[i];
if (s == null) {
continue;
}
for (Object o : s.playerEntities) {
if (o == null || !(o instanceof EntityPlayer)) {
continue;
}
EntityPlayer player = (EntityPlayer) o;
if (item.equals(player.getHeldItem())) {
NewPacketHandler.SEND_MESSAGE.sendToPlayer(player, "\u00A7e\u00A7oYou disarmed the trap.");
}
}
}
}
item.attemptDamageItem(119, ModjamMod.r);
}
return new ArrayList<ItemStack>();
}
@Override
public float getPlayerRelativeBlockHardness(EntityPlayer par1EntityPlayer, World par2World, int par3, int par4,
int par5) {
return (par1EntityPlayer.getHeldItem() != null && par1EntityPlayer.getHeldItem().getItem() == Items.shears)
? 1.0F
: getBlockHardness(par2World, par3, par4, par5);
}
}
|