Skip to content

Commit

Permalink
[Port] Update to 1.2.5 (v2.4.0)
Browse files Browse the repository at this point in the history
  • Loading branch information
CDAGaming committed Jun 9, 2024
1 parent a16befc commit cafcc6c
Show file tree
Hide file tree
Showing 21 changed files with 281 additions and 140 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,11 @@
import com.gitlab.cdagaming.craftpresence.utils.world.BiomeUtils;
import com.gitlab.cdagaming.craftpresence.utils.world.DimensionUtils;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import io.github.cdagaming.unicore.utils.MappingUtils;
import io.github.cdagaming.unicore.utils.OSUtils;
import io.github.cdagaming.unicore.utils.ScheduleUtils;
import io.github.cdagaming.unicore.utils.TimeUtils;
import io.github.cdagaming.unicore.utils.*;
import net.minecraft.client.Minecraft;
import net.minecraft.src.EntityPlayer;
import net.minecraft.src.Session;
import net.minecraft.src.UnexpectedThrowable;

/**
* The Primary Application Class and Utilities
Expand Down Expand Up @@ -197,7 +195,7 @@ private void scheduleTick() {
*/
private void clientTick() {
if (!Constants.IS_GAME_CLOSING) {
instance = Minecraft.getMinecraft();
instance = getMinecraftInstance();
if (initialized) {
session = instance.session;
player = instance.thePlayer;
Expand All @@ -213,4 +211,39 @@ private void clientTick() {
}
}
}

private static void ThrowException(Throwable e) {
ThrowException("Exception occurred in ModLoader", e);
}

public static void ThrowException(String message, Throwable e) {
Minecraft game = getMinecraftInstance();
if (game != null) {
game.displayUnexpectedThrowable(new UnexpectedThrowable(message, e));
} else {
throw new RuntimeException(e);
}
}

public static Minecraft getMinecraftInstance() {
if (instance == null) {
try {
ThreadGroup group = Thread.currentThread().getThreadGroup();
int count = group.activeCount();
Thread[] threads = new Thread[count];
group.enumerate(threads);

for (Thread thread : threads) {
if (thread.getName().equals("Minecraft main thread")) {
instance = (Minecraft) StringUtils.getField(Thread.class, thread, "target");
break;
}
}
} catch (Exception var4) {
ThrowException(var4);
}
}

return instance;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import com.gitlab.cdagaming.craftpresence.core.utils.ModUpdaterUtils;
import io.github.cdagaming.unicore.utils.StringUtils;
import io.github.cdagaming.unicore.utils.TranslationUtils;
import net.minecraft.client.ClientBrandRetriever;

/**
* Constant Variables and Methods used throughout the Application
Expand Down Expand Up @@ -92,7 +91,7 @@ private static String findGameBrand() {
} catch (Throwable ignored) {
}
return StringUtils.getOrDefault(
result, ClientBrandRetriever.getClientModName()
result, "vanilla"
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ public TranslationManager(final TranslationUtils instance) {
StringTranslate stInstance = StringTranslate.getInstance();
Properties data = (Properties) StringUtils.getField(
StringTranslate.class, stInstance,
"translateTable", "field_74815_b", "field_618", "b"
"translateTable", "field_20164_b", "b"
);
data.putAll(entries);
StringUtils.updateField(
StringTranslate.class, stInstance,
data,
"translateTable", "field_74815_b", "field_618", "b"
"translateTable", "field_20164_b", "b"
);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public static Object parseTag(final NBTBase tag) {
return tag.toString();
}
case 11:
return ((NBTTagIntArray) tag).intArray;
return ((NBTTagIntArray) tag).field_48181_a;
case 0:
case 12:
case 99:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,7 @@
import com.gitlab.cdagaming.craftpresence.core.config.element.ModuleData;
import com.gitlab.cdagaming.craftpresence.core.impl.ExtendedModule;
import io.github.cdagaming.unicore.utils.StringUtils;
import net.minecraft.src.GuiPlayerInfo;
import net.minecraft.src.Entity;
import net.minecraft.src.EntityList;
import net.minecraft.src.World;
import net.minecraft.src.WorldInfo;
import net.minecraft.src.*;

import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -115,7 +111,7 @@ public static String getName(final Entity entity, final boolean stripFormatting)
String result = "";
if (entity != null) {
result = StringUtils.getOrDefault(
entity.getEntityName()
EntityList.getEntityString(entity)
);
}

Expand Down Expand Up @@ -321,7 +317,7 @@ public void updatePresence() {

@Override
public void getInternalData() {
final Map mappings = (Map) StringUtils.getField(EntityList.class, null, "classToStringMapping", "field_75626_c", "field_3269", "c");
final Map mappings = (Map) StringUtils.getField(EntityList.class, null, "classToStringMapping", "field_1610_b", "c");
if (!mappings.values().isEmpty()) {
for (Object entityLocationObj : mappings.values()) {
final String entityLocation = (String) entityLocationObj;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1151,7 +1151,7 @@ public static int getStringWidth(final FontRenderer fontRenderer, final String s
* @return the character's width from the font renderer
*/
private static int getCharWidth(final FontRenderer fontRenderer, final char string) {
return fontRenderer.getCharWidth(string);
return fontRenderer.func_50105_a(string);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,22 +262,22 @@ public boolean mousePressed(@Nonnull Minecraft arg, int mouseX, int mouseY) {

@Override
public int getControlWidth() {
return width;
return field_52008_a;
}

@Override
public void setControlWidth(final int width) {
this.width = width;
this.field_52008_a = width;
}

@Override
public int getControlHeight() {
return height;
return field_52007_b;
}

@Override
public void setControlHeight(final int height) {
this.height = height;
this.field_52007_b = height;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public ExtendedTextControl(final FontRenderer fontRendererObj, final int x, fina
public int getControlWidth() {
return StringUtils.getValidInteger(StringUtils.getField(
GuiTextField.class, this,
"width", "field_73811_d", "field_1119", "d"
"width", "field_22077_f", "d"
)).getSecond();
}

Expand All @@ -101,15 +101,15 @@ public void setControlWidth(final int width) {
StringUtils.updateField(
GuiTextField.class, this,
width,
"width", "field_73811_d", "field_1119", "d"
"width", "field_22077_f", "d"
);
}

@Override
public int getControlHeight() {
return StringUtils.getValidInteger(StringUtils.getField(
GuiTextField.class, this,
"height", "field_73812_e", "field_1120", "e"
"height", "field_22076_g", "e"
)).getSecond();
}

Expand All @@ -118,7 +118,7 @@ public void setControlHeight(final int height) {
StringUtils.updateField(
GuiTextField.class, this,
height,
"height", "field_73812_e", "field_1120", "e"
"height", "field_22076_g", "e"
);
}

Expand All @@ -141,7 +141,7 @@ public void postDraw(ExtendedScreen screen) {
public int getControlPosX() {
return StringUtils.getValidInteger(StringUtils.getField(
GuiTextField.class, this,
"xPos", "field_73813_b", "field_1117", "b"
"xPos", "field_22079_d", "b"
)).getSecond();
}

Expand All @@ -150,15 +150,15 @@ public void setControlPosX(final int posX) {
StringUtils.updateField(
GuiTextField.class, this,
posX,
"xPos", "field_73813_b", "field_1117", "b"
"xPos", "field_22079_d", "b"
);
}

@Override
public int getControlPosY() {
return StringUtils.getValidInteger(StringUtils.getField(
GuiTextField.class, this,
"yPos", "field_73814_c", "field_1118", "c"
"yPos", "field_22078_e", "c"
)).getSecond();
}

Expand All @@ -167,7 +167,7 @@ public void setControlPosY(final int posY) {
StringUtils.updateField(
GuiTextField.class, this,
posY,
"yPos", "field_73814_c", "field_1118", "c"
"yPos", "field_22078_e", "c"
);
}

Expand Down Expand Up @@ -195,7 +195,7 @@ public void setControlMessage(final String newMessage) {
* @return The control's maximum text contents
*/
public int getControlMaxLength() {
return this.getMaxStringLength();
return this.func_50040_g();
}

/**
Expand All @@ -213,7 +213,7 @@ public void setControlMaxLength(final int newLength) {
* @return The control's focus status
*/
public boolean isControlFocused() {
return this.isFocused();
return this.func_50025_j();
}

/**
Expand All @@ -222,7 +222,7 @@ public boolean isControlFocused() {
* @param focused the new focus state for the control
*/
public void setControlFocused(final boolean focused) {
this.setFocused(focused);
this.func_50033_b(focused);
}

/**
Expand Down Expand Up @@ -251,8 +251,8 @@ public void onKeyTyped() {
* @return Whether the event completed successfully
*/
@Override
public boolean textboxKeyTyped(char typedChar, int keyCode) {
final boolean returnValue = super.textboxKeyTyped(typedChar, keyCode);
public boolean func_50037_a(char typedChar, int keyCode) {
final boolean returnValue = super.func_50037_a(typedChar, keyCode);
if (returnValue) {
onKeyTyped();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@

import javax.annotation.Nonnull;
import java.awt.*;
import java.lang.reflect.Field;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -177,10 +178,10 @@ public boolean isWithinBounds(final int mouseX, final int mouseY) {
top,
bottom,
StringUtils.getValidInteger(
StringUtils.getField(GuiSlot.class, this, "left", "field_77238_j", "field_1250", "j")
StringUtils.getField(GuiSlot.class, this, "left", "field_22258_g", "e")
).getSecond(),
StringUtils.getValidInteger(
StringUtils.getField(GuiSlot.class, this, "right", "field_77241_i", "field_1249", "i")
StringUtils.getField(GuiSlot.class, this, "right", "field_22259_f", "d")
).getSecond()
);
}
Expand Down Expand Up @@ -283,7 +284,13 @@ public void setList(List<String> itemList) {
if (!itemList.equals(this.itemList)) {
this.itemList = itemList;
// Reset the scrollbar to prevent OOB issues
method_1063(Integer.MIN_VALUE);
//method_1063(Integer.MIN_VALUE);
try {
Field field = GuiSlot.class.getDeclaredFields()[14];
field.setAccessible(true);
field.set(this, 0.0f);
} catch (Throwable ignored) {
}

setupAliasData();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public void preRender() {
copyButton.setControlEnabled(!blockInteractions);
StringUtils.updateField(GuiTextField.class, commandInput,
!blockInteractions,
"isEnabled", "field_73819_m", "field_1127", "m"
"isEnabled", "field_50043_m", "m"
);

if (!blockInteractions) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import net.minecraft.src.Gui;
import net.minecraft.src.GuiButton;
import net.minecraft.src.GuiScreen;
import net.minecraft.src.GuiTextField;
import org.lwjgl.Sys;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
Expand Down Expand Up @@ -226,7 +227,7 @@ public static void resetIndex() {
* @param input the text to interpret
*/
public static void copyToClipboard(final String input) {
setClipboardString(StringUtils.normalize(input));
func_50050_a(StringUtils.normalize(input));
}

/**
Expand Down Expand Up @@ -598,7 +599,10 @@ public void drawScreen(int mouseX, int mouseY, float partialTicks) {

for (Gui extendedControl : getControls()) {
if (extendedControl instanceof ExtendedTextControl textField) {
textField.drawTextBox();
final Object reflectedInfo = StringUtils.getField(GuiTextField.class, textField, "isEnabled", "field_50043_m", "m");
if (reflectedInfo != null && reflectedInfo.toString().equalsIgnoreCase("true")) {
textField.drawTextBox();
}
}
}

Expand Down Expand Up @@ -703,7 +707,7 @@ protected void keyTyped(char typedChar, int keyCode) {

for (Gui extendedControl : getControls()) {
if (extendedControl instanceof ExtendedTextControl textField) {
textField.textboxKeyTyped(typedChar, keyCode);
textField.func_50037_a(typedChar, keyCode);
}
if (extendedControl instanceof ExtendedScreen extendedScreen) {
extendedScreen.keyTyped(typedChar, keyCode);
Expand Down
Loading

0 comments on commit cafcc6c

Please sign in to comment.