/
EventHandleStandAbilities.java
354 lines (325 loc) · 15.8 KB
/
EventHandleStandAbilities.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
package com.novarch.jojomod.events;
import com.novarch.jojomod.JojoBizarreSurvival;
import com.novarch.jojomod.capabilities.stand.Stand;
import com.novarch.jojomod.capabilities.timestop.Timestop;
import com.novarch.jojomod.config.JojoBizarreSurvivalConfig;
import com.novarch.jojomod.entities.fakePlayer.FakePlayerEntity;
import com.novarch.jojomod.entities.stands.aerosmith.EntityAerosmith;
import com.novarch.jojomod.entities.stands.starPlatinum.EntityStarPlatinum;
import com.novarch.jojomod.entities.stands.theWorld.EntityTheWorld;
import com.novarch.jojomod.events.custom.AbilityEvent;
import com.novarch.jojomod.events.custom.StandEvent;
import com.novarch.jojomod.events.custom.StandPunchEvent;
import com.novarch.jojomod.init.EffectInit;
import com.novarch.jojomod.init.ItemInit;
import com.novarch.jojomod.init.SoundInit;
import com.novarch.jojomod.network.message.client.CSyncAerosmithPacket;
import com.novarch.jojomod.objects.items.ItemStandDisc;
import com.novarch.jojomod.util.JojoLibs;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraft.entity.IProjectile;
import net.minecraft.entity.MobEntity;
import net.minecraft.entity.item.ItemEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.projectile.DamagingProjectileEntity;
import net.minecraft.potion.Effects;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.StringTextComponent;
import net.minecraft.world.GameType;
import net.minecraftforge.client.event.RenderPlayerEvent;
import net.minecraftforge.event.TickEvent;
import net.minecraftforge.event.entity.item.ItemTossEvent;
import net.minecraftforge.event.entity.living.PotionEvent;
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import java.util.ArrayList;
import java.util.List;
@SuppressWarnings("ConstantConditions")
@Mod.EventBusSubscriber(modid = JojoBizarreSurvival.MOD_ID, bus = Mod.EventBusSubscriber.Bus.FORGE)
public class EventHandleStandAbilities
{
public static List<Entity> removalQueue = new ArrayList<>();
@SubscribeEvent
public static void onPlayerTick(TickEvent.PlayerTickEvent event)
{
PlayerEntity player = event.player;
if(!player.isPotionActive(Effects.GLOWING) && !player.isPotionActive(EffectInit.CRIMSON.get()))
player.setGlowing(false);
Stand.getLazyOptional(player).ifPresent(props -> {
if(props.getCooldown() == 0.5)
props.setTimeLeft(1000);
if(props.getStandID() == JojoLibs.StandID.GER)
player.clearActivePotions();
if(!props.getStandOn())
{
if(props.getCooldown() > 0)
props.subtractCooldown(0.5);
if(props.getTimeLeft() < 1000)
props.addTimeLeft(0.5);
player.setInvulnerable(false);
}
else if(props.getStandOn() && !props.getAbility())
{
if(props.getCooldown() > 0)
props.subtractCooldown(0.5);
if(props.getTimeLeft() < 1000)
props.addTimeLeft(0.5);
}
});
}
@SubscribeEvent
public static void effectAddedEvent(PotionEvent.PotionAddedEvent event)
{
if(event.getPotionEffect().getPotion() == EffectInit.CRIMSON.get())
event.getEntityLiving().setGlowing(true);
}
@SubscribeEvent
public static void effectRemovedEvent(PotionEvent.PotionRemoveEvent event)
{
if(event.getPotion() == EffectInit.CRIMSON.get())
event.getEntityLiving().setGlowing(false);
if(event.getPotion() == Effects.GLOWING)
event.getEntityLiving().setGlowing(false);
if(event.getPotion() == EffectInit.OXYGEN_POISONING.get())
event.setCanceled(true);
if(event.getPotion() == EffectInit.HAZE.get())
event.setCanceled(true);
}
@SubscribeEvent
public static void effectExpiredEvent(PotionEvent.PotionExpiryEvent event)
{
if(event.getPotionEffect().getPotion() == null)
return;
if(event.getPotionEffect().getPotion() == EffectInit.CRIMSON.get())
event.getEntityLiving().setGlowing(false);
if(event.getPotionEffect().getPotion() == Effects.GLOWING)
event.getEntityLiving().setGlowing(false);
}
@SubscribeEvent
public static void clientTick(TickEvent.ClientTickEvent event) {
if (Minecraft.getInstance().player == null)
return;
if (event.phase == TickEvent.Phase.START)
return;
PlayerEntity player = Minecraft.getInstance().player;
Stand.getLazyOptional(player).ifPresent(props -> {
if (!props.getStandOn() || !props.getAbility())
if (!player.isSpectator())
Minecraft.getInstance().setRenderViewEntity(player);
});
assert Minecraft.getInstance().world != null;
Minecraft.getInstance().world.getAllEntities().forEach(entity -> {
if (entity instanceof EntityAerosmith)
if (((EntityAerosmith) entity).getMaster() != null)
if (player.getEntityId() == ((EntityAerosmith) entity).getMaster().getEntityId()) {
float yaw = (float) Minecraft.getInstance().mouseHelper.getMouseX();
float pitch = (float) Minecraft.getInstance().mouseHelper.getMouseY();
if (pitch > 89.0f)
pitch = 89.0f;
else if (pitch < -89.0f)
pitch = -89.0f;
if (entity.rotationYaw != yaw && entity.rotationPitch != pitch)
JojoBizarreSurvival.INSTANCE.sendToServer(new CSyncAerosmithPacket(yaw, pitch));
}
});
}
@SubscribeEvent
public static void serverTick(TickEvent.ServerTickEvent event)
{
if(event.phase == TickEvent.Phase.END) {
removalQueue.forEach(Entity::remove);
removalQueue.clear();
}
}
@SubscribeEvent
public static void tooltipEvent(ItemTooltipEvent event)
{
String standName = "";
if(event.getItemStack().getTag() != null)
switch(event.getItemStack().getTag().getInt("StandID")) {
case JojoLibs.StandID.kingCrimson: {
standName = "King Crimson";
break;
}
case JojoLibs.StandID.dirtyDeedsDoneDirtCheap: {
standName = "D4C";
break;
}
case JojoLibs.StandID.goldExperience: {
standName = "Gold Experience";
break;
}
case JojoLibs.StandID.madeInHeaven: {
standName = "Made in Heaven";
break;
}
case JojoLibs.StandID.GER: {
standName = "Gold Experience Requiem";
break;
}
case JojoLibs.StandID.aerosmith: {
standName = "Aerosmith";
break;
}
case JojoLibs.StandID.weatherReport: {
standName = "Weather Report";
break;
}
case JojoLibs.StandID.killerQueen: {
standName = "Killer Queen";
break;
}
case JojoLibs.StandID.crazyDiamond: {
standName = "Crazy Diamond";
break;
}
case JojoLibs.StandID.purpleHaze: {
standName = "Purple Haze";
break;
}
case JojoLibs.StandID.theEmperor: {
standName = "The Emperor";
break;
}
case JojoLibs.StandID.whitesnake: {
standName = "Whitesnake";
break;
}
case JojoLibs.StandID.cMoon: {
standName = "C-Moon";
break;
}
case JojoLibs.StandID.theWorld: {
standName = "The World";
break;
}
case JojoLibs.StandID.starPlatinum: {
standName = "Star Platinum";
break;
}
case JojoLibs.StandID.silverChariot: {
standName = "Silver Chariot";
break;
}
}
if(event.getItemStack().getItem() instanceof ItemStandDisc)
if(!standName.equals(""))
event.getToolTip().add(new StringTextComponent(standName));
}
@SubscribeEvent
public static void throwawayEvent(ItemTossEvent event)
{
if(event.getEntityItem().getItem().getItem() == ItemInit.the_emperor.get()) {
event.setCanceled(true);
Stand.getLazyOptional(event.getPlayer()).ifPresent(props -> props.setStandOn(false));
}
}
@SubscribeEvent
public static void standUnsummoned(StandEvent.StandUnsummonedEvent event) {
PlayerEntity player = event.getPlayer();
Stand.getLazyOptional(player).ifPresent(props -> {
player.setInvulnerable(false);
player.setNoGravity(false);
if (!player.isCreative() && !player.isSpectator())
player.setGameType(GameType.SURVIVAL);
if (player.isPotionActive(EffectInit.CRIMSON_USER.get()))
player.removePotionEffect(EffectInit.CRIMSON_USER.get());
if (!player.world.isRemote) {
player.world.getServer().getWorld(player.dimension).getEntities()
.filter(entity -> entity instanceof FakePlayerEntity)
.filter(entity -> ((FakePlayerEntity) entity).getParent() == player)
.forEach(Entity::remove);
}
if (player.world.isRemote) {
if (props.getStandID() == JojoLibs.StandID.aerosmith)
if (!(Minecraft.getInstance().getRenderViewEntity() instanceof PlayerEntity)) {
Minecraft.getInstance().setRenderViewEntity(player);
Minecraft.getInstance().gameSettings.thirdPersonView = 0;
}
}
if(props.getStandID() == JojoLibs.StandID.theWorld) {
if(props.getAbility() && props.getTimeLeft() > 780)
player.world.playSound(null, new BlockPos(player.getPosX(), player.getPosY(), player.getPosZ()), SoundInit.RESUME_TIME.get(), SoundCategory.NEUTRAL, 5.0f, 1.0f);
EntityTheWorld.theWorld=null;
EntityTheWorld.dayTime = -1;
EntityTheWorld.gameTime = -1;
if (!player.world.isRemote)
player.world.getServer().getWorld(player.dimension).getEntities()
.filter(entity -> entity != player)
.forEach(entity -> Timestop.getLazyOptional(entity).ifPresent(props2 -> {
if ((entity instanceof IProjectile || entity instanceof ItemEntity || entity instanceof DamagingProjectileEntity) && (props2.getMotionX() != 0 && props2.getMotionY() != 0 && props2.getMotionZ() != 0)) {
entity.setMotion(props2.getMotionX(), props2.getMotionY(), props2.getMotionZ());
entity.setNoGravity(false);
} else {
if (props2.getMotionX() != 0 && props2.getMotionY() != 0 && props2.getMotionZ() != 0)
entity.setMotion(props2.getMotionX(), props2.getMotionY(), props2.getMotionZ());
}
if (entity instanceof MobEntity)
((MobEntity) entity).setNoAI(false);
entity.setMotion(props2.getMotionX(), props2.getMotionY(), props2.getMotionZ());
entity.velocityChanged = true;
entity.fallDistance = props2.getFallDistance();
entity.setInvulnerable(false);
props2.clear();
}));
} else if(props.getStandID() == JojoLibs.StandID.starPlatinum) {
if(props.getAbility() && props.getTimeLeft() > 900)
player.world.playSound(null, new BlockPos(player.getPosX(), player.getPosY(), player.getPosZ()), SoundInit.TIME_RESUME_STAR_PLATINUM.get(), SoundCategory.NEUTRAL, 5.0f, 1.0f);
EntityStarPlatinum.starPlatinum=null;
EntityStarPlatinum.dayTime = -1;
EntityStarPlatinum.gameTime = -1;
if (!player.world.isRemote)
player.world.getServer().getWorld(player.dimension).getEntities()
.filter(entity -> entity != player)
.forEach(entity -> Timestop.getLazyOptional(entity).ifPresent(props2 -> {
if ((entity instanceof IProjectile || entity instanceof ItemEntity || entity instanceof DamagingProjectileEntity) && (props2.getMotionX() != 0 && props2.getMotionY() != 0 && props2.getMotionZ() != 0)) {
entity.setMotion(props2.getMotionX(), props2.getMotionY(), props2.getMotionZ());
entity.setNoGravity(false);
} else {
if (props2.getMotionX() != 0 && props2.getMotionY() != 0 && props2.getMotionZ() != 0)
entity.setMotion(props2.getMotionX(), props2.getMotionY(), props2.getMotionZ());
}
if (entity instanceof MobEntity)
((MobEntity) entity).setNoAI(false);
entity.setMotion(props2.getMotionX(), props2.getMotionY(), props2.getMotionZ());
entity.velocityChanged = true;
entity.fallDistance = props2.getFallDistance();
entity.setInvulnerable(false);
props2.clear();
}));
}
});
}
@SubscribeEvent
public static void abilityOff(AbilityEvent.AbilityDeactivated event) {
PlayerEntity player = event.getPlayer();
assert player != null;
Stand.getLazyOptional(player).ifPresent(props -> {
if(props.getStandID() == JojoLibs.StandID.aerosmith)
if(!(Minecraft.getInstance().getRenderViewEntity() instanceof PlayerEntity)) {
Minecraft.getInstance().setRenderViewEntity(player);
Minecraft.getInstance().gameSettings.thirdPersonView = 0;
}
});
}
@SubscribeEvent
public static void standPunchEntityEvent(StandPunchEvent.EntityHit event) {
if(!JojoBizarreSurvivalConfig.COMMON.standPunchDamage.get())
event.setCanceled(true);
}
@SubscribeEvent
public static void standPunchBlockEvent(StandPunchEvent.BlockHit event) {
if(!JojoBizarreSurvivalConfig.COMMON.standPunchBlockBreaking.get())
event.setCanceled(true);
}
@SubscribeEvent
public static void renderPlayer(RenderPlayerEvent.Pre event) {
Stand.getLazyOptional(event.getPlayer()).ifPresent(props -> {
if(props.getStandID() == JojoLibs.StandID.aerosmith && props.getStandOn() && props.getAbility())
event.setCanceled(true);
});
}
}