Changed to a non-retarded way of sending a packet for the Demon Aura and created the Demon Will Viewer interface.

This commit is contained in:
WayofTime 2016-07-10 18:22:01 -04:00
parent 98ed17fe21
commit 12094c1153
3 changed files with 60 additions and 14 deletions

View file

@ -0,0 +1,12 @@
package WayofTime.bloodmagic.api.iface;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
public interface IDemonWillViewer
{
boolean canSeeDemonWillAura(World world, ItemStack stack, EntityPlayer player);
int getDemonWillAuraResolution(World world, ItemStack stack, EntityPlayer player);
}

View file

@ -1,11 +1,6 @@
package WayofTime.bloodmagic.network;
import io.netty.buffer.ByteBuf;
import java.io.IOException;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.PacketBuffer;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
@ -13,6 +8,7 @@ import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import WayofTime.bloodmagic.api.soul.DemonWillHolder;
import WayofTime.bloodmagic.api.soul.EnumDemonWillType;
import WayofTime.bloodmagic.proxy.ClientProxy;
public class DemonAuraPacketProcessor implements IMessage, IMessageHandler<DemonAuraPacketProcessor, IMessage>
@ -33,13 +29,9 @@ public class DemonAuraPacketProcessor implements IMessage, IMessageHandler<Demon
public void fromBytes(ByteBuf buffer)
{
PacketBuffer buff = new PacketBuffer(buffer);
try
for (EnumDemonWillType type : EnumDemonWillType.values())
{
NBTTagCompound tag = buff.readNBTTagCompoundFromBuffer();
currentWill.readFromNBT(tag, "Aura");
} catch (IOException e)
{
e.printStackTrace();
currentWill.willMap.put(type, buff.readDouble());
}
}
@ -47,9 +39,10 @@ public class DemonAuraPacketProcessor implements IMessage, IMessageHandler<Demon
public void toBytes(ByteBuf buffer)
{
PacketBuffer buff = new PacketBuffer(buffer);
NBTTagCompound tag = new NBTTagCompound();
currentWill.writeToNBT(tag, "Aura");
buff.writeNBTTagCompoundToBuffer(tag);
for (EnumDemonWillType type : EnumDemonWillType.values())
{
buff.writeDouble(currentWill.willMap.get(type));
}
}
@Override

View file

@ -47,6 +47,7 @@ import WayofTime.bloodmagic.BloodMagic;
import WayofTime.bloodmagic.api.BlockStack;
import WayofTime.bloodmagic.api.Constants;
import WayofTime.bloodmagic.api.altar.EnumAltarComponent;
import WayofTime.bloodmagic.api.iface.IDemonWillViewer;
import WayofTime.bloodmagic.api.util.helper.NBTHelper;
import WayofTime.bloodmagic.network.BloodMagicPacketHandler;
import WayofTime.bloodmagic.network.PlayerVelocityPacketProcessor;
@ -57,6 +58,46 @@ import com.google.common.collect.Iterables;
public class Utils
{
public static boolean canPlayerSeeDemonWill(EntityPlayer player)
{
ItemStack[] mainInventory = player.inventory.mainInventory;
for (ItemStack stack : mainInventory)
{
if (stack == null)
{
continue;
}
if (stack.getItem() instanceof IDemonWillViewer && ((IDemonWillViewer) stack.getItem()).canSeeDemonWillAura(player.worldObj, stack, player))
{
return true;
}
}
return false;
}
public static int getDemonWillResolution(EntityPlayer player)
{
ItemStack[] mainInventory = player.inventory.mainInventory;
for (ItemStack stack : mainInventory)
{
if (stack == null)
{
continue;
}
if (stack.getItem() instanceof IDemonWillViewer && ((IDemonWillViewer) stack.getItem()).canSeeDemonWillAura(player.worldObj, stack, player))
{
return ((IDemonWillViewer) stack.getItem()).getDemonWillAuraResolution(player.worldObj, stack, player);
}
}
return 1;
}
public static NBTTagCompound getPersistentDataTag(EntityPlayer player)
{
NBTTagCompound forgeData = player.getEntityData().getCompoundTag(EntityPlayer.PERSISTED_NBT_TAG);