Skip to content

Commit

Permalink
Updated MineTweaker integration, this should not make necessary mine …
Browse files Browse the repository at this point in the history
…tweaker usage on the client.
  • Loading branch information
brunoxkk0 committed Jun 13, 2024
1 parent e495166 commit 727c3c4
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 18 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ modName = NecroTempus

# This is a case-sensitive string to identify your mod. Convention is to use lower case.
modId = necrotempus
modVersion = 1.3.1
modVersion = 1.3.2
modGroup = io.github.cruciblemc.necrotempus

# WHY is there no version field?
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package io.github.cruciblemc.necrotempus.modules.features.compat;

import io.github.cruciblemc.necrotempus.NecroTempus;
import io.github.cruciblemc.necrotempus.modules.features.bossbar.compat.crafttweaker.BossBar;
import io.github.cruciblemc.necrotempus.modules.features.glyphs.compat.crafttweaker.Glyphs;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;

public class MineTweaker {

public static void init() {
try {

Class<?> MT_API = Class.forName("minetweaker.MineTweakerAPI");
Method method = MT_API.getDeclaredMethod("registerClass", Class.class);

for (Class<?> clazz : Arrays.asList(BossBar.class, Glyphs.class))
method.invoke(null, clazz);

} catch (NoClassDefFoundError | ClassNotFoundException | NoSuchMethodException | InvocationTargetException |
IllegalAccessException e) {
NecroTempus.getInstance().getLogger().warn("CraftTweaker is not available.");
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;

import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -304,10 +305,18 @@ private TabCell enforceDisplayName(TabCell cell) {

private int drawPlayerHead(int minX, int minY, TabCell cell) {
ResourceLocation texture = getPlayerSkin(cell.getSkullProfile());

// float height = 32F;
//
// try{
// IResource resource = Minecraft.getMinecraft().getResourceManager().getResource(texture);
// height = ImageIO.read(resource.getInputStream()).getHeight();
// } catch (IOException ignored) {}

minecraft.getTextureManager().bindTexture(texture);
GL11.glPushMatrix();

func_152125_a(minX, minY, 8F, 8F, 8, 8, 8, 8, 64.0F, texture.getResourceDomain().startsWith("skinport") ? 64F : 32F);
func_152125_a(minX, minY, 8F, 8F, 8, 8, 8, 8, 64.0F, 32F);

GL11.glPopMatrix();

Expand Down Expand Up @@ -380,6 +389,7 @@ private void drawScoreboardValues(ScoreObjective scoreObjective, int minY, int s

private static final HashSet<String> DOWNLOADING_SKINS = new HashSet<>();
private static SkinProvider skinProvider;
private static Constructor<MinecraftProfileTexture> constructor = null;

@SneakyThrows
@SuppressWarnings("rawtypes")
Expand All @@ -390,7 +400,7 @@ public ResourceLocation getPlayerSkin(GameProfile gameProfile) {
if (gameProfile != null) {

if (NecroTempusConfig.enableSkinPortCompat && Loader.isModLoaded("skinport") && skinProvider == null) {
skinProvider = (profile -> Hooks.TileEntitySkullRenderer_bindTexture(profile, locationStevePng));
skinProvider = (profile -> Hooks.GuiPlayerTabOverlay_bindTexture(profile, locationStevePng));
}

if (skinProvider != null)
Expand All @@ -407,11 +417,34 @@ public ResourceLocation getPlayerSkin(GameProfile gameProfile) {
if (DOWNLOADING_SKINS.contains(url))
return locationStevePng;

MinecraftProfileTexture skin = new MinecraftProfileTexture(url, null);
DOWNLOADING_SKINS.add(url);

String finalUrl = url;
return minecraft.func_152342_ad().func_152789_a(skin, MinecraftProfileTexture.Type.SKIN, (skinPart, skinLoc) -> DOWNLOADING_SKINS.remove(finalUrl));
if(constructor == null){
try{
constructor = MinecraftProfileTexture.class.getConstructor(String.class);
}catch (Exception ignored){
try{
constructor = MinecraftProfileTexture.class.getConstructor(String.class, Map.class);
}catch (Exception ignored2){}
}
}

MinecraftProfileTexture skin = null;


if(constructor != null){
if(constructor.getParameterCount() == 1){
skin = constructor.newInstance(url);
}else{
skin = constructor.newInstance(url, (Map) null);
}
}

if(skin != null){
DOWNLOADING_SKINS.add(url);

String finalUrl = url;
return minecraft.func_152342_ad().func_152789_a(skin, MinecraftProfileTexture.Type.SKIN, (skinPart, skinLoc) -> DOWNLOADING_SKINS.remove(finalUrl));
}
}

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,15 @@
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.event.FMLServerStartingEvent;
import io.github.cruciblemc.necrotempus.NecroTempus;
import io.github.cruciblemc.necrotempus.modules.features.bossbar.compat.crafttweaker.BossBar;
import io.github.cruciblemc.necrotempus.modules.features.glyphs.compat.crafttweaker.Glyphs;
import minetweaker.MineTweakerAPI;

import java.util.Arrays;
import io.github.cruciblemc.necrotempus.modules.features.compat.MineTweaker;

public abstract class CommonProxy {

public void preInit(FMLPreInitializationEvent event) {
}

public void init(FMLInitializationEvent event) {
try {
Arrays.asList(BossBar.class, Glyphs.class).forEach(MineTweakerAPI::registerClass);
} catch (NoClassDefFoundError e) {
NecroTempus.getInstance().getLogger().warn("CraftTweaker is not available.");
}
MineTweaker.init();
}

public void postInit(FMLPostInitializationEvent event) {
Expand Down

0 comments on commit 727c3c4

Please sign in to comment.