Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 25 additions & 5 deletions src/main/java/am2/client/handlers/ClientTickHandler.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package am2.client.handlers;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.*;

import am2.ArsMagica2;
import am2.api.extensions.ISpellCaster;
Expand All @@ -17,7 +13,10 @@
import am2.common.armor.ArmorHelper;
import am2.common.armor.infusions.GenericImbuement;
import am2.common.bosses.BossSpawnHelper;
import am2.common.buffs.BuffEffect;
import am2.common.defs.AMPotion;
import am2.common.defs.ItemDefs;
import am2.common.defs.PotionEffectsDefs;
import am2.common.extensions.EntityExtension;
import am2.common.items.ItemSpellBase;
import am2.common.items.ItemSpellBook;
Expand All @@ -31,13 +30,15 @@
import am2.common.trackers.EntityItemWatcher;
import am2.common.utils.DimensionUtilities;
import am2.common.world.MeteorSpawnHelper;
import com.google.common.collect.Maps;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumHand;
Expand All @@ -52,6 +53,7 @@
@SideOnly(Side.CLIENT)
public class ClientTickHandler{
public static HashMap<EntityLiving, EntityLivingBase> targetsToSet = new HashMap<EntityLiving, EntityLivingBase>();
private final Map<Potion, BuffEffect> clientBuffs = Maps.<Potion, BuffEffect>newHashMap();
private int mouseWheelValue = 0;
private int currentSlot = -1;
private boolean usingItem;
Expand Down Expand Up @@ -332,6 +334,24 @@ public void onServerTick(TickEvent.ServerTickEvent event){
localServerTick_End();
}
}

@SubscribeEvent
public void onPlayerTick(TickEvent.PlayerTickEvent event){
if (!event.player.worldObj.isRemote)
return;

for (PotionEffect effect : event.player.getActivePotionEffects()){
Potion potion = effect.getPotion();
if (potion instanceof AMPotion){
BuffEffect clientBuff = clientBuffs.get(potion);
if (clientBuff == null) {
clientBuff = (BuffEffect) PotionEffectsDefs.getEffect(effect);
clientBuffs.put(potion, clientBuff);
}
clientBuff.performClientEffect(event.player);
}
}
}

public void setDWheel(int dWheel, int slot, boolean usingItem){
this.mouseWheelValue = dWheel;
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/am2/common/buffs/BuffEffect.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

import net.minecraft.client.resources.I18n;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public abstract class BuffEffect extends PotionEffect{
protected boolean InitialApplication;
Expand Down Expand Up @@ -35,6 +38,14 @@ private void effectEnding(EntityLivingBase entityliving){
@Override
public void performEffect(EntityLivingBase entityliving){
}

/**
* This method is called from PlayerTickEvent
* to do some things, that needs client-side to work (e.g. swift swim)
*/
@SideOnly(Side.CLIENT)
public void performClientEffect(EntityPlayer entityPlayer){
}

@Override
public void combine(PotionEffect potioneffect){
Expand Down
44 changes: 35 additions & 9 deletions src/main/java/am2/common/buffs/BuffEffectSwiftSwim.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,44 @@ public void stopEffect(EntityLivingBase entityliving){

@Override
public void performEffect(EntityLivingBase entityliving){
if (entityliving.isInWater()){
if (!(entityliving instanceof EntityPlayer) || !((EntityPlayer)entityliving).capabilities.isFlying){
entityliving.motionX *= (1.133f + 0.03 * this.getAmplifier());
entityliving.motionZ *= (1.133f + 0.03 * this.getAmplifier());

if (entityliving.motionY > 0){
entityliving.motionY *= 1.134;
}
if (entityliving.isInWater() && !(entityliving instanceof EntityPlayer)){
entityliving.motionX *= (1.133f + 0.03 * this.getAmplifier());
entityliving.motionZ *= (1.133f + 0.03 * this.getAmplifier());

if (entityliving.motionY > 0){
entityliving.motionY *= 1.134;
}
}
}


@Override
public void performClientEffect(EntityPlayer entityPlayer){
//the maximum player motion in X or Z: 0.1178
//when sprinting: 0.15319
if (entityPlayer.isInWater() && !entityPlayer.capabilities.isFlying){
float maxSpeed = entityPlayer.isSprinting() ? 0.15319f : 0.1178f;

entityPlayer.motionX *= (1.133f + 0.03 * this.getAmplifier());
entityPlayer.motionZ *= (1.133f + 0.03 * this.getAmplifier());

//we can do it with the module of speed vector. not now
if (entityPlayer.motionX < -maxSpeed){
entityPlayer.motionX = -maxSpeed;
}else if (entityPlayer.motionX > maxSpeed){
entityPlayer.motionX = maxSpeed;
}
if (entityPlayer.motionZ < -maxSpeed){
entityPlayer.motionZ = -maxSpeed;
}else if (entityPlayer.motionZ > maxSpeed){
entityPlayer.motionZ = maxSpeed;
}

if (entityPlayer.motionY > 0){
entityPlayer.motionY *= 1.134;
}
}
}

@Override
protected String spellBuffName(){
return "Swift Swim";
Expand Down