From c0abd69a2a3e0343b98a8d5efa68fdd68a3cdfd7 Mon Sep 17 00:00:00 2001 From: WayofTime Date: Sat, 10 Jan 2015 14:31:24 -0500 Subject: [PATCH] Adding needed backend stuff in the form of packet handling --- .../api/spell/APISpellHelper.java | 92 ++++++++++++ .../common/NewPacketHandler.java | 141 ++++++++++++++++-- .../common/items/armour/OmegaArmour.java | 7 + .../common/omega/OmegaParadigm.java | 7 +- .../common/rituals/RitualEffectOmegaTest.java | 3 +- 5 files changed, 233 insertions(+), 17 deletions(-) diff --git a/src/main/java/WayofTime/alchemicalWizardry/api/spell/APISpellHelper.java b/src/main/java/WayofTime/alchemicalWizardry/api/spell/APISpellHelper.java index a2e68a27..ce40bd4f 100644 --- a/src/main/java/WayofTime/alchemicalWizardry/api/spell/APISpellHelper.java +++ b/src/main/java/WayofTime/alchemicalWizardry/api/spell/APISpellHelper.java @@ -14,6 +14,8 @@ import net.minecraft.util.MathHelper; import net.minecraft.util.MovingObjectPosition; import net.minecraft.util.Vec3; import net.minecraft.world.World; +import WayofTime.alchemicalWizardry.api.alchemy.energy.Reagent; +import WayofTime.alchemicalWizardry.api.alchemy.energy.ReagentRegistry; public class APISpellHelper { @@ -51,6 +53,96 @@ public class APISpellHelper data.setInteger("BM:MaxStoredLP", amount); } + public static float getPlayerCurrentReagentAmount(EntityPlayer player) + { + NBTTagCompound data = player.getEntityData(); + if(data.hasKey("BM:StoredReagentAmount")) + { + return data.getFloat("BM:StoredReagentAmount"); + } + + return 0; + } + + public static void setPlayerCurrentReagentAmount(EntityPlayer player, float amount) + { + NBTTagCompound data = player.getEntityData(); + data.setFloat("BM:StoredReagentAmount", amount); + } + + public static float getPlayerMaxReagentAmount(EntityPlayer player) + { + NBTTagCompound data = player.getEntityData(); + if(data.hasKey("BM:MaxReagentAmount")) + { + return data.getFloat("BM:MaxReagentAmount"); + } + + return 0; + } + + public static void setPlayerMaxReagentAmount(EntityPlayer player, float amount) + { + NBTTagCompound data = player.getEntityData(); + data.setFloat("BM:MaxReagentAmount", amount); + } + + public static Reagent getPlayerReagentType(EntityPlayer player) + { + NBTTagCompound data = player.getEntityData(); + if(data.hasKey("BM:ReagentType")) + { + return ReagentRegistry.getReagentForKey(data.getString("BM:ReagentType")); + } + + return null; + } + + public static void setPlayerReagentType(EntityPlayer player, String str) + { + NBTTagCompound data = player.getEntityData(); + data.setString("BM:ReagentType", str); + } + + public static void setPlayerReagentType(EntityPlayer player, Reagent reagent) + { + setPlayerReagentType(player, ReagentRegistry.getKeyForReagent(reagent)); + } + + public static int getCurrentAdditionalHP(EntityPlayer player) + { + NBTTagCompound data = player.getEntityData(); + if(data.hasKey("BM:CurrentAddedHP")) + { + return data.getInteger("BM:CurrentAddedHP"); + } + + return 0; + } + + public static void setCurrentAdditionalHP(EntityPlayer player, int amount) + { + NBTTagCompound data = player.getEntityData(); + data.setInteger("BM:CurrentAddedHP", amount); + } + + public static int getCurrentAdditionalMaxHP(EntityPlayer player) + { + NBTTagCompound data = player.getEntityData(); + if(data.hasKey("BM:MaxAddedHP")) + { + return data.getInteger("BM:MaxAddedHP"); + } + + return 0; + } + + public static void setCurrentAdditionalMaxHP(EntityPlayer player, int amount) + { + NBTTagCompound data = player.getEntityData(); + data.setInteger("BM:MaxAddedHP", amount); + } + public static MovingObjectPosition raytraceFromEntity(World world, Entity player, boolean par3, double range) { float f = 1.0F; diff --git a/src/main/java/WayofTime/alchemicalWizardry/common/NewPacketHandler.java b/src/main/java/WayofTime/alchemicalWizardry/common/NewPacketHandler.java index f3ff79d6..e6747133 100644 --- a/src/main/java/WayofTime/alchemicalWizardry/common/NewPacketHandler.java +++ b/src/main/java/WayofTime/alchemicalWizardry/common/NewPacketHandler.java @@ -1,19 +1,13 @@ package WayofTime.alchemicalWizardry.common; -import WayofTime.alchemicalWizardry.AlchemicalWizardry; -import WayofTime.alchemicalWizardry.api.ColourAndCoords; -import WayofTime.alchemicalWizardry.api.spell.APISpellHelper; -import WayofTime.alchemicalWizardry.common.tileEntity.*; -import cpw.mods.fml.common.FMLCommonHandler; -import cpw.mods.fml.common.network.FMLEmbeddedChannel; -import cpw.mods.fml.common.network.FMLIndexedMessageToMessageCodec; -import cpw.mods.fml.common.network.FMLOutboundHandler; -import cpw.mods.fml.common.network.NetworkRegistry; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.SimpleChannelInboundHandler; + +import java.util.EnumMap; +import java.util.LinkedList; +import java.util.List; + import net.minecraft.client.Minecraft; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; @@ -21,10 +15,27 @@ import net.minecraft.network.Packet; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; - -import java.util.EnumMap; -import java.util.LinkedList; -import java.util.List; +import WayofTime.alchemicalWizardry.AlchemicalWizardry; +import WayofTime.alchemicalWizardry.api.ColourAndCoords; +import WayofTime.alchemicalWizardry.api.alchemy.energy.Reagent; +import WayofTime.alchemicalWizardry.api.alchemy.energy.ReagentRegistry; +import WayofTime.alchemicalWizardry.api.spell.APISpellHelper; +import WayofTime.alchemicalWizardry.common.tileEntity.TEAltar; +import WayofTime.alchemicalWizardry.common.tileEntity.TEMasterStone; +import WayofTime.alchemicalWizardry.common.tileEntity.TEOrientable; +import WayofTime.alchemicalWizardry.common.tileEntity.TEPedestal; +import WayofTime.alchemicalWizardry.common.tileEntity.TEPlinth; +import WayofTime.alchemicalWizardry.common.tileEntity.TEReagentConduit; +import WayofTime.alchemicalWizardry.common.tileEntity.TESocket; +import WayofTime.alchemicalWizardry.common.tileEntity.TETeleposer; +import WayofTime.alchemicalWizardry.common.tileEntity.TEWritingTable; +import cpw.mods.fml.common.FMLCommonHandler; +import cpw.mods.fml.common.network.FMLEmbeddedChannel; +import cpw.mods.fml.common.network.FMLIndexedMessageToMessageCodec; +import cpw.mods.fml.common.network.FMLOutboundHandler; +import cpw.mods.fml.common.network.NetworkRegistry; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; /** * Handles the packet wrangling for IronChest @@ -73,6 +84,8 @@ public enum NewPacketHandler clientChannel.pipeline().addAfter(tileAltarCodec, "TEMasterStoneHandler", new TEMasterStoneMessageHandler()); clientChannel.pipeline().addAfter(tileAltarCodec, "TEReagentConduitHandler", new TEReagentConduitMessageHandler()); clientChannel.pipeline().addAfter(tileAltarCodec, "CurrentLPMessageHandler", new CurrentLPMessageHandler()); + clientChannel.pipeline().addAfter(tileAltarCodec, "CurrentReagentBarMessageHandler", new CurrentReagentBarMessageHandler()); + clientChannel.pipeline().addAfter(tileAltarCodec, "CurrentAddedHPMessageHandler", new CurrentAddedHPMessageHandler()); } @@ -267,6 +280,30 @@ public enum NewPacketHandler APISpellHelper.setPlayerMaxLPTag(player, msg.maxLP); } } + + private static class CurrentReagentBarMessageHandler extends SimpleChannelInboundHandler + { + @Override + protected void channelRead0(ChannelHandlerContext ctx, CurrentReagentBarMessage msg) throws Exception + { + EntityPlayer player = Minecraft.getMinecraft().thePlayer; + + APISpellHelper.setPlayerCurrentReagentAmount(player, msg.currentAR); + APISpellHelper.setPlayerMaxReagentAmount(player, msg.maxAR); + } + } + + private static class CurrentAddedHPMessageHandler extends SimpleChannelInboundHandler + { + @Override + protected void channelRead0(ChannelHandlerContext ctx, CurrentAddedHPMessage msg) throws Exception + { + EntityPlayer player = Minecraft.getMinecraft().thePlayer; + + APISpellHelper.setCurrentAdditionalHP(player, msg.currentHP); + APISpellHelper.setCurrentAdditionalMaxHP(player, msg.maxHP); + } + } public static class BMMessage { @@ -383,6 +420,19 @@ public enum NewPacketHandler int currentLP; int maxLP; } + + public static class CurrentReagentBarMessage extends BMMessage + { + String reagent; + float currentAR; + float maxAR; + } + + public static class CurrentAddedHPMessage extends BMMessage + { + int currentHP; + int maxHP; + } private class TEAltarCodec extends FMLIndexedMessageToMessageCodec { @@ -400,6 +450,8 @@ public enum NewPacketHandler addDiscriminator(9, TEMasterStoneMessage.class); addDiscriminator(10, TEReagentConduitMessage.class); addDiscriminator(11, CurrentLPMessage.class); + addDiscriminator(12, CurrentReagentBarMessage.class); + addDiscriminator(13, CurrentAddedHPMessage.class); } @Override @@ -606,6 +658,24 @@ public enum NewPacketHandler target.writeInt(((CurrentLPMessage) msg).currentLP); target.writeInt(((CurrentLPMessage) msg).maxLP); + break; + + case 12: + char[] charSet = ((CurrentReagentBarMessage)msg).reagent.toCharArray(); + target.writeInt(charSet.length); + for(char cha : charSet) + { + target.writeChar(cha); + } + target.writeFloat(((CurrentReagentBarMessage)msg).currentAR); + target.writeFloat(((CurrentReagentBarMessage)msg).maxAR); + + break; + + case 13: + target.writeInt(((CurrentAddedHPMessage) msg).currentHP); + target.writeInt(((CurrentAddedHPMessage) msg).maxHP); + break; } } @@ -819,6 +889,26 @@ public enum NewPacketHandler ((CurrentLPMessage) msg).currentLP = dat.readInt(); ((CurrentLPMessage) msg).maxLP = dat.readInt(); + break; + + case 12: + int size1 = dat.readInt(); + String str1 = ""; + for(int i=0; i