Skip to content

Commit

Permalink
Port to 1.12
Browse files Browse the repository at this point in the history
  • Loading branch information
mccreery committed Dec 18, 2017
1 parent abd06e0 commit b837eb6
Show file tree
Hide file tree
Showing 78 changed files with 1,358 additions and 987 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
gradle*
.gradle/
.classpath
.project
.settings/
bin/
build/
77 changes: 77 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
buildscript {
repositories {
jcenter()
maven { url = "http://files.minecraftforge.net/maven" }
}
dependencies {
classpath 'net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT'
}
}
apply plugin: 'net.minecraftforge.gradle.forge'
//Only edit below this line, the above code adds and enables the necessary things for Forge to be setup.


version = "1.3.9"
group = "tk.nukeduck.hud" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "hud"

sourceCompatibility = targetCompatibility = '1.8' // Need this here so eclipse task generates correctly.
compileJava {
sourceCompatibility = targetCompatibility = '1.8'
}

minecraft {
version = "1.12-14.21.1.2387"
runDir = "run"

// the mappings can be changed at any time, and must be in the following format.
// snapshot_YYYYMMDD snapshot are built nightly.
// stable_# stables are built at the discretion of the MCP team.
// Use non-default mappings at your own risk. they may not always work.
// simply re-run your setup task after changing the mappings to update your workspace.
mappings = "snapshot_20170624"
// makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable.
}

dependencies {
// you may put jars on which you depend on in ./libs
// or you may define them like so..
//compile "some.group:artifact:version:classifier"
//compile "some.group:artifact:version"

// real examples
//compile 'com.mod-buildcraft:buildcraft:6.0.8:dev' // adds buildcraft to the dev env
//compile 'com.googlecode.efficient-java-matrix-library:ejml:0.24' // adds ejml to the dev env

// the 'provided' configuration is for optional dependencies that exist at compile-time but might not at runtime.
//provided 'com.mod-buildcraft:buildcraft:6.0.8:dev'

// the deobf configurations: 'deobfCompile' and 'deobfProvided' are the same as the normal compile and provided,
// except that these dependencies get remapped to your current MCP mappings
//deobfCompile 'com.mod-buildcraft:buildcraft:6.0.8:dev'
//deobfProvided 'com.mod-buildcraft:buildcraft:6.0.8:dev'

// for more info...
// http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html
// http://www.gradle.org/docs/current/userguide/dependency_management.html

}

processResources {
// this will ensure that this task is redone when the versions change.
inputs.property "version", project.version
inputs.property "mcversion", project.minecraft.version

// replace stuff in mcmod.info, nothing else
from(sourceSets.main.resources.srcDirs) {
include 'mcmod.info'

// replace version and mcversion
expand 'version':project.version, 'mcversion':project.minecraft.version
}

// copy everything else except the mcmod.info
from(sourceSets.main.resources.srcDirs) {
exclude 'mcmod.info'
}
}
77 changes: 40 additions & 37 deletions src/main/java/tk/nukeduck/hud/BetterHud.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
import net.minecraft.client.gui.ScaledResolution;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.Mod.Instance;
import net.minecraftforge.fml.common.SidedProxy;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
Expand All @@ -22,7 +22,6 @@
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import tk.nukeduck.hud.element.ExtraGuiElement;
import tk.nukeduck.hud.element.HudElements;
import tk.nukeduck.hud.element.settings.ElementSettingPosition.Position;
import tk.nukeduck.hud.events.EntityInfoRenderer;
import tk.nukeduck.hud.events.PickupNotifier;
Expand All @@ -40,8 +39,10 @@
import tk.nukeduck.hud.util.constants.Constants;
import tk.nukeduck.hud.util.constants.Textures;

@Mod(modid = Constants.MOD_ID, name = Constants.MOD_NAME, version = "1.3.8")
@Mod(modid = Constants.MOD_ID, name = Constants.MOD_NAME, version = "1.3.9")
public class BetterHud {
@Instance(Constants.MOD_ID)
public static BetterHud INSTANCE;
@SidedProxy(clientSide="tk.nukeduck.hud.network.proxy.ClientProxy", serverSide="tk.nukeduck.hud.network.proxy.CommonProxy")
public static CommonProxy proxy;

Expand All @@ -63,26 +64,26 @@ public void init(FMLInitializationEvent e) {
registerMessage(MessagePickupHandler.class, MessagePickup.class, Side.CLIENT);
//registerMessage(MessageBreedingHandler.class, MessageBreeding.class, Side.CLIENT);

this.proxy.init();
BetterHud.proxy.init();
Textures.init();
this.proxy.initElements();
BetterHud.proxy.initElements();

FMLCommonHandler.instance().bus().register(serverStatus = new ServerStatusHandler());
MinecraftForge.EVENT_BUS.register(serverStatus = new ServerStatusHandler());
MinecraftForge.EVENT_BUS.register(pickupNotifier = new PickupNotifier());
//MinecraftForge.EVENT_BUS.register(breedNotifier = new BreedInfoNotifier());

this.proxy.initKeys();

FMLCommonHandler.instance().bus().register(this);
MinecraftForge.EVENT_BUS.register(this);

this.proxy.loadDefaults();
this.proxy.loadSettings();
BetterHud.proxy.initKeys();
BetterHud.proxy.loadDefaults();
BetterHud.proxy.loadSettings();
}

@SideOnly(Side.CLIENT)
@SubscribeEvent
public void onRenderTick(RenderGameOverlayEvent e) {
if(!proxy.elements.globalSettings.enabled) return;

if(e.isCancelable()) {
if(proxy.elements.potionBar.disableDefault.value && e.getType() == RenderGameOverlayEvent.ElementType.POTION_ICONS) {
e.setCanceled(true);
Expand All @@ -93,9 +94,9 @@ public void onRenderTick(RenderGameOverlayEvent e) {

Minecraft mc = Minecraft.getMinecraft();

if(mc != null && mc.ingameGUI != null && mc.thePlayer != null) {
if(mc != null && mc.ingameGUI != null && mc.player != null) {
mc.mcProfiler.startSection("betterHud");
// glPushAttrib(GL_ALL_ATTRIB_BITS);
//GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
GL11.glDisable(GL11.GL_LIGHTING);

GL11.glPushMatrix();
Expand All @@ -109,7 +110,7 @@ public void onRenderTick(RenderGameOverlayEvent e) {
LayoutManager layoutManager = new LayoutManager();
StringManager stringManager = new StringManager();

for(ExtraGuiElement element : this.proxy.elements.elements) {
for(ExtraGuiElement element : BetterHud.proxy.elements.elements) {
if(element.shouldRender()) {
if(element.shouldProfile()) {
mc.mcProfiler.startSection(element.getName());
Expand All @@ -131,10 +132,10 @@ public void onRenderTick(RenderGameOverlayEvent e) {
}*/

int right = resolution.getScaledWidth() - Constants.SPACER;
RenderUtil.renderStrings(mc.fontRendererObj, stringManager.get(Position.TOP_LEFT), Constants.SPACER, layoutManager.get(Position.TOP_LEFT), Position.TOP_LEFT);
RenderUtil.renderStrings(mc.fontRendererObj, stringManager.get(Position.TOP_RIGHT), right, layoutManager.get(Position.TOP_RIGHT), Position.TOP_RIGHT);
RenderUtil.renderStrings(mc.fontRendererObj, stringManager.get(Position.BOTTOM_LEFT), Constants.SPACER, resolution.getScaledHeight() - layoutManager.get(Position.BOTTOM_LEFT), Position.BOTTOM_LEFT);
RenderUtil.renderStrings(mc.fontRendererObj, stringManager.get(Position.BOTTOM_RIGHT), right, resolution.getScaledHeight() - layoutManager.get(Position.BOTTOM_RIGHT), Position.BOTTOM_RIGHT);
RenderUtil.renderStrings(mc.fontRenderer, stringManager.get(Position.TOP_LEFT), Constants.SPACER, layoutManager.get(Position.TOP_LEFT), Position.TOP_LEFT);
RenderUtil.renderStrings(mc.fontRenderer, stringManager.get(Position.TOP_RIGHT), right, layoutManager.get(Position.TOP_RIGHT), Position.TOP_RIGHT);
RenderUtil.renderStrings(mc.fontRenderer, stringManager.get(Position.BOTTOM_LEFT), Constants.SPACER, resolution.getScaledHeight() - layoutManager.get(Position.BOTTOM_LEFT), Position.BOTTOM_LEFT);
RenderUtil.renderStrings(mc.fontRenderer, stringManager.get(Position.BOTTOM_RIGHT), right, resolution.getScaledHeight() - layoutManager.get(Position.BOTTOM_RIGHT), Position.BOTTOM_RIGHT);

mc.mcProfiler.endSection();
GL11.glPopMatrix();
Expand All @@ -143,48 +144,50 @@ public void onRenderTick(RenderGameOverlayEvent e) {

GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
//GL11.glPopAttrib();
}
}

public static Random random = new Random();

//static float currentHealth = -1;
//public boolean isInWater = false;

private static short updateTicker = 0;

@SideOnly(Side.CLIENT)
@SubscribeEvent
@SideOnly(Side.CLIENT) // GuiScreen doesn't exist on server side
public void clientTick(ClientTickEvent e) {
Minecraft mc = Minecraft.getMinecraft();

updateTicker++;
if(updateTicker == 200) updateTicker = 0;

for(ExtraGuiElement element : ExtraGuiElement.UpdateSpeed.FASTER.elements) {
if(element.shouldRender()) element.update(mc);
}
if(updateTicker % 20 == 0) {
for(ExtraGuiElement element : ExtraGuiElement.UpdateSpeed.FAST.elements) {
if(proxy.elements.globalSettings.enabled) {
updateTicker++;
if(updateTicker == 200) updateTicker = 0;

for(ExtraGuiElement element : ExtraGuiElement.UpdateSpeed.FASTER.elements) {
if(element.shouldRender()) element.update(mc);
}
if(updateTicker % 100 == 0) {
for(ExtraGuiElement element : ExtraGuiElement.UpdateSpeed.MEDIUM.elements) {
if(updateTicker % 20 == 0) {
for(ExtraGuiElement element : ExtraGuiElement.UpdateSpeed.FAST.elements) {
if(element.shouldRender()) element.update(mc);
}
if(updateTicker == 0) {
for(ExtraGuiElement element : ExtraGuiElement.UpdateSpeed.SLOW.elements) {
if(updateTicker % 100 == 0) {
for(ExtraGuiElement element : ExtraGuiElement.UpdateSpeed.MEDIUM.elements) {
if(element.shouldRender()) element.update(mc);
}
if(updateTicker == 0) {
for(ExtraGuiElement element : ExtraGuiElement.UpdateSpeed.SLOW.elements) {
if(element.shouldRender()) element.update(mc);
}
}
}
}
}

if(mc != null && mc.thePlayer != null) {
if(mc != null && mc.inGameHasFocus && mc.currentScreen == null && ((ClientProxy) this.proxy).openMenu.isPressed()) {
if(mc != null && mc.player != null && mc.inGameHasFocus && mc.currentScreen == null) {
if(((ClientProxy)BetterHud.proxy).openMenu.isPressed()) {
GuiHUDMenu gui = new GuiHUDMenu();
gui.initGui();
mc.displayGuiScreen(gui);
} else if(((ClientProxy)BetterHud.proxy).disable.isPressed()) {
((ClientProxy)BetterHud.proxy).elements.globalSettings.enabled = !((ClientProxy)BetterHud.proxy).elements.globalSettings.enabled;
}
}
}
Expand Down
12 changes: 5 additions & 7 deletions src/main/java/tk/nukeduck/hud/element/ExtraGuiElement.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraft.client.resources.I18n;
import tk.nukeduck.hud.element.settings.ElementSetting;
import tk.nukeduck.hud.element.settings.ElementSettingDivider;
import tk.nukeduck.hud.util.Bounds;
import tk.nukeduck.hud.util.FormatUtil;
import tk.nukeduck.hud.util.LayoutManager;
import tk.nukeduck.hud.util.StringManager;

Expand All @@ -28,7 +26,7 @@ public abstract class ExtraGuiElement {

/** @return The localized name of this element. */
public final String getLocalizedName() {
return FormatUtil.translatePre("element." + this.getName());
return I18n.format("betterHud.element." + this.getName());
}

public Bounds getBounds(ScaledResolution resolution) {
Expand Down Expand Up @@ -66,20 +64,20 @@ public final void loadSettings(HashMap<String, String> keyVals) {
if(keyVals.containsKey("enabled")) this.enabled = Boolean.parseBoolean(keyVals.get("enabled"));

for(ElementSetting setting : this.settings) {
if(setting instanceof ElementSettingDivider) continue;
if(setting instanceof ElementSettingDivider || setting.getName() == "enabled") continue;
if(keyVals.containsKey(setting.getName())) setting.fromString(keyVals.get(setting.getName()));
}
}

/** Saves this element's settings into a key-value combination map.
* @return Key-value combinations containing this element's setting names and values. */
public final HashMap<String, String> saveSettings() {
/*public final HashMap<String, String> saveSettings() {
HashMap<String, String> keyVals = new HashMap<String, String>();
for(ElementSetting setting : this.settings) {
keyVals.put(setting.getName(), setting.toString());
}
return keyVals;
}
}*/

/** Register updates for this element at the specified speed.
* @param speed The speed to update this element at. */
Expand Down
Loading

0 comments on commit b837eb6

Please sign in to comment.