diff --git a/src/main/java/WayofTime/bloodmagic/client/hud/HUDElementDemonWillAura.java b/src/main/java/WayofTime/bloodmagic/client/hud/HUDElementDemonWillAura.java index b7ec0050..bb74688d 100644 --- a/src/main/java/WayofTime/bloodmagic/client/hud/HUDElementDemonWillAura.java +++ b/src/main/java/WayofTime/bloodmagic/client/hud/HUDElementDemonWillAura.java @@ -10,10 +10,12 @@ import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.VertexBuffer; import net.minecraft.client.renderer.vertex.DefaultVertexFormats; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.ResourceLocation; import net.minecraftforge.client.event.RenderGameOverlayEvent; import WayofTime.bloodmagic.api.Constants; import WayofTime.bloodmagic.api.soul.EnumDemonWillType; +import WayofTime.bloodmagic.proxy.ClientProxy; public class HUDElementDemonWillAura extends HUDElement { @@ -34,6 +36,7 @@ public class HUDElementDemonWillAura extends HUDElement @Override public void render(Minecraft minecraft, ScaledResolution resolution, float partialTicks) { + EntityPlayer player = minecraft.thePlayer; // ItemStack sigilHolding = minecraft.thePlayer.getHeldItemMainhand(); // // TODO - Clean this mess // // Check mainhand for Sigil of Holding @@ -61,9 +64,10 @@ public class HUDElementDemonWillAura extends HUDElement for (EnumDemonWillType type : EnumDemonWillType.values()) { + GlStateManager.color(1.0F, 1.0F, 1.0F); minecraft.getTextureManager().bindTexture(crystalTextures.get(type)); - double amount = 10 + type.ordinal() * 15; + double amount = ClientProxy.currentAura == null ? 0 : ClientProxy.currentAura.getWill(type); double ratio = Math.max(Math.min(amount / maxAmount, 1), 0); double x = getXOffset() + 8 + type.ordinal() * 6; @@ -73,10 +77,21 @@ public class HUDElementDemonWillAura extends HUDElement vertexBuffer.begin(7, DefaultVertexFormats.POSITION_TEX); vertexBuffer.pos((double) (x), (double) (y + height), 0).tex(0, 1).endVertex(); - vertexBuffer.pos((double) (x + width), (double) (y + height), 0).tex(1d / 8d, 1).endVertex(); - vertexBuffer.pos((double) (x + width), (double) (y), 0).tex(1d / 8d, 1 - ratio).endVertex(); + vertexBuffer.pos((double) (x + width), (double) (y + height), 0).tex(5d / 16d, 1).endVertex(); + vertexBuffer.pos((double) (x + width), (double) (y), 0).tex(5d / 16d, 1 - ratio).endVertex(); vertexBuffer.pos((double) (x), (double) (y), 0).tex(0, 1 - ratio).endVertex(); tessellator.draw(); + + if (player.isSneaking()) + { + GlStateManager.pushMatrix(); + String value = "" + (int) amount; + GlStateManager.translate(x, (y + height + 4 + value.length() * 3), 0); + GlStateManager.scale(0.5, 0.5, 1); + GlStateManager.rotate(-90, 0, 0, 1); + minecraft.fontRendererObj.drawStringWithShadow("" + (int) amount, 0, 2, 0xffffff); + GlStateManager.popMatrix(); + } } minecraft.getTextureManager().bindTexture(new ResourceLocation(Constants.Mod.MODID, "textures/gui/demonWillBar.png")); diff --git a/src/main/java/WayofTime/bloodmagic/demonAura/WorldDemonWillHandler.java b/src/main/java/WayofTime/bloodmagic/demonAura/WorldDemonWillHandler.java index 5caee62e..1dd17e37 100644 --- a/src/main/java/WayofTime/bloodmagic/demonAura/WorldDemonWillHandler.java +++ b/src/main/java/WayofTime/bloodmagic/demonAura/WorldDemonWillHandler.java @@ -15,6 +15,17 @@ public class WorldDemonWillHandler static ConcurrentHashMap containedWills = new ConcurrentHashMap(); public static ConcurrentHashMap> dirtyChunks = new ConcurrentHashMap>(); + public static DemonWillHolder getWillHolder(int dim, int x, int y) + { + WillChunk chunk = getWillChunk(dim, x, y); + if (chunk != null) + { + return chunk.getCurrentWill(); + } + + return null; + } + public static WillWorld getWillWorld(int dim) { return containedWills.get(dim); diff --git a/src/main/java/WayofTime/bloodmagic/item/soul/ItemSoulGem.java b/src/main/java/WayofTime/bloodmagic/item/soul/ItemSoulGem.java index 9e25e1c8..d4d3afbf 100644 --- a/src/main/java/WayofTime/bloodmagic/item/soul/ItemSoulGem.java +++ b/src/main/java/WayofTime/bloodmagic/item/soul/ItemSoulGem.java @@ -207,7 +207,7 @@ public class ItemSoulGem extends Item implements IDemonWillGem, IMeshProvider, I double soulsDrained = Math.min(drainAmount, souls); - if (!doDrain) + if (doDrain) { setWill(type, soulGemStack, souls - soulsDrained); } @@ -287,7 +287,7 @@ public class ItemSoulGem extends Item implements IDemonWillGem, IMeshProvider, I double filled = Math.min(fillAmount, maxWill - current); - if (filled > 0 && doFill) + if (doFill) { this.setWill(type, stack, filled + current); } diff --git a/src/main/java/WayofTime/bloodmagic/network/BloodMagicPacketHandler.java b/src/main/java/WayofTime/bloodmagic/network/BloodMagicPacketHandler.java index 286b34a9..4b7a6b91 100644 --- a/src/main/java/WayofTime/bloodmagic/network/BloodMagicPacketHandler.java +++ b/src/main/java/WayofTime/bloodmagic/network/BloodMagicPacketHandler.java @@ -1,13 +1,13 @@ package WayofTime.bloodmagic.network; -import WayofTime.bloodmagic.api.Constants; -import WayofTime.bloodmagic.util.ChatUtil; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.tileentity.TileEntity; import net.minecraftforge.fml.common.network.NetworkRegistry; import net.minecraftforge.fml.common.network.simpleimpl.IMessage; import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper; import net.minecraftforge.fml.relauncher.Side; +import WayofTime.bloodmagic.api.Constants; +import WayofTime.bloodmagic.util.ChatUtil; public class BloodMagicPacketHandler { @@ -21,6 +21,7 @@ public class BloodMagicPacketHandler INSTANCE.registerMessage(PlayerFallDistancePacketProcessor.class, PlayerFallDistancePacketProcessor.class, 3, Side.SERVER); INSTANCE.registerMessage(SigilHoldingPacketProcessor.class, SigilHoldingPacketProcessor.class, 4, Side.SERVER); INSTANCE.registerMessage(KeyProcessor.class, KeyProcessor.class, 5, Side.SERVER); + INSTANCE.registerMessage(DemonAuraPacketProcessor.class, DemonAuraPacketProcessor.class, 6, Side.CLIENT); } public static void sendToAllAround(IMessage message, TileEntity te, int range) diff --git a/src/main/java/WayofTime/bloodmagic/network/DemonAuraPacketProcessor.java b/src/main/java/WayofTime/bloodmagic/network/DemonAuraPacketProcessor.java new file mode 100644 index 00000000..05b88ecb --- /dev/null +++ b/src/main/java/WayofTime/bloodmagic/network/DemonAuraPacketProcessor.java @@ -0,0 +1,70 @@ +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; +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.proxy.ClientProxy; + +public class DemonAuraPacketProcessor implements IMessage, IMessageHandler +{ + public DemonWillHolder currentWill = new DemonWillHolder(); + + public DemonAuraPacketProcessor() + { + + } + + public DemonAuraPacketProcessor(DemonWillHolder holder) + { + this.currentWill = holder; + } + + @Override + public void fromBytes(ByteBuf buffer) + { + PacketBuffer buff = new PacketBuffer(buffer); + try + { + NBTTagCompound tag = buff.readNBTTagCompoundFromBuffer(); + currentWill.readFromNBT(tag, "Aura"); + } catch (IOException e) + { + e.printStackTrace(); + } + } + + @Override + public void toBytes(ByteBuf buffer) + { + PacketBuffer buff = new PacketBuffer(buffer); + NBTTagCompound tag = new NBTTagCompound(); + currentWill.writeToNBT(tag, "Aura"); + buff.writeNBTTagCompoundToBuffer(tag); + } + + @Override + public IMessage onMessage(DemonAuraPacketProcessor message, MessageContext ctx) + { + if (ctx.side == Side.CLIENT) + { + message.onMessageFromServer(); + } + return null; + } + + @SideOnly(Side.CLIENT) + public void onMessageFromServer() + { + ClientProxy.currentAura = currentWill; + } +} diff --git a/src/main/java/WayofTime/bloodmagic/proxy/ClientProxy.java b/src/main/java/WayofTime/bloodmagic/proxy/ClientProxy.java index 72795412..50eedc4e 100644 --- a/src/main/java/WayofTime/bloodmagic/proxy/ClientProxy.java +++ b/src/main/java/WayofTime/bloodmagic/proxy/ClientProxy.java @@ -21,6 +21,7 @@ import org.apache.commons.lang3.tuple.Pair; import WayofTime.bloodmagic.BloodMagic; import WayofTime.bloodmagic.api.Constants; +import WayofTime.bloodmagic.api.soul.DemonWillHolder; import WayofTime.bloodmagic.client.IMeshProvider; import WayofTime.bloodmagic.client.IVariantProvider; import WayofTime.bloodmagic.client.helper.ShaderHelper; @@ -48,6 +49,8 @@ import WayofTime.bloodmagic.util.helper.InventoryRenderHelperV2; public class ClientProxy extends CommonProxy { + public static DemonWillHolder currentAura = new DemonWillHolder(); + private InventoryRenderHelper renderHelper; private InventoryRenderHelperV2 renderHelperV2; diff --git a/src/main/java/WayofTime/bloodmagic/tile/TileDemonCrucible.java b/src/main/java/WayofTime/bloodmagic/tile/TileDemonCrucible.java index 0af7a64e..31b0a61b 100644 --- a/src/main/java/WayofTime/bloodmagic/tile/TileDemonCrucible.java +++ b/src/main/java/WayofTime/bloodmagic/tile/TileDemonCrucible.java @@ -80,9 +80,10 @@ public class TileDemonCrucible extends TileInventory implements ITickable, IDemo double currentAmount = WorldDemonWillHandler.getCurrentWill(worldObj, pos, type); double drainAmount = Math.min(maxWill - currentAmount, gemDrainRate); double filled = WorldDemonWillHandler.fillWillToMaximum(worldObj, pos, type, drainAmount, maxWill, false); - filled = gemItem.drainWill(type, stack, filled, true); + filled = gemItem.drainWill(type, stack, filled, false); if (filled > 0) { + filled = gemItem.drainWill(type, stack, filled, true); WorldDemonWillHandler.fillWillToMaximum(worldObj, pos, type, filled, maxWill, true); } } diff --git a/src/main/java/WayofTime/bloodmagic/util/handler/event/GenericHandler.java b/src/main/java/WayofTime/bloodmagic/util/handler/event/GenericHandler.java index 249d5106..f73d575b 100644 --- a/src/main/java/WayofTime/bloodmagic/util/handler/event/GenericHandler.java +++ b/src/main/java/WayofTime/bloodmagic/util/handler/event/GenericHandler.java @@ -13,8 +13,10 @@ import net.minecraft.init.Enchantments; import net.minecraft.inventory.EntityEquipmentSlot; import net.minecraft.item.ItemStack; import net.minecraft.util.DamageSource; +import net.minecraft.util.math.BlockPos; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.entity.living.LivingDropsEvent; +import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent; import net.minecraftforge.event.entity.living.LivingHurtEvent; import net.minecraftforge.event.entity.player.PlayerEvent; import net.minecraftforge.event.entity.player.PlayerInteractEvent; @@ -33,12 +35,14 @@ import WayofTime.bloodmagic.api.iface.IBindable; import WayofTime.bloodmagic.api.livingArmour.LivingArmourUpgrade; import WayofTime.bloodmagic.api.orb.IBloodOrb; import WayofTime.bloodmagic.api.saving.SoulNetwork; +import WayofTime.bloodmagic.api.soul.DemonWillHolder; import WayofTime.bloodmagic.api.util.helper.BindableHelper; import WayofTime.bloodmagic.api.util.helper.ItemHelper; import WayofTime.bloodmagic.api.util.helper.NBTHelper; import WayofTime.bloodmagic.api.util.helper.NetworkHelper; import WayofTime.bloodmagic.api.util.helper.PlayerHelper; import WayofTime.bloodmagic.block.BlockAltar; +import WayofTime.bloodmagic.demonAura.WorldDemonWillHandler; import WayofTime.bloodmagic.item.ItemAltarMaker; import WayofTime.bloodmagic.item.ItemExperienceBook; import WayofTime.bloodmagic.item.armour.ItemLivingArmour; @@ -46,6 +50,8 @@ import WayofTime.bloodmagic.item.gear.ItemPackSacrifice; import WayofTime.bloodmagic.livingArmour.LivingArmour; import WayofTime.bloodmagic.livingArmour.tracker.StatTrackerSelfSacrifice; import WayofTime.bloodmagic.livingArmour.upgrade.LivingArmourUpgradeSelfSacrifice; +import WayofTime.bloodmagic.network.BloodMagicPacketHandler; +import WayofTime.bloodmagic.network.DemonAuraPacketProcessor; import WayofTime.bloodmagic.registry.ModItems; import WayofTime.bloodmagic.util.ChatUtil; import WayofTime.bloodmagic.util.helper.TextHelper; @@ -79,6 +85,35 @@ public class GenericHandler } } + // Handles sending the client the Demon Will Aura updates + @SubscribeEvent + public void onLivingUpdate(LivingUpdateEvent event) + { + if (!event.getEntityLiving().worldObj.isRemote) + { + EntityLivingBase entity = event.getEntityLiving(); + if (entity instanceof EntityPlayer && entity.worldObj.getTotalWorldTime() % 50 == 0) //TODO: Change to an incremental counter + { + sendPlayerDemonWillAura((EntityPlayer) entity); + } + return; + } + } + +// @SideOnly(Side.SERVER) + public void sendPlayerDemonWillAura(EntityPlayer player) + { + if (player instanceof EntityPlayerMP) + { + BlockPos pos = player.getPosition(); + DemonWillHolder holder = WorldDemonWillHandler.getWillHolder(player.worldObj.provider.getDimension(), pos.getX() >> 4, pos.getZ() >> 4); + if (holder != null) + { + BloodMagicPacketHandler.sendTo(new DemonAuraPacketProcessor(holder), (EntityPlayerMP) player); + } + } + } + // Handles destroying altar @SubscribeEvent public void harvestEvent(PlayerEvent.HarvestCheck event) diff --git a/src/main/resources/assets/bloodmagic/textures/gui/demonWillBar.png b/src/main/resources/assets/bloodmagic/textures/gui/demonWillBar.png index 90748c6a..a9559f80 100644 Binary files a/src/main/resources/assets/bloodmagic/textures/gui/demonWillBar.png and b/src/main/resources/assets/bloodmagic/textures/gui/demonWillBar.png differ