Updated the Demon Aura hud by allowing it to actually see the Aura in the chunk - refresh rate is 50 ticks.

This commit is contained in:
WayofTime 2016-07-10 15:27:26 -04:00
parent 0ac2b78803
commit 98ed17fe21
9 changed files with 144 additions and 8 deletions

View file

@ -10,10 +10,12 @@ import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.VertexBuffer; import net.minecraft.client.renderer.VertexBuffer;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats; import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.event.RenderGameOverlayEvent; import net.minecraftforge.client.event.RenderGameOverlayEvent;
import WayofTime.bloodmagic.api.Constants; import WayofTime.bloodmagic.api.Constants;
import WayofTime.bloodmagic.api.soul.EnumDemonWillType; import WayofTime.bloodmagic.api.soul.EnumDemonWillType;
import WayofTime.bloodmagic.proxy.ClientProxy;
public class HUDElementDemonWillAura extends HUDElement public class HUDElementDemonWillAura extends HUDElement
{ {
@ -34,6 +36,7 @@ public class HUDElementDemonWillAura extends HUDElement
@Override @Override
public void render(Minecraft minecraft, ScaledResolution resolution, float partialTicks) public void render(Minecraft minecraft, ScaledResolution resolution, float partialTicks)
{ {
EntityPlayer player = minecraft.thePlayer;
// ItemStack sigilHolding = minecraft.thePlayer.getHeldItemMainhand(); // ItemStack sigilHolding = minecraft.thePlayer.getHeldItemMainhand();
// // TODO - Clean this mess // // TODO - Clean this mess
// // Check mainhand for Sigil of Holding // // Check mainhand for Sigil of Holding
@ -61,9 +64,10 @@ public class HUDElementDemonWillAura extends HUDElement
for (EnumDemonWillType type : EnumDemonWillType.values()) for (EnumDemonWillType type : EnumDemonWillType.values())
{ {
GlStateManager.color(1.0F, 1.0F, 1.0F);
minecraft.getTextureManager().bindTexture(crystalTextures.get(type)); 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 ratio = Math.max(Math.min(amount / maxAmount, 1), 0);
double x = getXOffset() + 8 + type.ordinal() * 6; double x = getXOffset() + 8 + type.ordinal() * 6;
@ -73,10 +77,21 @@ public class HUDElementDemonWillAura extends HUDElement
vertexBuffer.begin(7, DefaultVertexFormats.POSITION_TEX); vertexBuffer.begin(7, DefaultVertexFormats.POSITION_TEX);
vertexBuffer.pos((double) (x), (double) (y + height), 0).tex(0, 1).endVertex(); 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 + height), 0).tex(5d / 16d, 1).endVertex();
vertexBuffer.pos((double) (x + width), (double) (y), 0).tex(1d / 8d, 1 - ratio).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(); vertexBuffer.pos((double) (x), (double) (y), 0).tex(0, 1 - ratio).endVertex();
tessellator.draw(); 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")); minecraft.getTextureManager().bindTexture(new ResourceLocation(Constants.Mod.MODID, "textures/gui/demonWillBar.png"));

View file

@ -15,6 +15,17 @@ public class WorldDemonWillHandler
static ConcurrentHashMap<Integer, WillWorld> containedWills = new ConcurrentHashMap<Integer, WillWorld>(); static ConcurrentHashMap<Integer, WillWorld> containedWills = new ConcurrentHashMap<Integer, WillWorld>();
public static ConcurrentHashMap<Integer, CopyOnWriteArrayList<PosXY>> dirtyChunks = new ConcurrentHashMap<Integer, CopyOnWriteArrayList<PosXY>>(); public static ConcurrentHashMap<Integer, CopyOnWriteArrayList<PosXY>> dirtyChunks = new ConcurrentHashMap<Integer, CopyOnWriteArrayList<PosXY>>();
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) public static WillWorld getWillWorld(int dim)
{ {
return containedWills.get(dim); return containedWills.get(dim);

View file

@ -207,7 +207,7 @@ public class ItemSoulGem extends Item implements IDemonWillGem, IMeshProvider, I
double soulsDrained = Math.min(drainAmount, souls); double soulsDrained = Math.min(drainAmount, souls);
if (!doDrain) if (doDrain)
{ {
setWill(type, soulGemStack, souls - soulsDrained); 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); double filled = Math.min(fillAmount, maxWill - current);
if (filled > 0 && doFill) if (doFill)
{ {
this.setWill(type, stack, filled + current); this.setWill(type, stack, filled + current);
} }

View file

@ -1,13 +1,13 @@
package WayofTime.bloodmagic.network; package WayofTime.bloodmagic.network;
import WayofTime.bloodmagic.api.Constants;
import WayofTime.bloodmagic.util.ChatUtil;
import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.fml.common.network.NetworkRegistry; import net.minecraftforge.fml.common.network.NetworkRegistry;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage; import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper; import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper;
import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.Side;
import WayofTime.bloodmagic.api.Constants;
import WayofTime.bloodmagic.util.ChatUtil;
public class BloodMagicPacketHandler public class BloodMagicPacketHandler
{ {
@ -21,6 +21,7 @@ public class BloodMagicPacketHandler
INSTANCE.registerMessage(PlayerFallDistancePacketProcessor.class, PlayerFallDistancePacketProcessor.class, 3, Side.SERVER); INSTANCE.registerMessage(PlayerFallDistancePacketProcessor.class, PlayerFallDistancePacketProcessor.class, 3, Side.SERVER);
INSTANCE.registerMessage(SigilHoldingPacketProcessor.class, SigilHoldingPacketProcessor.class, 4, Side.SERVER); INSTANCE.registerMessage(SigilHoldingPacketProcessor.class, SigilHoldingPacketProcessor.class, 4, Side.SERVER);
INSTANCE.registerMessage(KeyProcessor.class, KeyProcessor.class, 5, 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) public static void sendToAllAround(IMessage message, TileEntity te, int range)

View file

@ -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<DemonAuraPacketProcessor, IMessage>
{
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;
}
}

View file

@ -21,6 +21,7 @@ import org.apache.commons.lang3.tuple.Pair;
import WayofTime.bloodmagic.BloodMagic; import WayofTime.bloodmagic.BloodMagic;
import WayofTime.bloodmagic.api.Constants; import WayofTime.bloodmagic.api.Constants;
import WayofTime.bloodmagic.api.soul.DemonWillHolder;
import WayofTime.bloodmagic.client.IMeshProvider; import WayofTime.bloodmagic.client.IMeshProvider;
import WayofTime.bloodmagic.client.IVariantProvider; import WayofTime.bloodmagic.client.IVariantProvider;
import WayofTime.bloodmagic.client.helper.ShaderHelper; import WayofTime.bloodmagic.client.helper.ShaderHelper;
@ -48,6 +49,8 @@ import WayofTime.bloodmagic.util.helper.InventoryRenderHelperV2;
public class ClientProxy extends CommonProxy public class ClientProxy extends CommonProxy
{ {
public static DemonWillHolder currentAura = new DemonWillHolder();
private InventoryRenderHelper renderHelper; private InventoryRenderHelper renderHelper;
private InventoryRenderHelperV2 renderHelperV2; private InventoryRenderHelperV2 renderHelperV2;

View file

@ -80,9 +80,10 @@ public class TileDemonCrucible extends TileInventory implements ITickable, IDemo
double currentAmount = WorldDemonWillHandler.getCurrentWill(worldObj, pos, type); double currentAmount = WorldDemonWillHandler.getCurrentWill(worldObj, pos, type);
double drainAmount = Math.min(maxWill - currentAmount, gemDrainRate); double drainAmount = Math.min(maxWill - currentAmount, gemDrainRate);
double filled = WorldDemonWillHandler.fillWillToMaximum(worldObj, pos, type, drainAmount, maxWill, false); 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) if (filled > 0)
{ {
filled = gemItem.drainWill(type, stack, filled, true);
WorldDemonWillHandler.fillWillToMaximum(worldObj, pos, type, filled, maxWill, true); WorldDemonWillHandler.fillWillToMaximum(worldObj, pos, type, filled, maxWill, true);
} }
} }

View file

@ -13,8 +13,10 @@ import net.minecraft.init.Enchantments;
import net.minecraft.inventory.EntityEquipmentSlot; import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.DamageSource; import net.minecraft.util.DamageSource;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.living.LivingDropsEvent; 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.living.LivingHurtEvent;
import net.minecraftforge.event.entity.player.PlayerEvent; import net.minecraftforge.event.entity.player.PlayerEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent; 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.livingArmour.LivingArmourUpgrade;
import WayofTime.bloodmagic.api.orb.IBloodOrb; import WayofTime.bloodmagic.api.orb.IBloodOrb;
import WayofTime.bloodmagic.api.saving.SoulNetwork; 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.BindableHelper;
import WayofTime.bloodmagic.api.util.helper.ItemHelper; import WayofTime.bloodmagic.api.util.helper.ItemHelper;
import WayofTime.bloodmagic.api.util.helper.NBTHelper; import WayofTime.bloodmagic.api.util.helper.NBTHelper;
import WayofTime.bloodmagic.api.util.helper.NetworkHelper; import WayofTime.bloodmagic.api.util.helper.NetworkHelper;
import WayofTime.bloodmagic.api.util.helper.PlayerHelper; import WayofTime.bloodmagic.api.util.helper.PlayerHelper;
import WayofTime.bloodmagic.block.BlockAltar; import WayofTime.bloodmagic.block.BlockAltar;
import WayofTime.bloodmagic.demonAura.WorldDemonWillHandler;
import WayofTime.bloodmagic.item.ItemAltarMaker; import WayofTime.bloodmagic.item.ItemAltarMaker;
import WayofTime.bloodmagic.item.ItemExperienceBook; import WayofTime.bloodmagic.item.ItemExperienceBook;
import WayofTime.bloodmagic.item.armour.ItemLivingArmour; 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.LivingArmour;
import WayofTime.bloodmagic.livingArmour.tracker.StatTrackerSelfSacrifice; import WayofTime.bloodmagic.livingArmour.tracker.StatTrackerSelfSacrifice;
import WayofTime.bloodmagic.livingArmour.upgrade.LivingArmourUpgradeSelfSacrifice; import WayofTime.bloodmagic.livingArmour.upgrade.LivingArmourUpgradeSelfSacrifice;
import WayofTime.bloodmagic.network.BloodMagicPacketHandler;
import WayofTime.bloodmagic.network.DemonAuraPacketProcessor;
import WayofTime.bloodmagic.registry.ModItems; import WayofTime.bloodmagic.registry.ModItems;
import WayofTime.bloodmagic.util.ChatUtil; import WayofTime.bloodmagic.util.ChatUtil;
import WayofTime.bloodmagic.util.helper.TextHelper; 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 // Handles destroying altar
@SubscribeEvent @SubscribeEvent
public void harvestEvent(PlayerEvent.HarvestCheck event) public void harvestEvent(PlayerEvent.HarvestCheck event)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.5 KiB

After

Width:  |  Height:  |  Size: 3.5 KiB