/
WorldEventHandler.java
468 lines (402 loc) · 20.9 KB
/
WorldEventHandler.java
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
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
package com.camellias.voidaicarcania.util.handlers;
import com.camellias.voidaicarcania.init.ModItems;
import com.camellias.voidaicarcania.network.NetworkHandler;
import com.camellias.voidaicarcania.network.packets.HoldSpacebarMessage;
import com.camellias.voidaicarcania.world.dimension.voidic.TeleporterVoid;
import baubles.api.BaublesApi;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.settings.GameSettings;
import net.minecraft.client.settings.KeyBinding;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Items;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.ItemStack;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.management.PlayerList;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraftforge.client.event.RenderPlayerEvent;
import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.event.entity.living.LivingHurtEvent;
import net.minecraftforge.event.entity.player.AdvancementEvent;
import net.minecraftforge.event.entity.player.AttackEntityEvent;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.PlayerEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent.PlayerTickEvent;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@EventBusSubscriber
public class WorldEventHandler
{
@SubscribeEvent
public static void onPlayerLogin(PlayerEvent.PlayerLoggedInEvent event)
{
event.player.sendMessage(new TextComponentString("\u00A75\u00A7l[Voidaic Arcania:] \u00A7dThis mod is still in BETA. Gameplay info can currently be found on the VA Wiki:"));
event.player.sendMessage(ForgeHooks.newChatWithLinks(" https://github.com/CammiePone/Voidaic-Arcania/wiki"));
}
@SubscribeEvent
public static void onPlayerHurt(LivingHurtEvent event)
{
if(event.getEntityLiving() instanceof EntityPlayerMP && event.getEntityLiving().dimension == 0
&& event.getEntityLiving().getPosition().getY() <= -60)
{
EntityPlayerMP player = (EntityPlayerMP) event.getEntityLiving();
PlayerList playerList = player.getEntityWorld().getMinecraftServer().getPlayerList();
event.setCanceled(true);
playerList.transferPlayerToDimension(player, -64,
new TeleporterVoid((WorldServer) player.getEntityWorld(),
player.posX, 250, player.posZ));
}
if(event.getEntityLiving() instanceof EntityPlayerMP && event.getEntityLiving().dimension == -64
&& event.getEntityLiving().getPosition().getY() <= -60)
{
EntityPlayerMP player = (EntityPlayerMP) event.getEntityLiving();
PlayerList playerList = player.getEntityWorld().getMinecraftServer().getPlayerList();
event.setCanceled(true);
playerList.transferPlayerToDimension(player, -1,
new TeleporterVoid((WorldServer) player.getEntityWorld(),
player.getPosition().getX(), 250, player.getPosition().getZ()));
}
if(event.getEntityLiving() instanceof EntityPlayer)
{
EntityPlayer player = (EntityPlayer) event.getEntityLiving();
//Amulet of Shielding
if(BaublesApi.isBaubleEquipped(player, ModItems.A_SHIELD_AMULET) > -1)
{
/*ItemStack stack = BaublesApi.getBaublesHandler(player).getStackInSlot(0);
if(ModItems.A_SHIELD_AMULET.getDamage(stack) < 3)
{
ModItems.A_SHIELD_AMULET.setDamage(stack, ModItems.A_SHIELD_AMULET.getDamage(stack) + 1);
event.setCanceled(true);
}
if(ModItems.A_SHIELD_AMULET.getDamage(stack) == 3)
{
}*/
if(event.getAmount() > 14F)
{
event.setAmount(14F);
}
}
//Belt of Resistance
if(BaublesApi.isBaubleEquipped(player, ModItems.A_RESISTANCE_BELT) > -1)
{
event.setAmount(event.getAmount() / 2);
}
}
}
@SubscribeEvent
public static void onPlayerAttack(AttackEntityEvent event)
{
EntityPlayer player = event.getEntityPlayer();
//Cowl of The Reaper
if(BaublesApi.isBaubleEquipped(player, ModItems.A_REAPER_COWL) > -1)
{
if(player.getHealth() < player.getMaxHealth())
{
player.heal(1.0F);
}
}
//Charm of Explosive Blows
if(BaublesApi.isBaubleEquipped(player, ModItems.A_VOID_CHARM) > -1)
{
if(!player.world.isRemote)
{
player.world.createExplosion(player, player.posX, player.posY, player.posZ, 3.0F, true);
}
}
//Charm of Removal
if(BaublesApi.isBaubleEquipped(player, ModItems.A_LUCK_CHARM) > -1)
{
if(event.getTarget() instanceof EntityLiving)
{
EntityLiving target = (EntityLiving) event.getTarget();
if(target.hurtResistantTime <= 1)
{
if((player.getHeldItemMainhand().isEmpty() && player.getHeldItemOffhand().isEmpty()) && !player.world.isRemote)
{
if(target.hasItemInSlot(EntityEquipmentSlot.HEAD) || target.hasItemInSlot(EntityEquipmentSlot.CHEST) ||
target.hasItemInSlot(EntityEquipmentSlot.LEGS) || target.hasItemInSlot(EntityEquipmentSlot.FEET))
{
ItemStack head = target.getItemStackFromSlot(EntityEquipmentSlot.HEAD);
ItemStack body = target.getItemStackFromSlot(EntityEquipmentSlot.CHEST);
ItemStack legs = target.getItemStackFromSlot(EntityEquipmentSlot.LEGS);
ItemStack feet = target.getItemStackFromSlot(EntityEquipmentSlot.FEET);
if(!head.isEmpty())
{
if(!body.isEmpty())
{
if(!legs.isEmpty())
{
if(!feet.isEmpty())
{
target.entityDropItem(feet, 1);
target.setItemStackToSlot(EntityEquipmentSlot.FEET, new ItemStack(Items.AIR));
}
else
{
target.entityDropItem(legs, 1);
target.setItemStackToSlot(EntityEquipmentSlot.LEGS, new ItemStack(Items.AIR));
}
}
else
{
target.entityDropItem(body, 1);
target.setItemStackToSlot(EntityEquipmentSlot.CHEST, new ItemStack(Items.AIR));
}
}
else
{
target.entityDropItem(head, 1);
target.setItemStackToSlot(EntityEquipmentSlot.HEAD, new ItemStack(Items.AIR));
}
}
}
}
}
}
if(event.getTarget() instanceof EntityPlayer)
{
EntityPlayer target = (EntityPlayer) event.getTarget();
if(target.hurtResistantTime <= 1)
{
if((player.getHeldItemMainhand().isEmpty() && player.getHeldItemOffhand().isEmpty()) && !player.world.isRemote)
{
if(target.hasItemInSlot(EntityEquipmentSlot.HEAD) || target.hasItemInSlot(EntityEquipmentSlot.CHEST) ||
target.hasItemInSlot(EntityEquipmentSlot.LEGS) || target.hasItemInSlot(EntityEquipmentSlot.FEET))
{
ItemStack head = target.getItemStackFromSlot(EntityEquipmentSlot.HEAD);
ItemStack body = target.getItemStackFromSlot(EntityEquipmentSlot.CHEST);
ItemStack legs = target.getItemStackFromSlot(EntityEquipmentSlot.LEGS);
ItemStack feet = target.getItemStackFromSlot(EntityEquipmentSlot.FEET);
if(!head.isEmpty())
{
if(!body.isEmpty())
{
if(!legs.isEmpty())
{
if(!feet.isEmpty())
{
target.entityDropItem(feet, 1);
target.setItemStackToSlot(EntityEquipmentSlot.FEET, new ItemStack(Items.AIR));
}
else
{
target.entityDropItem(legs, 1);
target.setItemStackToSlot(EntityEquipmentSlot.LEGS, new ItemStack(Items.AIR));
}
}
else
{
target.entityDropItem(body, 1);
target.setItemStackToSlot(EntityEquipmentSlot.CHEST, new ItemStack(Items.AIR));
}
}
else
{
target.entityDropItem(head, 1);
target.setItemStackToSlot(EntityEquipmentSlot.HEAD, new ItemStack(Items.AIR));
}
}
}
}
}
}
}
}
@SubscribeEvent
public static void onAdvancementGet(AdvancementEvent event)
{
if(!event.getEntityPlayer().world.isRemote)
{
EntityPlayerMP player = (EntityPlayerMP) event.getEntityPlayer();
MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();
if(player != null)
{
if(event.getAdvancement() == player.getServer().getAdvancementManager().getAdvancement(new ResourceLocation
("minecraft", "nether/root")))
{
server.getCommandManager().executeCommand(server, "/give " + player.getName() +
" written_book 1 0 {title:\"Of Creation - Vol. III\", author:\"Artemis\", pages:["
+ " \"{text:\\\"To whom it may concern, I've sent you this book to aide you on a quest of mine. After you've grown, I will send you information as to my whereabouts. This quest is fully voluntary, and, if you wish, you may ignore my bidding. But, if you would like power... then please, read on.\\\"}\","
+ " \"{text:\\\"3rd New Moon, 1052 - I've come across a peculiar item... it hails from an unknown origin, and houses odd properties. Transformative properties... I feel further testing will be necessary. The anomaly, at least from my testing, seems to be created by combining\\\"}\","
+ " \"{text:\\\"Glowstone Dust with four pure diamonds, until the diamonds shatter, combining with the nethereal lightsource.\\\"}\","
+ " \"{text:\\\"5th Waxing Crescent, 1052 - I've made an amazing discovery! These shards... when 8 or so are surrounding a cluster of pure diamonds, they create some kind of catalyst! I can feel the energy emanating from it... it's powerful... And that excites me greatly.\\\"}\","
+ " \"{text:\\\"... The rest is missing...\\\"}\"]}");
}
if(event.getAdvancement() == player.getServer().getAdvancementManager().getAdvancement(new ResourceLocation
("voidaicarcania", "transmutation_orb")))
{
server.getCommandManager().executeCommand(server, "/give " + player.getName() +
" written_book 1 0 {title:\"Missing Notes 1\", author:\"Artemis\", pages:["
+ " \"{text:\\\"12th Waning Crescent, 1052 - It's strange... how this orb pulses, every day, drawing my attention away from my other work. As if it's beckoning me to use it. I feel that I should look into its limitations more. By the close of the year, I will know its secrets...\\\"}\","
+ " \"{text:\\\"1st New Moon, 1055 - Strange, how it is, I've spent this past year trying to understand this orb... and now, I have. In an altar made of quartz, I can use it to replicate items, though it seems limited in what it can make. No matter, I'm sure I can surpass it with more tests.\\\"}\"]}");
}
if(event.getAdvancement() == player.getServer().getAdvancementManager().getAdvancement(new ResourceLocation
("voidaicarcania", "altar")))
{
server.getCommandManager().executeCommand(server, "/give " + player.getName() +
" written_book 1 0 {title:\"Missing Notes 2\", author:\"Artemis\", pages:["
+ " \"{text:\\\"4th Quarter Moon, 1055 - Amazing! I can use the altar without the orb! I found that I can combine an ender pearl and breath of a dragon in the altar to create a highly volatile... gaseous liquid! It seems pouring it on something breaks it down\\\"}\","
+ " \"{text:\\\"to the molecular level, even bedrock! Tonight, I will descend below the bedrock, see what I can find. I'll make sure to bring the ingredients for a portal in case I get stuck. I should probably take my wings, as well. Who knows if there's even anything down there?\\\"}\"]}");
}
if(event.getAdvancement() == player.getServer().getAdvancementManager().getAdvancement(new ResourceLocation
("voidaicarcania", "void_shard")))
{
server.getCommandManager().executeCommand(server, "/give " + player.getName() +
" written_book 1 0 {title:\"Missing Notes 3\", author:\"Artemis\", pages:["
+ " \"{text:\\\"5th Quarter Moon, 1055 - While I was in the void, I found these strange shards... they remind me of the blue ones I created around two years ago... I wonder how these behave?\\\"}\","
+ " \"{text:\\\"5th Waning Crescent, 1055 - These are brilliant! I can create that volitile concoction out of these far easier, so I can return to the void later on! I'll have to make sure I'm better prepared next time. I'll prepare for a longer visit this time.\\\"}\","
+ " \"{text:\\\"3rd New Moon, 1056 - Interesting... I can combine 8 of these new crystals with my orb... they seem to... take over, or empower it, perhaps? I'll have to do some more testing with this. Maybe this is my breakthrough I've been looking for?\\\"}\"]}");
}
if(event.getAdvancement() == player.getServer().getAdvancementManager().getAdvancement(new ResourceLocation
("voidaicarcania", "void_orb")))
{
server.getCommandManager().executeCommand(server, "/give " + player.getName() +
" written_book 1 0 {title:\"Missing Notes 4\", author:\"Artemis\", pages:["
+ " \"{text:\\\"3rd New Moon, 1056 - This orb... with its origins of the void, I think it more efficiently uses essence from other items to create new ones. I tested it, and I can create diamonds - DIAMONDS! It's amazing! I wonder what the limits of this new orb are...\\\"}\","
+ " \"{text:\\\"3rd Quarter Moon, 1056 - Disappointingly, it seems that I cannot make much more than I could before... it's not too surprising, if I'm honest, but I'm glad I discovered this new orb. Perhaps one day, I'll find more uses for it.\\\"}\"]}");
}
if(event.getAdvancement() == player.getServer().getAdvancementManager().getAdvancement(new ResourceLocation
("voidaicarcania", "enter_void")))
{
//player.world.playSound(null, player.getPosition(), SoundsHandler.VOID_THEME, SoundCategory.MASTER, 1000.0F, 1.0F);
server.getCommandManager().executeCommand(server, "/give " + player.getName() +
" written_book 1 0 {title:\"Missing Notes 5\", author:\"Artemis\", pages:["
+ " \"{text:\\\"4th Quarter Moon, 1055 - This confounded place... I had thought it would be easier than this. I cannot fly back out the way I came, nor can I create a portal. It seems that it's forcing me to stay, or... go further down? I'll have to try, but first, research!\\\"}\","
+ " \"{text:\\\"4th Waning Crescent, 1055 - These... wraiths. They're immensely powerful. One-on-one, they aren't too bad, but... the moment they group together... I don't think anyone could hope to beat them. They phase through everything, disappear, reappear... This place...\\\"}\","
+ " \"{text:\\\"5th New Moon, 1055 - Today I go further down. This may be a mistake, but hopefully I'm wrong.\\\"}\","
+ " \"{text:\\\"5th New Moon, 1055 - It's strange. I'm back in the nether? It's hot, and I have that same sense of dread, but I'm on bedrock. Is the void an intermediary between our world and this? Is this the top of the nether? At least I can make my portal home now...\\\"}\"]}");
}
if(event.getAdvancement() == player.getServer().getAdvancementManager().getAdvancement(new ResourceLocation
("voidaicarcania", "botany_altar")))
{
server.getCommandManager().executeCommand(server, "/give " + player.getName() +
" written_book 1 0 {title:\"Missing Notes 6\", author:\"Artemis\", pages:["
+ " \"{text:\\\"5th Waxing Crescent, 1055 - In my time visiting the void, I came across two plants which I've never seen before... a weed, and a bloom. I did some extensive testing with them, and found that, in the presence of Wraith Wisp, I can alter them. I've recorded the\\\"}\","
+ " \"{text:\\\"recipes that I've discovered so far, on the following pages. They're all quite... interesting, and perhaps have more uses unbeknownst to me.\\\"}\","
+ " \"{text:\\\"Featherweed - Feather and Void Weed This weed is quite interesting. It's extremely light weight, and seems to have some uses in later herbology.\\\"}\","
+ " \"{text:\\\"Floatshroom - Mushroom and Shulker Bullet An interesting mushroom. I fed a tiny amount to a rabbit, and, surprisingly, it survived. It ended up... floating for a short while.\\\"}\","
+ " \"{text:\\\"Glowgrowth - Netherwart and Glowstone Dust Glowgrowth is an interesting plant. Feeding it to the same rabbit, it began to emit a bright light. Maybe I can find some uses for this...\\\"}\","
+ " \"{text:\\\"Void Melon Seed - Melon Seeds and Void Bulb I decided to try mixing our melons with the void's bulbous fruit. Interestingly, it worked, and made a small melon with properties unknown.\\\"}\","
+ " \"{text:\\\"Moon Mint - Void Crystal and Dark Camellia This leaf, interestingly, seems to help with increasing vision, if only temporarily. I find it quite useful when trying to find small things.\\\"}\","
+ " \"{text:\\\"Neddlesprout - Stick and Cactus Green Dye I wouldn't recommend eating this one. It's spiny to the touch, but the spines are so small, I can't find them to remove them.\\\"}\","
+ " \"{text:\\\"Starbloom - Blaze Powder and Wraith Wisp I dub this the miracle plant! It's, by far, the best possible herb one could eat! I must make more of these. Shame they're so difficult to produce...\\\"}\"]}");
}
}
}
}
@SideOnly(Side.CLIENT)
@SubscribeEvent
public static void onPlayerRender(RenderPlayerEvent.Pre event)
{
EntityPlayer player = event.getEntityPlayer();
World world = event.getEntity().world;
if(world.isRemote)
{
if(BaublesApi.isBaubleEquipped(player, ModItems.A_INVISIBILITY_CLOAK) > -1)
{
event.setCanceled(true);
}
}
}
@SubscribeEvent
public static void onPlayerTick(PlayerTickEvent event)
{
if(event.player.ticksExisted % 10 == 0)
{
if((event.player.dimension == -64 || event.player.dimension == -1) && event.player.posY <= -50)
{
event.player.heal(20.0F);
}
}
if(event.player.dimension == -64)
{
EntityPlayer player = event.player;
World world = player.world;
BlockPos pos = player.getPosition();
BlockPos blockpos = pos.add(0, -1, 0);
IBlockState state = player.world.getBlockState(blockpos);
if(!player.isElytraFlying() || !player.capabilities.isFlying)
{
if(state.getBlock().isPassable(player.world, blockpos))
{
if(world.isRemote)
{
GameSettings settings = Minecraft.getMinecraft().gameSettings;
KeyBinding jump = settings.keyBindJump;
GuiScreen gui = Minecraft.getMinecraft().currentScreen;
if(settings.isKeyDown(jump) && gui == null)
{
NetworkHandler.INSTANCE.sendToAll(new HoldSpacebarMessage(player));
}
}
if(player.isSneaking())
{
player.motionY = -0.25D;
}
if((player.motionY <= 0.2D && player.motionY >= -0.2D))
{
player.motionY = player.motionY / 1.025D;
}
player.setNoGravity(true);
player.jumpMovementFactor *= 1.75F;
player.fallDistance = 0.0F;
}
else
{
player.setNoGravity(false);
}
}
else
{
player.setNoGravity(false);
}
}
else
{
if(event.player.ticksExisted % 20 == 0)
{
event.player.setNoGravity(false);
}
}
if(!event.player.world.isRemote)
{
EntityPlayer player = event.player;
EntityEquipmentSlot head = EntityEquipmentSlot.HEAD;
EntityEquipmentSlot body = EntityEquipmentSlot.CHEST;
EntityEquipmentSlot legs = EntityEquipmentSlot.LEGS;
EntityEquipmentSlot feet = EntityEquipmentSlot.FEET;
if((player.getItemStackFromSlot(head).getItem() == ModItems.ASTRALITE_HELM
&& player.getItemStackFromSlot(body).getItem() == ModItems.ASTRALITE_CHEST
&& player.getItemStackFromSlot(legs).getItem() == ModItems.ASTRALITE_LEGS
&& player.getItemStackFromSlot(feet).getItem() == ModItems.ASTRALITE_BOOTS))
{
if(!player.isElytraFlying() && !player.capabilities.isFlying)
{
if(player.isAirBorne)
{
if(player.motionY < 0.0D)
{
player.motionY *= 0.9D;
}
player.jumpMovementFactor *= 1.3F;
}
}
if(player.fallDistance != 0.0F)
{
player.fallDistance = 0.0F;
}
}
}
}
}