Skip to content

Commit

Permalink
Forge compatibility fix and minor formatting cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
EasyMFnE committed Oct 2, 2014
1 parent 39885e1 commit 439fd19
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 39 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -3,4 +3,6 @@
/.classpath
/lib
/.project
/res/CHANGES
/res/README.md
/.settings
3 changes: 3 additions & 0 deletions CHANGES
@@ -1,3 +1,6 @@
[2014-10-02] v1.0.1
- Fix for compatibility with Forge and deobfuscated clients.

[2014-09-30] v1.0.0
- Configuration panel now allows customization of potion colors.

Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -4,7 +4,7 @@
[Bug Report](https://github.com/EasyMFnE/PotionColorizer/issues) |
[Donate](https://www.paypal.com/cgi-bin/webscr?hosted_button_id=457RX2KYUDY5G&item_name=PotionColorizer&cmd=_s-xclick)</center>

<center>**Latest Version:** v1.0.0 for mc1.7.10</center>
<center>**Latest Version:** v1.0.1 for mc1.7.10</center>

## About ##

Expand Down
6 changes: 3 additions & 3 deletions java/net/easymfne/potioncolorizer/GuiHexColorField.java
Expand Up @@ -6,9 +6,9 @@
* Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* PotionColorizer is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* PotionColorizer is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
Expand Down
53 changes: 40 additions & 13 deletions java/net/easymfne/potioncolorizer/LiteModPotionColorizer.java
Expand Up @@ -6,9 +6,9 @@
* Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* PotionColorizer is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* PotionColorizer is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
Expand Down Expand Up @@ -55,7 +55,9 @@ public class LiteModPotionColorizer implements LiteMod, InitCompleteListener,

/** Name/Version information. */
public static final String MOD_NAME = "PotionColorizer";
public static final String MOD_VERSION = "1.0.0";
public static final String MOD_VERSION = "1.0.1";

private static final int JUMP_BOOST_COLOR_1_8 = 2293580;

/** Modification instance. */
public static LiteModPotionColorizer instance;
Expand Down Expand Up @@ -161,7 +163,7 @@ public void init(File configPath) {
Integer.valueOf(potion.getLiquidColor()));
}
}
defaultColors.put(Potion.jump.getName(), 2293580);
defaultColors.put(Potion.jump.getName(), JUMP_BOOST_COLOR_1_8);
LiteLoaderLogger.info("Saved %d default potion liquid colors.",
defaultColors.size());
}
Expand All @@ -188,19 +190,44 @@ public void onTick(Minecraft minecraft, float partialTicks, boolean inGame,
* color is not defined, reset its current color to the default if
* necessary.
*
* @throws IllegalArgumentException
* If a potion does not have a liquid color field.
* @throws IllegalAccessException
* If a potion does not have an accessible liquid color field.
* @throws NoSuchFieldException
* If the Potion class does not have the liquid color field.
* @throws SecurityException
* If a security manager prevents access to liquid color field.
*/
private void setPotionColors() throws IllegalArgumentException,
IllegalAccessException, NoSuchFieldException, SecurityException {
Field f =
Potion.class.getDeclaredField(PotionObf.potion_liquidColor.obf);
private void setPotionColors() throws NoSuchFieldException,
IllegalAccessException {
for (int i = 0; i < PotionObf.potion_liquidColor.names.length; i++) {
try {
setPotionColors(PotionObf.potion_liquidColor.names[i]);
return;
} catch (NoSuchFieldException e) {
if (i == PotionObf.potion_liquidColor.names.length - 1) {
throw e;
}
} catch (IllegalAccessException e) {
if (i == PotionObf.potion_liquidColor.names.length - 1) {
throw e;
}
}
}
}

/**
* Using reflection, modify potion colors to custom values via the given
* field name. If a custom color is not defined, reset its current color to
* the default if necessary.
*
* @param fieldName
* The name of the liquid color field.
* @throws IllegalAccessException
* If a potion does not have an accessible field of that name.
* @throws NoSuchFieldException
* If the Potion class does not have a field of that name.
*/
private void setPotionColors(String fieldName) throws NoSuchFieldException,
IllegalAccessException {
Field f = Potion.class.getDeclaredField(fieldName);
boolean accessibility = f.isAccessible();
f.setAccessible(true);
for (Potion potion : Potion.potionTypes) {
Expand Down
28 changes: 16 additions & 12 deletions java/net/easymfne/potioncolorizer/PotionColorizerConfigPanel.java
Expand Up @@ -6,9 +6,9 @@
* Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* PotionColorizer is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* PotionColorizer is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
Expand Down Expand Up @@ -90,8 +90,9 @@ public ColorConfigLine(int idStart, String potionName, int xPos,
.setText(colorToHex(LiteModPotionColorizer.instance.customPotionColors
.get(potionName)));
} else {
textField.setText(colorToHex(LiteModPotionColorizer.defaultColors
.get(potionName)));
textField
.setText(colorToHex(LiteModPotionColorizer.defaultColors
.get(potionName)));
}
label = I18n.format(potionName, new Object[0]);
}
Expand Down Expand Up @@ -228,23 +229,24 @@ public void mouseMoved(ConfigPanelHost host, int mouseX, int mouseY) {
@Override
public void mousePressed(ConfigPanelHost host, int mouseX, int mouseY,
int mouseButton) {
if (deglintBox.mousePressed(Minecraft.getMinecraft(), mouseX,
mouseY)) {
if (deglintBox.mousePressed(Minecraft.getMinecraft(), mouseX, mouseY)) {
activeButton = deglintBox;
LiteModPotionColorizer.instance.deglintPotions =
!LiteModPotionColorizer.instance.deglintPotions;
deglintBox.checked = LiteModPotionColorizer.instance.deglintPotions;
} else if (recolorBox.mousePressed(Minecraft.getMinecraft(), mouseX, mouseY)) {
} else if (recolorBox.mousePressed(Minecraft.getMinecraft(), mouseX,
mouseY)) {
activeButton = recolorBox;
LiteModPotionColorizer.instance.recolorPotions =
!LiteModPotionColorizer.instance.recolorPotions;
recolorBox.checked = LiteModPotionColorizer.instance.recolorPotions;
} else if (customColorBox.mousePressed(Minecraft.getMinecraft(), mouseX,
mouseY)) {
} else if (customColorBox.mousePressed(Minecraft.getMinecraft(),
mouseX, mouseY)) {
activeButton = customColorBox;
LiteModPotionColorizer.instance.customColors =
!LiteModPotionColorizer.instance.customColors;
customColorBox.checked = LiteModPotionColorizer.instance.customColors;
customColorBox.checked =
LiteModPotionColorizer.instance.customColors;
for (ColorConfigLine line : colorLines) {
line.refresh();
}
Expand Down Expand Up @@ -293,7 +295,9 @@ public void onPanelShown(ConfigPanelHost host) {
new GuiCheckbox(id++, 10, SPACING * line++, I18n.format(
"config.recolor.text", new Object[0]));
recolorBox.checked = LiteModPotionColorizer.instance.recolorPotions;
customColorBox = new GuiCheckbox(id++, 10, SPACING * line++, I18n.format("config.custom.text", new Object[0]));
customColorBox =
new GuiCheckbox(id++, 10, SPACING * line++, I18n.format(
"config.custom.text", new Object[0]));
customColorBox.checked = LiteModPotionColorizer.instance.customColors;
colorLines = new ArrayList<ColorConfigLine>();
for (Potion potion : Potion.potionTypes) {
Expand Down
Expand Up @@ -6,9 +6,9 @@
* Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* PotionColorizer is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* PotionColorizer is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
Expand Down Expand Up @@ -58,7 +58,8 @@ protected void addEvents() {
private void addRecolorEvent() {
addEvent(
Event.getOrCreate(
"PotionColorizer_ItemPotion_getColorFromItemStack", true),
"PotionColorizer_ItemPotion_getColorFromItemStack",
true),
new MethodInfo(PotionObf.itemPotion,
PotionObf.itemPotion_getColorFromItemStack,
Integer.TYPE, new Object[] { ItemStack.class,
Expand Down
10 changes: 5 additions & 5 deletions java/net/easymfne/potioncolorizer/PotionObf.java
Expand Up @@ -6,9 +6,9 @@
* Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* PotionColorizer is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* PotionColorizer is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
Expand Down Expand Up @@ -37,8 +37,8 @@ public class PotionObf extends Obf {
"func_77636_d", "e", "hasEffect");

/** liquidColor field in net.minecraft.potion.Potion class. */
public static PotionObf potion_liquidColor = new PotionObf("liquidColor",
"K");
public static PotionObf potion_liquidColor = new PotionObf("field_76414_N",
"K", "liquidColor");

/**
* Create a new obfuscation mapping.
Expand Down
1 change: 0 additions & 1 deletion res/src

This file was deleted.

0 comments on commit 439fd19

Please sign in to comment.