Skip to content

Commit

Permalink
switching to @config annotations and adding option to only show entit…
Browse files Browse the repository at this point in the history
…y bars when a weapon is equiped
  • Loading branch information
frodare committed Sep 23, 2018
1 parent b49c327 commit 077bd0a
Show file tree
Hide file tree
Showing 12 changed files with 207 additions and 171 deletions.
8 changes: 3 additions & 5 deletions src/main/java/net/torocraft/torohud/ToroHUD.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package net.torocraft.torohud;

import net.minecraft.server.MinecraftServer;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.Mod.Instance;
Expand All @@ -12,10 +11,9 @@
import net.minecraftforge.fml.common.event.FMLServerStartingEvent;
import net.minecraftforge.fml.common.network.NetworkRegistry;
import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper;
import net.torocraft.torohud.config.ConfigurationHandler;
import net.torocraft.torohud.proxy.CommonProxy;

@Mod(modid = ToroHUD.MODID, name = ToroHUD.MODNAME, version = ToroHUD.VERSION, guiFactory = "net.torocraft.torohud.gui.GuiFactory")
@Mod(modid = ToroHUD.MODID, name = ToroHUD.MODNAME, version = ToroHUD.VERSION)

public class ToroHUD {

Expand All @@ -37,8 +35,8 @@ public class ToroHUD {
public void preInit(FMLPreInitializationEvent e) {
PROXY.preInit(e);

ConfigurationHandler.init(e.getSuggestedConfigurationFile());
MinecraftForge.EVENT_BUS.register(new ConfigurationHandler());
//ConfigurationHandler.init(e.getSuggestedConfigurationFile());
//MinecraftForge.EVENT_BUS.register(new ConfigurationHandler());
}

@EventHandler
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static Relation determineRelation(Entity entity) {
}

protected Relation determineRelation() {
return determineRelation(entity);
return determineRelation(entity);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.monster.EntityGhast;
import net.minecraft.util.math.MathHelper;
import net.minecraftforge.common.config.Config;
import net.minecraftforge.common.config.Config.Name;
import net.torocraft.torohud.ToroHUD;

@Config(modid = ToroHUD.MODID, name = "Entity Display Settings")
public class EntityDisplay implements IDisplay {

private static final int RENDER_HEIGHT = 30;
Expand All @@ -33,6 +37,9 @@ public class EntityDisplay implements IDisplay {
private float prevPrevYahHead;
private int scale = 1;

@Name("Show 3D Model of Entity")
public static boolean showEntityModel = true; // config.getBoolean("Show 3D Model of Entity", Configuration.CATEGORY_CLIENT, true, "Shows a 3D model of the entity being targeted");

public EntityDisplay(Minecraft mc) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ private void drawEffects() {
String duration = Potion.getPotionDurationString(potion, 1.0F);
mc.fontRenderer.drawStringWithShadow(duration, x, y + 18, 0xe0e0e0);

mc.fontRenderer.drawStringWithShadow( getAmplifierText(potion), x, y, 0xc0c0c0);
mc.fontRenderer.drawStringWithShadow(getAmplifierText(potion), x, y, 0xc0c0c0);

x += 24;
}
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/net/torocraft/torohud/events/Events.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
import net.minecraft.entity.EntityLivingBase;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType;
import net.minecraftforge.common.config.Config.Type;
import net.minecraftforge.common.config.ConfigManager;
import net.minecraftforge.event.entity.living.LivingDamageEvent;
import net.minecraftforge.event.entity.living.LivingHealEvent;
import net.minecraftforge.fml.client.event.ConfigChangedEvent.OnConfigChangedEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.network.NetworkRegistry.TargetPoint;
Expand All @@ -14,6 +17,13 @@
@Mod.EventBusSubscriber()
public class Events {

@SubscribeEvent
public static void onConfigChanged(OnConfigChangedEvent event){
if(event.getModID().equals(ToroHUD.MODID)){
ConfigManager.sync(ToroHUD.MODID, Type.INSTANCE);
}
}

@SubscribeEvent
public static void displayDamage(LivingDamageEvent event) {
EntityLivingBase e = event.getEntityLiving();
Expand Down
71 changes: 50 additions & 21 deletions src/main/java/net/torocraft/torohud/gui/GuiEntityStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,52 @@
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType;
import net.minecraftforge.common.config.Config;
import net.minecraftforge.common.config.Config.Comment;
import net.minecraftforge.common.config.Config.Name;
import net.minecraftforge.common.config.Config.RangeInt;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.torocraft.torohud.ToroHUD;
import net.torocraft.torohud.config.ConfigurationHandler;
import net.torocraft.torohud.display.BarDisplay;
import net.torocraft.torohud.display.EntityDisplay;
import net.torocraft.torohud.display.IDisplay;
import net.torocraft.torohud.display.PotionDisplay;

@Config(modid = ToroHUD.MODID, name = "GUI Settings")
public class GuiEntityStatus extends Gui {

//
//
//
@Name("Disable GUI")
public static boolean disableGui = false;// config.getString("Health Bar Display", Configuration.CATEGORY_CLIENT, "HEARTS", "Display Health Bars", new String[]{"BAR", "OFF"});

// statusDisplayPosition = config
// .getString("Health Bar Position", Configuration.CATEGORY_CLIENT, "TOP LEFT", "Location of Health Bar", new String[]{"TOP LEFT", "TOP CENTER", "TOP RIGHT", "BOTTOM LEFT", "BOTTOM RIGHT"});


@Name("X Offset")
public static int xOffset = 0; //config.getInt("Health Bar X", Configuration.CATEGORY_CLIENT, 0, -20000, 20000, "With CUSTOM position, sets X position of Health Bar");

@Name("Y Offset")
public static int yOffset = 0; // config.getInt("Health Bar Y", Configuration.CATEGORY_CLIENT, 0, -20000, 20000, "With CUSTOM position, sets Y position of Health Bar");


@Name("GUI Position")
public static GuiAnchor guiPosition = GuiAnchor.TOP_LEFT;

public enum GuiAnchor {TOP_LEFT, TOP_CENTER, TOP_RIGHT, BOTTOM_LEFT, BOTTOM_RIGHT}

@Name("Hide Delay")
@Comment("Delays hiding the dialog for the given number of milliseconds")
@RangeInt(min = 50, max = 5000)
public static int hideDelay = 300; //config.getInt("Hide Delay", Configuration.CATEGORY_CLIENT, 400, 50, 5000, );

public enum Skin {NONE, BASIC}

@Name("Background Skin Selection")
public static Skin skin = Skin.BASIC; // config.getString("Skin", Configuration.CATEGORY_CLIENT, "BASIC", "Background Skin Selection", new String[]{"NONE", "BASIC", "HEAVY"});

private static final int PADDING_FROM_EDGE = 3;
private static final ResourceLocation SKIN_BASIC = new ResourceLocation(ToroHUD.MODID, "textures/gui/default_skin_basic.png");
private static final ResourceLocation SKIN_HEAVY = new ResourceLocation(ToroHUD.MODID, "textures/gui/default_skin_heavy.png");
Expand Down Expand Up @@ -52,7 +88,7 @@ public GuiEntityStatus(Minecraft mc) {

@SubscribeEvent
public void drawHealthBar(RenderGameOverlayEvent.Pre event) {
if (!showHealthBar || event.getType() != ElementType.CHAT) {
if (disableGui || !showHealthBar || event.getType() != ElementType.CHAT) {
return;
}
updateGuiAge();
Expand All @@ -62,24 +98,17 @@ public void drawHealthBar(RenderGameOverlayEvent.Pre event) {
}

private void drawSkin() {
if (ConfigurationHandler.skin.equals("NONE")) {
if (skin.equals(Skin.NONE) || !EntityDisplay.showEntityModel) {
return;
}

if (ConfigurationHandler.skin.equals("HEAVY")) {
mc.getTextureManager().bindTexture(SKIN_HEAVY);
} else {
mc.getTextureManager().bindTexture(SKIN_BASIC);
}

mc.getTextureManager().bindTexture(SKIN_BASIC);
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
Gui.drawModalRectWithCustomSizedTexture(screenX - 10, screenY - 10, 0.0f, 0.0f, 160, 60, 160, 60);
}

private void updateGuiAge() {
String entityStatusDisplay = ConfigurationHandler.entityStatusDisplay;
age = age + 15;
if (age > ConfigurationHandler.hideDelay || entityStatusDisplay.equals("OFF")) {
if (age > hideDelay) {
hideHealthBar();
}
}
Expand All @@ -90,12 +119,12 @@ private void updatePositions() {
x = screenX;
y = screenY;

if (ConfigurationHandler.showEntityModel) {
if (EntityDisplay.showEntityModel) {
entityDisplay.setPosition(x, y);
x += 40;
}

if (ConfigurationHandler.statusDisplayPosition.contains("BOTTOM")) {
if (guiPosition.equals(GuiAnchor.BOTTOM_LEFT) || guiPosition.equals(GuiAnchor.BOTTOM_RIGHT)) {
y += 6;
}

Expand All @@ -104,7 +133,7 @@ private void updatePositions() {
}

private void draw() {
if (ConfigurationHandler.showEntityModel) {
if (EntityDisplay.showEntityModel) {
entityDisplay.draw();
}
barDisplay.draw();
Expand All @@ -113,7 +142,7 @@ private void draw() {

private void adjustForDisplayPositionSetting() {

if (ConfigurationHandler.showEntityModel) {
if (EntityDisplay.showEntityModel) {
displayHeight = 40;
displayWidth = 140;
} else {
Expand All @@ -122,20 +151,20 @@ private void adjustForDisplayPositionSetting() {
}

ScaledResolution viewport = new ScaledResolution(mc);
String displayPosition = ConfigurationHandler.statusDisplayPosition;
String displayPosition = guiPosition.toString();

int sh = viewport.getScaledHeight();
int sw = viewport.getScaledWidth();

if (displayPosition.contains("TOP") || displayPosition.equals("CUSTOM")) {
if (displayPosition.contains("TOP")) {
screenY = PADDING_FROM_EDGE;
}

if (displayPosition.contains("BOTTOM")) {
screenY = sh - displayHeight - PADDING_FROM_EDGE;
}

if (displayPosition.contains("LEFT") || displayPosition.equals("CUSTOM")) {
if (displayPosition.contains("LEFT")) {
screenX = PADDING_FROM_EDGE;
}

Expand All @@ -147,8 +176,8 @@ private void adjustForDisplayPositionSetting() {
screenX = (sw - displayWidth) / 2;
}

screenX += ConfigurationHandler.statusDisplayX;
screenY += ConfigurationHandler.statusDisplayY;
screenX += xOffset;
screenY += yOffset;
}

private void showHealthBar() {
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/net/torocraft/torohud/gui/GuiFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import net.minecraftforge.fml.client.IModGuiFactory;
import net.torocraft.torohud.config.GuiConfigToroHealth;

public class GuiFactory implements IModGuiFactory {

Expand All @@ -20,7 +19,7 @@ public boolean hasConfigGui() {

@Override
public GuiScreen createConfigGui(GuiScreen parentScreen) {
return new GuiConfigToroHealth(parentScreen);
return null;// new GuiConfigToroHUD(parentScreen);
}

@Override
Expand Down
Loading

0 comments on commit 077bd0a

Please sign in to comment.