mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-19 03:39:17 +00:00
Fix boss bar rendering, music still not playing
This commit is contained in:
12 files changed
+99
-74
No files matched your search
@@ -21,12 +21,7 @@ import java.awt.*;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* An extension of IBossDisplayData. This counts as a botania boss and as a normal
|
||||
* minecraft boss since it has IBossDisplayData. Instead of using the typical
|
||||
* BossStatus.setBossStatus(entity, true) to set the health bar in the render use
|
||||
* BotaniaAPI.internalMethodHandler.setBossStatus(entity);<br><br>
|
||||
* Alternatively, you can check if botania is loaded and use the vanilla one
|
||||
* if that's not the case.
|
||||
* A Botania boss, that is subject to special rendering.
|
||||
*/
|
||||
public interface IBotaniaBoss {
|
||||
|
||||
@@ -55,16 +50,17 @@ public interface IBotaniaBoss {
|
||||
/**
|
||||
* A callback for when this boss's boss bar renders, you can do additional rendering
|
||||
* here if needed.
|
||||
* @return How tall your auxiliary renders were
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void bossBarRenderCallback(ScaledResolution res, int x, int y);
|
||||
public int bossBarRenderCallback(ScaledResolution res, int x, int y);
|
||||
|
||||
/**
|
||||
* Get the UUID of the {@link BossInfo} instance tracking this boss
|
||||
* @return The uuid. Note that this is NOT the entity's UUID!
|
||||
* todo 1.9 is this needed?
|
||||
* Get the serverside UUID of the {@link net.minecraft.world.BossInfoServer} instance tracking this boss
|
||||
* Note that this is NOT the entity's UUID, nor is it the clientside UUID of the BossInfoServer instance!
|
||||
* You will most likely need to sync this yourself using the datawatcher
|
||||
* @return The uuid.
|
||||
*/
|
||||
public UUID getBossInfoUuid();
|
||||
|
||||
public EntityLivingBase getEntity();
|
||||
}
|
||||
@@ -200,11 +200,6 @@ public class DummyMethodHandler implements IInternalMethodHandler {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBossStatus(IBotaniaBoss status) {
|
||||
// NO-OP
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBuildcraftPipe(TileEntity tile) {
|
||||
return false;
|
||||
|
||||
@@ -117,8 +117,6 @@ public interface IInternalMethodHandler {
|
||||
|
||||
public ResourceLocation getDefaultBossBarTexture();
|
||||
|
||||
public void setBossStatus(IBotaniaBoss status);
|
||||
|
||||
public boolean isBuildcraftPipe(TileEntity tile);
|
||||
|
||||
public void sparkleFX(World world, double x, double y, double z, float r, float g, float b, float size, int m);
|
||||
|
||||
@@ -16,6 +16,9 @@ import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.client.event.RenderGameOverlayEvent;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import org.lwjgl.opengl.ARBShaderObjects;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import vazkii.botania.api.boss.IBotaniaBoss;
|
||||
@@ -27,51 +30,51 @@ import vazkii.botania.client.lib.LibResources;
|
||||
import vazkii.botania.common.core.helper.MathHelper;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
public final class BossBarHandler {
|
||||
|
||||
// Only access on the client thread!
|
||||
public static final Set<IBotaniaBoss> bosses = new HashSet<>();
|
||||
public static final ResourceLocation defaultBossBar = new ResourceLocation(LibResources.GUI_BOSS_BAR);
|
||||
private static IBotaniaBoss currentBoss;
|
||||
|
||||
private static final BarCallback barUniformCallback = new BarCallback();
|
||||
|
||||
public static void setCurrentBoss(IBotaniaBoss status) {
|
||||
currentBoss = status;
|
||||
@SubscribeEvent
|
||||
public void onBarRender(RenderGameOverlayEvent.BossInfo evt) {
|
||||
UUID infoUuid = evt.getBossInfo().getUniqueId();
|
||||
for(IBotaniaBoss currentBoss : bosses) {
|
||||
if(currentBoss.getBossInfoUuid().equals(infoUuid)) {
|
||||
evt.setCanceled(true);
|
||||
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
Rectangle bgRect = currentBoss.getBossBarTextureRect();
|
||||
Rectangle fgRect = currentBoss.getBossBarHPTextureRect();
|
||||
String name = evt.getBossInfo().getName().getFormattedText();
|
||||
int c = evt.getResolution().getScaledWidth() / 2;
|
||||
int x = evt.getX();
|
||||
int y = evt.getY();
|
||||
int xf = x + (bgRect.width - fgRect.width) / 2;
|
||||
int yf = y + (bgRect.height - fgRect.height) / 2;
|
||||
int fw = (int) ((double) fgRect.width * (evt.getBossInfo().getPercent()));
|
||||
int tx = c - mc.fontRendererObj.getStringWidth(name) / 2;
|
||||
|
||||
GlStateManager.color(1F, 1F, 1F, 1F);
|
||||
int auxHeight = currentBoss.bossBarRenderCallback(evt.getResolution(), x, y);
|
||||
GlStateManager.enableBlend();
|
||||
GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
||||
mc.renderEngine.bindTexture(currentBoss.getBossBarTexture());
|
||||
drawBar(currentBoss, x, y, bgRect.x, bgRect.y, bgRect.width, bgRect.height, true);
|
||||
drawBar(currentBoss, xf, yf, fgRect.x, fgRect.y, fw, fgRect.height, false);
|
||||
mc.fontRendererObj.drawStringWithShadow(name, tx, y - 10, 0xA2018C);
|
||||
GlStateManager.enableBlend();
|
||||
evt.setIncrement(Math.max(bgRect.height, fgRect.height) + auxHeight + mc.fontRendererObj.FONT_HEIGHT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void render(ScaledResolution res) {
|
||||
if(currentBoss == null)
|
||||
return;
|
||||
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
Rectangle bgRect = currentBoss.getBossBarTextureRect();
|
||||
Rectangle fgRect = currentBoss.getBossBarHPTextureRect();
|
||||
String name = currentBoss.getEntity().getDisplayName().getFormattedText();
|
||||
int c = res.getScaledWidth() / 2;
|
||||
int x = c - bgRect.width / 2;
|
||||
int y = 20;
|
||||
int xf = x + (bgRect.width - fgRect.width) / 2;
|
||||
int yf = y + (bgRect.height - fgRect.height) / 2;
|
||||
int fw = (int) ((double) fgRect.width * (currentBoss.getEntity().getHealth() / currentBoss.getEntity().getMaxHealth()));
|
||||
int tx = c - mc.fontRendererObj.getStringWidth(name) / 2;
|
||||
|
||||
GlStateManager.color(1F, 1F, 1F, 1F);
|
||||
currentBoss.bossBarRenderCallback(res, x, y);
|
||||
GlStateManager.enableBlend();
|
||||
GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
||||
mc.renderEngine.bindTexture(currentBoss.getBossBarTexture());
|
||||
drawBar(x, y, bgRect.x, bgRect.y, bgRect.width, bgRect.height, true);
|
||||
drawBar(xf, yf, fgRect.x, fgRect.y, fw, fgRect.height, false);
|
||||
mc.fontRendererObj.drawStringWithShadow(name, tx, y - 10, 0xA2018C);
|
||||
GlStateManager.enableBlend();
|
||||
|
||||
Entity e = (Entity) currentBoss;
|
||||
EntityPlayer p = mc.thePlayer;
|
||||
if(e.isDead || !p.worldObj.loadedEntityList.contains(e) || MathHelper.pointDistanceSpace(e.posX, e.posY, e.posZ, p.posX, p.posY, p.posZ) > 32)
|
||||
currentBoss = null;
|
||||
}
|
||||
|
||||
private static void drawBar(int x, int y, int u, int v, int w, int h, boolean bg) {
|
||||
private static void drawBar(IBotaniaBoss currentBoss, int x, int y, int u, int v, int w, int h, boolean bg) {
|
||||
boolean useShader = currentBoss instanceof IBotaniaBossWithShader;
|
||||
if(useShader) {
|
||||
IBotaniaBossWithShader shader = (IBotaniaBossWithShader) currentBoss;
|
||||
|
||||
@@ -206,8 +206,6 @@ public final class HUDHandler {
|
||||
if(anyRequest)
|
||||
renderManaInvBar(event.getResolution(), creative, totalMana, totalMaxMana);
|
||||
|
||||
profiler.endStartSection("bossBar");
|
||||
BossBarHandler.render(event.getResolution());
|
||||
profiler.endStartSection("itemsRemaining");
|
||||
ItemsRemainingRenderHandler.render(event.getResolution(), event.getPartialTicks());
|
||||
profiler.endSection();
|
||||
|
||||
@@ -35,6 +35,7 @@ import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
||||
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
import net.minecraftforge.fml.relauncher.ReflectionHelper;
|
||||
import vazkii.botania.api.boss.IBotaniaBoss;
|
||||
import vazkii.botania.api.item.IExtendedPlayerController;
|
||||
import vazkii.botania.api.lexicon.LexiconEntry;
|
||||
import vazkii.botania.api.lexicon.multiblock.Multiblock;
|
||||
@@ -44,6 +45,7 @@ import vazkii.botania.api.wiki.IWikiProvider;
|
||||
import vazkii.botania.api.wiki.WikiHooks;
|
||||
import vazkii.botania.client.challenge.ModChallenges;
|
||||
import vazkii.botania.client.core.handler.BaubleRenderHandler;
|
||||
import vazkii.botania.client.core.handler.BossBarHandler;
|
||||
import vazkii.botania.client.core.handler.BotaniaPlayerController;
|
||||
import vazkii.botania.client.core.handler.BoundTileRenderer;
|
||||
import vazkii.botania.client.core.handler.ClientTickHandler;
|
||||
@@ -201,6 +203,7 @@ public class ClientProxy extends CommonProxy {
|
||||
MinecraftForge.EVENT_BUS.register(new MultiblockRenderHandler());
|
||||
MinecraftForge.EVENT_BUS.register(new SkyblockRenderEvents());
|
||||
MinecraftForge.EVENT_BUS.register(new RenderLexicon());
|
||||
MinecraftForge.EVENT_BUS.register(new BossBarHandler());
|
||||
|
||||
if(ConfigHandler.useAdaptativeConfig)
|
||||
MinecraftForge.EVENT_BUS.register(new AdaptorNotifier());
|
||||
@@ -472,5 +475,15 @@ public class ClientProxy extends CommonProxy {
|
||||
public void lightningFX(World world, Vector3 vectorStart, Vector3 vectorEnd, float ticksPerMeter, long seed, int colorOuter, int colorInner) {
|
||||
LightningHandler.spawnLightningBolt(world, vectorStart, vectorEnd, ticksPerMeter, seed, colorOuter, colorInner);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addBoss(IBotaniaBoss boss) {
|
||||
BossBarHandler.bosses.add(boss);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeBoss(IBotaniaBoss boss) {
|
||||
BossBarHandler.bosses.remove(boss);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,8 +55,6 @@ public class RenderDoppleganger extends RenderBiped<EntityDoppleganger> {
|
||||
|
||||
@Override
|
||||
public void doRender(EntityDoppleganger dopple, double par2, double par4, double par6, float par8, float par9) {
|
||||
BossBarHandler.setCurrentBoss(dopple);
|
||||
|
||||
int invulTime = dopple.getInvulTime();
|
||||
if(invulTime > 0) {
|
||||
grainIntensity = invulTime > 20 ? 1F : invulTime * 0.05F;
|
||||
|
||||
@@ -223,11 +223,6 @@ public class InternalMethodHandler extends DummyMethodHandler {
|
||||
return BossBarHandler.defaultBossBar;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBossStatus(IBotaniaBoss status) {
|
||||
BossBarHandler.setCurrentBoss(status);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldForceCheck() {
|
||||
return ConfigHandler.flowerForceCheck;
|
||||
|
||||
@@ -37,6 +37,7 @@ import net.minecraftforge.fml.common.event.FMLServerStartingEvent;
|
||||
import net.minecraftforge.fml.common.network.NetworkRegistry;
|
||||
import org.apache.logging.log4j.Level;
|
||||
import vazkii.botania.api.BotaniaAPI;
|
||||
import vazkii.botania.api.boss.IBotaniaBoss;
|
||||
import vazkii.botania.api.lexicon.ITwoNamedPage;
|
||||
import vazkii.botania.api.lexicon.LexiconEntry;
|
||||
import vazkii.botania.api.lexicon.LexiconPage;
|
||||
@@ -321,4 +322,12 @@ public class CommonProxy {
|
||||
// NO-OP
|
||||
}
|
||||
|
||||
public void addBoss(IBotaniaBoss boss) {
|
||||
// NO-OP
|
||||
}
|
||||
|
||||
public void removeBoss(IBotaniaBoss boss) {
|
||||
// NO-OP
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,6 +10,7 @@
|
||||
*/
|
||||
package vazkii.botania.common.entity;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.Minecraft;
|
||||
@@ -28,6 +29,7 @@ import net.minecraft.entity.monster.EntitySkeleton;
|
||||
import net.minecraft.entity.monster.EntityWitch;
|
||||
import net.minecraft.entity.monster.EntityZombie;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.init.MobEffects;
|
||||
@@ -115,6 +117,7 @@ public class EntityDoppleganger extends EntityCreature implements IBotaniaBossWi
|
||||
private static final DataParameter<Boolean> AGGRO = EntityDataManager.createKey(EntityDoppleganger.class, DataSerializers.BOOLEAN);
|
||||
private static final DataParameter<Boolean> HARD_MODE = EntityDataManager.createKey(EntityDoppleganger.class, DataSerializers.BOOLEAN);
|
||||
private static final DataParameter<BlockPos> SOURCE = EntityDataManager.createKey(EntityDoppleganger.class, DataSerializers.BLOCK_POS);
|
||||
private static final DataParameter<Optional<UUID>> BOSSINFO_ID = EntityDataManager.createKey(EntityDoppleganger.class, DataSerializers.OPTIONAL_UNIQUE_ID);
|
||||
|
||||
private static final BlockPos[] PYLON_LOCATIONS = {
|
||||
new BlockPos(4, 1, 4),
|
||||
@@ -144,6 +147,7 @@ public class EntityDoppleganger extends EntityCreature implements IBotaniaBossWi
|
||||
tasks.addTask(1, new EntityAIWatchClosest(this, EntityPlayer.class, Float.MAX_VALUE));
|
||||
isImmuneToFire = true;
|
||||
experienceValue = 825;
|
||||
Botania.proxy.addBoss(this);
|
||||
}
|
||||
|
||||
public static MultiblockSet makeMultiblockSet() {
|
||||
@@ -273,6 +277,7 @@ public class EntityDoppleganger extends EntityCreature implements IBotaniaBossWi
|
||||
dataManager.register(DATA_MOB_SPAWN_TICKS, 0);
|
||||
dataManager.register(HARD_MODE, false);
|
||||
dataManager.register(PLAYER_COUNT, 0);
|
||||
dataManager.register(BOSSINFO_ID, Optional.absent());
|
||||
}
|
||||
|
||||
public int getInvulTime() {
|
||||
@@ -499,6 +504,7 @@ public class EntityDoppleganger extends EntityCreature implements IBotaniaBossWi
|
||||
|
||||
@Override
|
||||
public void setDead() {
|
||||
Botania.proxy.removeBoss(this);
|
||||
BlockPos source = getSource();
|
||||
Botania.proxy.playRecordClientSided(worldObj, source, null);
|
||||
isPlayingMusic = false;
|
||||
@@ -515,7 +521,10 @@ public class EntityDoppleganger extends EntityCreature implements IBotaniaBossWi
|
||||
public void onLivingUpdate() {
|
||||
super.onLivingUpdate();
|
||||
|
||||
bossInfo.setPercent(getHealth() / getMaxHealth());
|
||||
if (!worldObj.isRemote) {
|
||||
dataManager.set(BOSSINFO_ID, Optional.of(bossInfo.getUniqueId()));
|
||||
bossInfo.setPercent(getHealth() / getMaxHealth());
|
||||
}
|
||||
|
||||
if(!getPassengers().isEmpty())
|
||||
this.dismountRidingEntity();
|
||||
@@ -764,6 +773,20 @@ public class EntityDoppleganger extends EntityCreature implements IBotaniaBossWi
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBossVisibleTo(EntityPlayerMP player)
|
||||
{
|
||||
super.setBossVisibleTo(player);
|
||||
this.bossInfo.addPlayer(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBossNonVisibleTo(EntityPlayerMP player)
|
||||
{
|
||||
super.setBossNonVisibleTo(player);
|
||||
this.bossInfo.removePlayer(player);
|
||||
}
|
||||
|
||||
private void spawnMissile() {
|
||||
if(!worldObj.isRemote) {
|
||||
EntityMagicMissile missile = new EntityMagicMissile(this, true);
|
||||
@@ -879,7 +902,7 @@ public class EntityDoppleganger extends EntityCreature implements IBotaniaBossWi
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void bossBarRenderCallback(ScaledResolution res, int x, int y) {
|
||||
public int bossBarRenderCallback(ScaledResolution res, int x, int y) {
|
||||
GlStateManager.pushMatrix();
|
||||
int px = x + 160;
|
||||
int py = y + 12;
|
||||
@@ -897,16 +920,13 @@ public class EntityDoppleganger extends EntityCreature implements IBotaniaBossWi
|
||||
mc.fontRendererObj.drawStringWithShadow("" + getPlayerCount(), px + 15, py + 4, 0xFFFFFF);
|
||||
mc.fontRendererObj.setUnicodeFlag(unicode);
|
||||
GlStateManager.popMatrix();
|
||||
|
||||
return 5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getBossInfoUuid() {
|
||||
return bossInfo.getUniqueId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityLivingBase getEntity() {
|
||||
return this;
|
||||
return dataManager.get(BOSSINFO_ID).or(new UUID(0, 0));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in new issue
Block a user