From 794085660ef10c4cc413bb2b8852a489783f4c93 Mon Sep 17 00:00:00 2001
From: Electroblob77 <35599699+Electroblob77@users.noreply.github.com>
Date: Wed, 19 Feb 2020 00:11:33 +0000
Subject: [PATCH] Move screen shaking effect into a proper method in the client
proxy, fix earthquake's version not working and add screen shake to meteor,
lightning hammer and shockwave
---
.../java/electroblob/wizardry/CommonProxy.java | 7 +++++++
.../wizardry/client/ClientProxy.java | 6 +++++-
.../client/WizardryClientEventHandler.java | 18 +++++++++++++++++-
.../wizardry/entity/EntityMeteor.java | 11 +++++++++--
.../entity/construct/EntityEarthquake.java | 13 -------------
.../entity/construct/EntityHammer.java | 7 +++++++
.../electroblob/wizardry/spell/Earthquake.java | 6 ++++++
.../electroblob/wizardry/spell/Shockwave.java | 15 ++++++++++-----
8 files changed, 61 insertions(+), 22 deletions(-)
diff --git a/src/main/java/electroblob/wizardry/CommonProxy.java b/src/main/java/electroblob/wizardry/CommonProxy.java
index 36178e21..63cf5ede 100644
--- a/src/main/java/electroblob/wizardry/CommonProxy.java
+++ b/src/main/java/electroblob/wizardry/CommonProxy.java
@@ -240,6 +240,13 @@ public class CommonProxy {
/** Starts the first-person blink overlay effect for the specified player. */
public void playBlinkEffect(EntityPlayer player){}
+
+ /**
+ * Starts the client-side screen shake effect for the specified player.
+ * @param player The player whose screen is to be shaken
+ * @param intensity The amplitude of the shaking (around 10 looks about right)
+ */
+ public void shakeScreen(EntityPlayer player, float intensity){}
/**
* Gets the client side world using Minecraft.getMinecraft().world. Only to be called client side! Returns
diff --git a/src/main/java/electroblob/wizardry/client/ClientProxy.java b/src/main/java/electroblob/wizardry/client/ClientProxy.java
index c2527b74..7b4f2e6e 100644
--- a/src/main/java/electroblob/wizardry/client/ClientProxy.java
+++ b/src/main/java/electroblob/wizardry/client/ClientProxy.java
@@ -29,7 +29,6 @@ import electroblob.wizardry.item.ItemScroll;
import electroblob.wizardry.item.ItemSpellBook;
import electroblob.wizardry.item.ItemWand;
import electroblob.wizardry.packet.*;
-import electroblob.wizardry.potion.PotionSlowTime;
import electroblob.wizardry.registry.Spells;
import electroblob.wizardry.registry.WizardrySounds;
import electroblob.wizardry.spell.*;
@@ -195,6 +194,11 @@ public class ClientProxy extends CommonProxy {
if(Minecraft.getMinecraft().player == player) WizardryClientEventHandler.playBlinkEffect();
}
+ @Override
+ public void shakeScreen(EntityPlayer player, float intensity){
+ if(Minecraft.getMinecraft().player == player) WizardryClientEventHandler.shakeScreen(intensity);
+ }
+
@Override
public Set getSpellHUDSkins(){
return GuiSpellDisplay.getSkinKeys();
diff --git a/src/main/java/electroblob/wizardry/client/WizardryClientEventHandler.java b/src/main/java/electroblob/wizardry/client/WizardryClientEventHandler.java
index 74dbedb1..00972eca 100644
--- a/src/main/java/electroblob/wizardry/client/WizardryClientEventHandler.java
+++ b/src/main/java/electroblob/wizardry/client/WizardryClientEventHandler.java
@@ -68,11 +68,21 @@ public final class WizardryClientEventHandler {
private static int blinkEffectTimer;
/** The number of ticks the blink effect lasts for. */
private static final int BLINK_EFFECT_DURATION = 8;
+
+ /** The remaining time for which the screen shake effect will be active. */
+ private static int screenShakeCounter = 0;
+ private static final float SHAKINESS = 0.5f;
- /** Starts the first person blink overlay effect. */
+ /** Starts the first-person blink overlay effect. */
public static void playBlinkEffect(){
blinkEffectTimer = BLINK_EFFECT_DURATION;
}
+
+ /** Starts the client-side screen shake effect. */
+ public static void shakeScreen(float intensity){
+ screenShakeCounter = (int)(intensity / SHAKINESS);
+ Minecraft.getMinecraft().player.rotationPitch -= intensity * 0.5f; // Start halfway down
+ }
@SubscribeEvent
public static void onPlayerTickEvent(TickEvent.PlayerTickEvent event){
@@ -81,6 +91,12 @@ public final class WizardryClientEventHandler {
if(blinkEffectTimer > 0) blinkEffectTimer--;
+ if(screenShakeCounter > 0){
+ float magnitude = screenShakeCounter * SHAKINESS;
+ Minecraft.getMinecraft().player.rotationPitch += screenShakeCounter % 2 == 0 ? magnitude : -magnitude;
+ screenShakeCounter--;
+ }
+
// Only seems to work here...
// EntityLiving victim = Possession.getPossessee(Minecraft.getMinecraft().player);
// if(victim != null && victim.getHeldItemMainhand().isEmpty()){
diff --git a/src/main/java/electroblob/wizardry/entity/EntityMeteor.java b/src/main/java/electroblob/wizardry/entity/EntityMeteor.java
index f41d63ad..938e5c16 100644
--- a/src/main/java/electroblob/wizardry/entity/EntityMeteor.java
+++ b/src/main/java/electroblob/wizardry/entity/EntityMeteor.java
@@ -5,9 +5,11 @@ import electroblob.wizardry.registry.Spells;
import electroblob.wizardry.registry.WizardryBlocks;
import electroblob.wizardry.registry.WizardrySounds;
import electroblob.wizardry.spell.Meteor;
+import electroblob.wizardry.util.WizardryUtilities;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.MoverType;
import net.minecraft.entity.item.EntityFallingBlock;
+import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.SoundCategory;
import net.minecraft.world.World;
@@ -61,9 +63,9 @@ public class EntityMeteor extends EntityFallingBlock {
this.motionY *= 0.9800000190734863D;
this.motionZ *= 0.9800000190734863D;
- if(!this.world.isRemote){
+ if(this.onGround){
- if(this.onGround){
+ if(!this.world.isRemote){
this.motionX *= 0.699999988079071D;
this.motionZ *= 0.699999988079071D;
@@ -72,8 +74,13 @@ public class EntityMeteor extends EntityFallingBlock {
Spells.meteor.getProperty(Meteor.BLAST_STRENGTH).floatValue() * blastMultiplier,
damageBlocks, damageBlocks);
this.setDead();
+
+ }else{
+ WizardryUtilities.getEntitiesWithinRadius(15, posX, posY, posZ, world, EntityPlayer.class)
+ .forEach(p -> Wizardry.proxy.shakeScreen(p, 10));
}
}
+
}
@Override
diff --git a/src/main/java/electroblob/wizardry/entity/construct/EntityEarthquake.java b/src/main/java/electroblob/wizardry/entity/construct/EntityEarthquake.java
index 2a6f455a..19dd083c 100644
--- a/src/main/java/electroblob/wizardry/entity/construct/EntityEarthquake.java
+++ b/src/main/java/electroblob/wizardry/entity/construct/EntityEarthquake.java
@@ -7,7 +7,6 @@ import electroblob.wizardry.util.MagicDamage.DamageType;
import electroblob.wizardry.util.WizardryUtilities;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityFallingBlock;
-import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.MobEffects;
import net.minecraft.network.play.server.SPacketEntityVelocity;
@@ -97,18 +96,6 @@ public class EntityEarthquake extends EntityMagicConstruct {
}
}
}
-
- if(!world.isRemote){
- // Constant 15 blocks for now
- List targets2 = WizardryUtilities.getEntitiesWithinRadius(15, posX, posY, posZ, world, EntityPlayer.class);
-
- float magnitude = 10f * ((float)(this.lifetime - this.ticksExisted))/(float)this.lifetime;
-
- // Makes the screen shake
- for(EntityPlayer target : targets2){
- target.rotationPitch += this.ticksExisted % 2 == 0 ? magnitude : -magnitude;
- }
- }
}
}
diff --git a/src/main/java/electroblob/wizardry/entity/construct/EntityHammer.java b/src/main/java/electroblob/wizardry/entity/construct/EntityHammer.java
index 8aa12a20..328a4077 100644
--- a/src/main/java/electroblob/wizardry/entity/construct/EntityHammer.java
+++ b/src/main/java/electroblob/wizardry/entity/construct/EntityHammer.java
@@ -169,6 +169,7 @@ public class EntityHammer extends EntityMagicConstruct {
public void fall(float distance, float damageMultiplier){
if(world.isRemote){
+
for(int i = 0; i < 40; i++){
double particleX = this.posX - 1.0d + 2 * rand.nextDouble();
double particleZ = this.posZ - 1.0d + 2 * rand.nextDouble();
@@ -180,6 +181,12 @@ public class EntityHammer extends EntityMagicConstruct {
particleX - this.posX, 0, particleZ - this.posZ, Block.getStateId(block));
}
}
+
+ if(this.fallDistance > 10){
+ WizardryUtilities.getEntitiesWithinRadius(10, posX, posY, posZ, world, EntityPlayer.class)
+ .forEach(p -> Wizardry.proxy.shakeScreen(p, 6));
+ }
+
}else{
// Just to check the hammer has actually fallen from the sky, rather than the block under it being broken.
if(this.fallDistance > 10){
diff --git a/src/main/java/electroblob/wizardry/spell/Earthquake.java b/src/main/java/electroblob/wizardry/spell/Earthquake.java
index 946358be..2c9ae2b8 100644
--- a/src/main/java/electroblob/wizardry/spell/Earthquake.java
+++ b/src/main/java/electroblob/wizardry/spell/Earthquake.java
@@ -1,5 +1,6 @@
package electroblob.wizardry.spell;
+ import electroblob.wizardry.Wizardry;
import electroblob.wizardry.entity.construct.EntityEarthquake;
import electroblob.wizardry.registry.WizardryItems;
import electroblob.wizardry.util.SpellModifiers;
@@ -7,6 +8,7 @@
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
+ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.EnumAction;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumParticleTypes;
@@ -53,6 +55,10 @@
world.spawnParticle(EnumParticleTypes.BLOCK_DUST, particleX, y,
particleZ, particleX - x, 0, particleZ - z, Block.getStateId(block));
}
+
+ WizardryUtilities.getEntitiesWithinRadius(15, x, y, z, world, EntityPlayer.class)
+ .forEach(p -> Wizardry.proxy.shakeScreen(p, 12));
+
}
return super.spawnConstruct(world, x, y, z, side, caster, modifiers);
diff --git a/src/main/java/electroblob/wizardry/spell/Shockwave.java b/src/main/java/electroblob/wizardry/spell/Shockwave.java
index abfd6767..2d3d89c7 100644
--- a/src/main/java/electroblob/wizardry/spell/Shockwave.java
+++ b/src/main/java/electroblob/wizardry/spell/Shockwave.java
@@ -41,12 +41,17 @@ public class Shockwave extends Spell {
for(EntityLivingBase target : targets){
- if(target instanceof EntityPlayer && (!Wizardry.settings.playersMoveEachOther
- || ItemArtefact.isArtefactActive((EntityPlayer)target, WizardryItems.amulet_anchoring))){
+ if(target instanceof EntityPlayer){
- if(!world.isRemote) caster.sendStatusMessage(new TextComponentTranslation("spell.resist",
- target.getName(), this.getNameForTranslationFormatted()), true);
- return false;
+ Wizardry.proxy.shakeScreen((EntityPlayer)target, 10);
+
+ if(!Wizardry.settings.playersMoveEachOther) continue;
+
+ if(ItemArtefact.isArtefactActive((EntityPlayer)target, WizardryItems.amulet_anchoring)){
+ if(!world.isRemote) caster.sendStatusMessage(new TextComponentTranslation("spell.resist",
+ target.getName(), this.getNameForTranslationFormatted()), true);
+ continue;
+ }
}
if(AllyDesignationSystem.isValidTarget(caster, target)){