Skip to content

Commit

Permalink
added potion HUD, disabling inventory shift when you have potion effe…
Browse files Browse the repository at this point in the history
…cts, and fixed crash when clicking an emoji out of range in the emoji picker
  • Loading branch information
PepperLola committed Apr 7, 2021
1 parent a2bf534 commit 4680270
Show file tree
Hide file tree
Showing 13 changed files with 293 additions and 9 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ sourceSets {
main.resources.srcDirs += '../shared/main/resources'
}

version = "1.17.0"
version = "1.17.1"
group= "com.palight.playerinfo" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "playerinfo"

Expand Down
5 changes: 3 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#Wed Apr 07 10:57:56 PDT 2021
distributionUrl=https\://services.gradle.org/distributions/gradle-4.8.1-all.zip
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.8.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
5 changes: 3 additions & 2 deletions src/main/java/com/palight/playerinfo/PlayerInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class PlayerInfo
//TODO update version here and in build.gradle
public static final String NAME = "playerinfo";
public static final String MODID = "playerinfo";
public static final String VERSION = "1.17.0";
public static final String VERSION = "1.17.1";
public static String commitHash;
public static String defaultBranchName = "master";
public static String githubAPIURL = "https://api.github.com/repos/PepperLola/playerinfo/git/refs/heads/" + defaultBranchName;
Expand Down Expand Up @@ -90,10 +90,11 @@ public class PlayerInfo
modules.put("stats", new StatsMod());
modules.put("clock", new ClockMod());
modules.put("memory", new MemoryMod());
modules.put("potions", new PotionsMod());
}

@EventHandler
public void init(FMLInitializationEvent event) throws IllegalAccessException, IOException {
public void init(FMLInitializationEvent event) throws IOException {
System.out.println("(PLAYERINFO) INITIALIZING MOD!");
proxy.init(event);
createDataFolder();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package com.palight.playerinfo.gui.ingame.widgets.impl;

import com.palight.playerinfo.PlayerInfo;
import com.palight.playerinfo.gui.ingame.widgets.GuiIngameWidget;
import com.palight.playerinfo.modules.impl.gui.PotionsMod;
import com.palight.playerinfo.util.MCUtil;
import com.palight.playerinfo.util.NumberUtil;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.resources.I18n;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.ResourceLocation;

import java.util.Collection;
import java.util.Iterator;

public class PotionsWidget extends GuiIngameWidget {
protected static final ResourceLocation inventoryBackground = new ResourceLocation("textures/gui/container/inventory.png");

private PotionsMod module;

public PotionsWidget() {
super(0, -1, 140, 64);
}

@Override
public void render(Minecraft mc) {
if (module == null) {
module = (PotionsMod) getModule();
}
if (this.getPosition().getY() == -1) {
ScaledResolution res = new ScaledResolution(mc);
this.getPosition().setY((res.getScaledHeight() - this.height) / 2);
}
Collection<PotionEffect> collection = mc.thePlayer.getActivePotionEffects();

if (!collection.isEmpty()) {
int itemHeight = 33;
if (collection.size() > 5) {
itemHeight = 132 / (collection.size() - 1);
}

if (module.renderTransparentBackground) {
this.height = collection.size() * itemHeight;
super.render(mc);
}

GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
GlStateManager.disableLighting();

Iterator potionEffectIterator = mc.thePlayer.getActivePotionEffects().iterator();

int yPosition = this.getPosition().getY();
int xPosition = this.getPosition().getX();

while(potionEffectIterator.hasNext()) {
PotionEffect effect = (PotionEffect)potionEffectIterator.next();
Potion potion = Potion.potionTypes[effect.getPotionID()];

if (potion.shouldRender(effect)) {
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
mc.getTextureManager().bindTexture(inventoryBackground);

if (module.renderBackground) {
this.drawTexturedModalRect(xPosition, yPosition, 0, 166, 140, 32);
}

if (potion.hasStatusIcon()) {
int iconIndex = potion.getStatusIconIndex();
this.drawTexturedModalRect(xPosition + 6, yPosition + 7, iconIndex % 8 * 18, 198 + iconIndex / 8 * 18, 18, 18);
}

potion.renderInventoryEffect(xPosition, yPosition, effect, mc);

if (potion.shouldRenderInvText(effect)) {
String formattedName = I18n.format(potion.getName());
if (module.renderLevelAsNumber) {
formattedName += " " + (effect.getAmplifier() + 1);
} else {
formattedName += " " + NumberUtil.integerToRoman(effect.getAmplifier() + 1);
}

PlayerInfo.instance.fontRendererObj.drawStringWithShadow(formattedName, (float) (xPosition + 10 + 18), (float) (yPosition + 6), 16777215);
String durationString = Potion.getDurationString(effect);
PlayerInfo.instance.fontRendererObj.drawStringWithShadow(durationString, (float) (xPosition + 10 + 18), (float) (yPosition + 6 + 10), 8355711);
}

yPosition += itemHeight;
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class DisplayTweaksGui extends CustomGuiScreenScrollable {
private GuiCheckBox stackChatMessages;
private GuiCheckBox transparentChat;
private GuiCheckBox renderOwnName;
private GuiCheckBox disableInventoryShift;

private DisplayTweaksMod module;

Expand All @@ -47,8 +48,9 @@ public void initGui() {
renderPingAsText = new GuiCheckBox(4, buttonX, buttonY + 128, "Render ping as text", module.renderPingAsText);
renderUnicodeText = new GuiCheckBox(5, buttonX, buttonY + 160, "Render custom unicode font", module.unicodeFontRendererEnabled);
stackChatMessages = new GuiCheckBox(6, buttonX, buttonY + 192, "Stack chat messages", module.stackChatMessages);
transparentChat = new GuiCheckBox(7, buttonX, buttonY + 224, "Transparent Chat", module.transparentChat);
renderOwnName = new GuiCheckBox(8, buttonX, buttonY + 256, "Render Own Name", module.renderOwnName);
transparentChat = new GuiCheckBox(7, buttonX, buttonY + 224, "Transparent chat", module.transparentChat);
renderOwnName = new GuiCheckBox(8, buttonX, buttonY + 256, "Render own name", module.renderOwnName);
disableInventoryShift = new GuiCheckBox(9, buttonX, buttonY + 288, "Disable inventory shift", module.disableInventoryShift);

this.guiElements.addAll(Arrays.asList(
this.disableWater,
Expand All @@ -59,7 +61,8 @@ public void initGui() {
this.renderUnicodeText,
this.stackChatMessages,
this.transparentChat,
this.renderOwnName
this.renderOwnName,
this.disableInventoryShift
));
}

Expand All @@ -83,6 +86,8 @@ protected void widgetClicked(GuiCustomWidget widget) {
module.transparentChat = transparentChat.checked;
} else if (widget.id == renderOwnName.id) {
module.renderOwnName = renderOwnName.checked;
} else if (widget.id == disableInventoryShift.id) {
module.disableInventoryShift = disableInventoryShift.checked;
}

ModConfiguration.syncFromGUI();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.palight.playerinfo.gui.screens.impl.options.modules.gui;

import com.palight.playerinfo.PlayerInfo;
import com.palight.playerinfo.gui.screens.CustomGuiScreenScrollable;
import com.palight.playerinfo.gui.widgets.GuiCustomWidget;
import com.palight.playerinfo.gui.widgets.impl.GuiCheckBox;
import com.palight.playerinfo.modules.impl.gui.CustomMainMenuMod;
import com.palight.playerinfo.modules.impl.gui.PotionsMod;
import com.palight.playerinfo.options.ModConfiguration;

import java.util.Arrays;

public class PotionsGui extends CustomGuiScreenScrollable {
private int buttonX;
private int buttonY;

private GuiCheckBox renderBackground;
private GuiCheckBox renderLevelAsNumber;
private GuiCheckBox renderTransparentBackground;

private PotionsMod module;

public PotionsGui() {
super("screen.potions");
}

@Override
public void initGui() {
super.initGui();

if (module == null) {
module = (PotionsMod) PlayerInfo.getModules().get("potions");
}

buttonX = guiX + 32;
buttonY = guiY + 32;

renderBackground = new GuiCheckBox(0, buttonX, buttonY, "Show background", module.renderBackground);
renderLevelAsNumber = new GuiCheckBox(1, buttonX, buttonY + 32, "Show level as number", module.renderLevelAsNumber);
renderTransparentBackground = new GuiCheckBox(2, buttonX, buttonY + 64, "Show transparent background", module.renderTransparentBackground);

this.guiElements.addAll(Arrays.asList(
this.renderBackground,
this.renderLevelAsNumber,
this.renderTransparentBackground
));
}

@Override
protected void widgetClicked(GuiCustomWidget widget) {
if (module == null) {
module = (PotionsMod) PlayerInfo.getModules().get("potions");
}

super.widgetClicked(widget);

if (widget.id == renderBackground.id) {
module.renderBackground = renderBackground.checked;
} else if (widget.id == renderLevelAsNumber.id) {
module.renderLevelAsNumber = renderLevelAsNumber.checked;
} else if (widget.id == renderTransparentBackground.id) {
module.renderTransparentBackground = renderTransparentBackground.checked;
}

ModConfiguration.syncFromGUI();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public String widgetClicked(int mouseX, int mouseY) {
int y = (mouseY - this.yPosition) / this.cellHeight;

int i = offset + (y * rows) + x;
if (i >= TextReplacementMod.nameList.size()) return "";

return TextReplacementMod.nameList.get(i);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.palight.playerinfo.mixin.client.gui;

import com.palight.playerinfo.PlayerInfo;
import com.palight.playerinfo.modules.impl.gui.DisplayTweaksMod;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.InventoryEffectRenderer;
import net.minecraft.inventory.Container;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;

@Mixin(InventoryEffectRenderer.class)
public class MixinInventoryEffectRenderer extends GuiContainer {
@Shadow private boolean hasActivePotionEffects;

private DisplayTweaksMod module;

public MixinInventoryEffectRenderer(Container p_i1072_1_) {
super(p_i1072_1_);
}

/**
* @reason Disable inventory GUI shifting when the player has potion effects
* @author palight
*/
@Overwrite
protected void updateActivePotionEffects() {
if (module == null) {
module = (DisplayTweaksMod) PlayerInfo.getModules().get("displayTweaks");
}
boolean hasVisibleEffect = false;

for (PotionEffect effect : this.mc.thePlayer.getActivePotionEffects()) {
Potion potion = Potion.potionTypes[effect.getPotionID()];
if (potion.shouldRender(effect)) {
hasVisibleEffect = true;
break;
}
}

if (!this.mc.thePlayer.getActivePotionEffects().isEmpty() && hasVisibleEffect) {
if (module.disableInventoryShift) {
this.guiLeft = (this.width - this.xSize) / 2;
} else {
this.guiLeft = 160 + (this.width - this.xSize - 200) / 2;
}
this.hasActivePotionEffects = true;
} else {
this.guiLeft = (this.width - this.xSize) / 2;
this.hasActivePotionEffects = false;
}

}

@Override
protected void drawGuiContainerBackgroundLayer(float v, int i, int i1) {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public class DisplayTweaksMod extends Module {
public boolean transparentChat = false;
@ConfigOption
public boolean renderOwnName = false;
@ConfigOption
public boolean disableInventoryShift = false;

public static boolean hardcoreHearts = false;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.palight.playerinfo.modules.impl.gui;

import com.palight.playerinfo.gui.ingame.widgets.impl.PotionsWidget;
import com.palight.playerinfo.gui.screens.impl.options.modules.gui.PotionsGui;
import com.palight.playerinfo.modules.Module;
import com.palight.playerinfo.options.ConfigOption;

public class PotionsMod extends Module {
@ConfigOption
public boolean renderBackground = true;
@ConfigOption
public boolean renderLevelAsNumber = false;
@ConfigOption
public boolean renderTransparentBackground = false;

public PotionsMod() {
super("potions", "Potions", "Displays active potion effects.", ModuleType.GUI, new PotionsGui(), new PotionsWidget());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public StatsMod() {
@SubscribeEvent
public void onPlayerJoin(EntityJoinWorldEvent event) {

if (!(event.entity instanceof EntityPlayer)) return;
if (!(event.entity instanceof EntityPlayer) || !event.world.isRemote) return;
EntityPlayer player = ((EntityPlayer) event.entity);
EntityPlayerSP clientPlayer = Minecraft.getMinecraft().thePlayer;
if (player.getUniqueID().equals(clientPlayer.getUniqueID())) {
Expand Down
31 changes: 31 additions & 0 deletions src/main/java/com/palight/playerinfo/util/NumberUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,38 @@
import com.palight.playerinfo.math.parsing.InvalidExpressionException;
import org.apache.commons.lang3.ArrayUtils;

import java.util.TreeMap;

public class NumberUtil {

private static final TreeMap<Integer, String> treemap = new TreeMap<>();
static {
treemap.put(1000, "M");
treemap.put(900, "CM");
treemap.put(500, "D");
treemap.put(400, "CD");
treemap.put(100, "C");
treemap.put(90, "XC");
treemap.put(50, "L");
treemap.put(40, "XL");
treemap.put(10, "X");
treemap.put(9, "IX");
treemap.put(5, "V");
treemap.put(4, "IV");
treemap.put(1, "I");

}

public static String integerToRoman(int number) {
System.out.println("TO ROMAN: " + number);
if (number <= 0) return "";
int l = treemap.floorKey(number);
if (number == l) {
return treemap.get(number);
}
return treemap.get(l) + integerToRoman(number - l);
}

public static boolean isBetween(int num, int low, int high) {
return low <= num && num <= high;
}
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/mixins.playerinfo.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"client.gui.MixinGuiIngameForge",
"client.gui.MixinGuiNewChat",
"client.gui.MixinGuiPlayerTabOverlay",
"client.gui.MixinInventoryEffectRenderer",
"client.network.MixinNetHandlerPlayClient",
"client.resources.MixinLocale",
"client.world.MixinChunk",
Expand Down

0 comments on commit 4680270

Please sign in to comment.