Fixed the Speed and Jump rituals so that they correctly update the player's motion

This commit is contained in:
WayofTime 2016-04-13 11:05:17 -04:00
parent 81e9452a21
commit c0b39039cc
6 changed files with 115 additions and 29 deletions

View file

@ -8,6 +8,8 @@ Version 2.0.0-32
- Added True Strike, increasing the damage of critical hits
- Updated for Forge 12.16.0.1859
- Did some work on the Sentient Bow to start adding abilities to it
- Fixed the Speed and Jump rituals so that they correctly update the player's motion.
------------------------------------------------------
Version 2.0.0-31
------------------------------------------------------

View file

@ -17,6 +17,7 @@ public class BloodMagicPacketHandler
{
INSTANCE.registerMessage(ChatUtil.PacketNoSpamChat.Handler.class, ChatUtil.PacketNoSpamChat.class, 0, Side.CLIENT);
INSTANCE.registerMessage(ItemRouterButtonPacketProcessor.class, ItemRouterButtonPacketProcessor.class, 1, Side.SERVER);
INSTANCE.registerMessage(PlayerVelocityPacketProcessor.class, PlayerVelocityPacketProcessor.class, 2, Side.CLIENT);
}
public static void sendToAllAround(IMessage message, TileEntity te, int range)

View file

@ -0,0 +1,67 @@
package WayofTime.bloodmagic.network;
import io.netty.buffer.ByteBuf;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.network.PacketBuffer;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class PlayerVelocityPacketProcessor implements IMessage, IMessageHandler<PlayerVelocityPacketProcessor, IMessage>
{
private double motionX;
private double motionY;
private double motionZ;
public PlayerVelocityPacketProcessor()
{
}
public PlayerVelocityPacketProcessor(double motionX, double motionY, double motionZ)
{
this.motionX = motionX;
this.motionY = motionY;
this.motionZ = motionZ;
}
@Override
public void fromBytes(ByteBuf buffer)
{
PacketBuffer buff = new PacketBuffer(buffer);
motionX = buff.readDouble();
motionY = buff.readDouble();
motionZ = buff.readDouble();
}
@Override
public void toBytes(ByteBuf buffer)
{
PacketBuffer buff = new PacketBuffer(buffer);
buff.writeDouble(motionX);
buff.writeDouble(motionY);
buff.writeDouble(motionZ);
}
@Override
public IMessage onMessage(PlayerVelocityPacketProcessor message, MessageContext ctx)
{
if (ctx.side == Side.CLIENT)
{
message.onMessageFromServer();
}
return null;
}
@SideOnly(Side.CLIENT)
public void onMessageFromServer()
{
EntityPlayer player = Minecraft.getMinecraft().thePlayer;
player.motionX = motionX;
player.motionY = motionY;
player.motionZ = motionZ;
}
}

View file

@ -4,6 +4,7 @@ import WayofTime.bloodmagic.api.Constants;
import WayofTime.bloodmagic.api.network.SoulNetwork;
import WayofTime.bloodmagic.api.ritual.*;
import WayofTime.bloodmagic.api.util.helper.NetworkHelper;
import WayofTime.bloodmagic.util.Utils;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
@ -53,20 +54,18 @@ public class RitualJumping extends Ritual
double motionY = 1.5;
if (entity instanceof EntityPlayer && entity instanceof EntityPlayerMP)
entity.fallDistance = 0;
if (entity.isSneaking())
{
((EntityPlayerMP) entity).fallDistance = 0;
if (entity.isSneaking())
continue;
((EntityPlayerMP) entity).motionY = motionY;
totalEffects++;
} else
continue;
}
entity.motionY = motionY;
totalEffects++;
if (entity instanceof EntityPlayer)
{
entity.fallDistance = 0;
if (entity.isSneaking())
continue;
entity.motionY = motionY;
totalEffects++;
Utils.setPlayerSpeedFromServer((EntityPlayer) entity, entity.motionX, entity.motionY, entity.motionZ);
}
}
}

View file

@ -1,15 +1,21 @@
package WayofTime.bloodmagic.ritual;
import java.util.ArrayList;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import WayofTime.bloodmagic.api.Constants;
import WayofTime.bloodmagic.api.network.SoulNetwork;
import WayofTime.bloodmagic.api.ritual.*;
import WayofTime.bloodmagic.api.ritual.AreaDescriptor;
import WayofTime.bloodmagic.api.ritual.EnumRuneType;
import WayofTime.bloodmagic.api.ritual.IMasterRitualStone;
import WayofTime.bloodmagic.api.ritual.Ritual;
import WayofTime.bloodmagic.api.ritual.RitualComponent;
import WayofTime.bloodmagic.api.util.helper.NetworkHelper;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.world.World;
import java.util.ArrayList;
import WayofTime.bloodmagic.util.Utils;
public class RitualSpeed extends Ritual
{
@ -78,6 +84,10 @@ public class RitualSpeed extends Ritual
break;
}
if (entity instanceof EntityPlayer)
{
Utils.setPlayerSpeedFromServer((EntityPlayer) entity, entity.motionX, entity.motionY, entity.motionZ);
}
}
}

View file

@ -1,12 +1,6 @@
package WayofTime.bloodmagic.util;
import WayofTime.bloodmagic.api.BlockStack;
import WayofTime.bloodmagic.api.altar.EnumAltarComponent;
import WayofTime.bloodmagic.api.event.TeleposeEvent;
import WayofTime.bloodmagic.registry.ModBlocks;
import WayofTime.bloodmagic.tile.TileInventory;
import com.google.common.collect.Iterables;
import java.util.ArrayList;
import net.minecraft.block.Block;
import net.minecraft.block.BlockPortal;
@ -15,6 +9,7 @@ import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Blocks;
import net.minecraft.init.MobEffects;
import net.minecraft.init.SoundEvents;
@ -28,20 +23,24 @@ import net.minecraft.potion.Potion;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.DamageSource;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.common.ISpecialArmor;
import net.minecraftforge.common.ISpecialArmor.ArmorProperties;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.IFluidBlock;
import net.minecraftforge.fluids.IFluidHandler;
import net.minecraftforge.fml.common.FMLCommonHandler;
import WayofTime.bloodmagic.api.BlockStack;
import WayofTime.bloodmagic.api.altar.EnumAltarComponent;
import WayofTime.bloodmagic.network.BloodMagicPacketHandler;
import WayofTime.bloodmagic.network.PlayerVelocityPacketProcessor;
import WayofTime.bloodmagic.registry.ModBlocks;
import WayofTime.bloodmagic.tile.TileInventory;
import java.util.ArrayList;
import com.google.common.collect.Iterables;
public class Utils
{
@ -59,6 +58,14 @@ public class Utils
return beaconData;
}
public static void setPlayerSpeedFromServer(EntityPlayer player, double motionX, double motionY, double motionZ)
{
if (!player.worldObj.isRemote && player instanceof EntityPlayerMP)
{
BloodMagicPacketHandler.sendTo(new PlayerVelocityPacketProcessor(motionX, motionY, motionZ), (EntityPlayerMP) player);
}
}
public static boolean isInteger(String integer)
{
try