Skip to content
This repository was archived by the owner on Jan 24, 2025. It is now read-only.

Commit 2a4aa8a

Browse files
committed
support all 1.15 versions
* update to forgegradle 5.x * update to gradle 7 * use accesstransformer instead of reflections * use official mappings * cleanup code
1 parent 971a0e5 commit 2a4aa8a

File tree

8 files changed

+86
-103
lines changed

8 files changed

+86
-103
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,5 @@ run
2323

2424
# Files from Forge MDK
2525
forge*changelog.txt
26+
27+
/logs/

build.gradle

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@ buildscript {
55
mavenCentral()
66
}
77
dependencies {
8-
classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '3.+', changing: true
8+
classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '5.+', changing: true
99
}
1010
}
1111
apply plugin: 'net.minecraftforge.gradle'
1212
// Only edit below this line, the above code adds and enables the necessary things for Forge to be setup.
1313
apply plugin: 'eclipse'
1414
apply plugin: 'maven-publish'
1515

16-
version = '1.0-1.15.2'
16+
version = '1.0-1.15.x'
1717
group = 'com.github.nearata.optifinecapes' // http://maven.apache.org/guides/mini/guide-naming-conventions.html
1818
archivesBaseName = 'OptifineCapes'
1919

20-
sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8' // Need this here so eclipse task generates correctly.
20+
java.toolchain.languageVersion = JavaLanguageVersion.of(8)
2121
//Print out JVM information so that we know what version is running. Extreamly useful for people to know when helping you.
2222
println('Java: ' + System.getProperty('java.version') + ' JVM: ' + System.getProperty('java.vm.version') + '(' + System.getProperty('java.vendor') + ') Arch: ' + System.getProperty('os.arch'))
2323

@@ -27,10 +27,10 @@ minecraft {
2727
// stable_# Stables are built at the discretion of the MCP team.
2828
// Use non-default mappings at your own risk. they may not always work.
2929
// Simply re-run your setup task after changing the mappings to update your workspace.
30-
mappings channel: 'snapshot', version: '20201112-1.15.1'
30+
mappings channel: 'official', version: '1.15.2'
3131
// makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable.
3232

33-
// accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg')
33+
accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg')
3434

3535
// Default run configurations.
3636
// These can be tweaked, removed, or duplicated as needed.
@@ -91,7 +91,7 @@ dependencies {
9191
// Specify the version of Minecraft to use, If this is any group other then 'net.minecraft' it is assumed
9292
// that the dep is a ForgeGradle 'patcher' dependency. And it's patches will be applied.
9393
// The userdev artifact is a special name and will get all sorts of transformations applied to it.
94-
minecraft 'net.minecraftforge:forge:1.15.2-31.2.46'
94+
minecraft 'net.minecraftforge:forge:1.15.2-31.2.55'
9595

9696
// You may put jars on which you depend on in ./libs or you may define them like so..
9797
// compile "some.group:artifact:version:classifier"
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1.1-bin.zip
34
zipStoreBase=GRADLE_USER_HOME
4-
zipStorePath=wrapper/dists
5-
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.3-bin.zip
5+
zipStorePath=wrapper/dists

settings.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rootProject.name = 'OptifineCapes-1.15.x'

src/main/java/com/github/nearata/optifinecapes/CapeManager.java

Lines changed: 0 additions & 68 deletions
This file was deleted.
Lines changed: 65 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,100 @@
11
package com.github.nearata.optifinecapes;
22

3+
import java.io.IOException;
4+
import java.net.URL;
35
import java.util.ArrayList;
46
import java.util.List;
7+
import java.util.Map;
58

6-
import org.apache.logging.log4j.LogManager;
7-
import org.apache.logging.log4j.Logger;
9+
import com.mojang.authlib.minecraft.MinecraftProfileTexture.Type;
810

911
import net.minecraft.client.Minecraft;
1012
import net.minecraft.client.entity.player.AbstractClientPlayerEntity;
13+
import net.minecraft.client.renderer.texture.DynamicTexture;
14+
import net.minecraft.client.renderer.texture.NativeImage;
15+
import net.minecraft.util.ResourceLocation;
16+
import net.minecraft.util.Util;
1117
import net.minecraftforge.client.event.RenderPlayerEvent;
1218
import net.minecraftforge.common.MinecraftForge;
13-
import net.minecraftforge.event.TickEvent;
19+
import net.minecraftforge.event.TickEvent.ClientTickEvent;
1420
import net.minecraftforge.eventbus.api.SubscribeEvent;
1521
import net.minecraftforge.fml.common.Mod;
1622

1723
@Mod("optifinecapes")
18-
public class OptifineCapes
24+
public final class OptifineCapes
1925
{
20-
public static final Logger logger = LogManager.getLogger();
2126
private final Minecraft mc = Minecraft.getInstance();
22-
private static List<String> players = new ArrayList<String>();
27+
private List<String> players = new ArrayList<>();
2328

2429
public OptifineCapes()
2530
{
2631
MinecraftForge.EVENT_BUS.register(this);
2732
}
2833

2934
@SubscribeEvent
30-
public final void renderPlayer(RenderPlayerEvent.Pre event)
35+
public void renderPlayer(RenderPlayerEvent.Pre event)
3136
{
3237
final AbstractClientPlayerEntity acp = (AbstractClientPlayerEntity) event.getPlayer();
33-
final String username = acp.getDisplayName().getString();
38+
final String username = acp.getName().getString();
3439

35-
if (acp.hasPlayerInfo() && acp.getLocationCape() == null && !players.contains(username))
40+
if (acp.isCapeLoaded() && acp.getCloakTextureLocation() == null && !players.contains(username))
3641
{
37-
players.add(username);
38-
CapeManager.loadCape(acp);
42+
this.players.add(username);
43+
Map<Type, ResourceLocation> textureLocations = acp.getPlayerInfo().textureLocations;
44+
45+
Util.backgroundExecutor().execute(() -> {
46+
try
47+
{
48+
final URL url = new URL(String.format("http://s.optifine.net/capes/%s.png", username));
49+
final NativeImage nativeImage = NativeImage.read(url.openStream());
50+
final DynamicTexture dynamictexture = new DynamicTexture(this.parseCape(nativeImage));
51+
final ResourceLocation resourcelocation = mc.getTextureManager().register("optifinecapes/", dynamictexture);
52+
53+
textureLocations.put(Type.CAPE, resourcelocation);
54+
textureLocations.put(Type.ELYTRA, resourcelocation);
55+
}
56+
catch (IOException e)
57+
{
58+
// no cape
59+
}
60+
});
3961
}
4062
}
41-
63+
4264
@SubscribeEvent
43-
public final void clientTick(TickEvent.ClientTickEvent event)
65+
public void clientTick(ClientTickEvent event)
4466
{
45-
if (mc.world == null && !players.isEmpty())
67+
if (mc.player == null && !this.players.isEmpty())
4668
{
47-
players.clear();
69+
this.players.clear();
4870
}
4971
}
72+
73+
private NativeImage parseCape(NativeImage nativeImageIn)
74+
{
75+
int imageWidth = 64;
76+
int imageHeight = 32;
77+
int imageSrcWidth = nativeImageIn.getWidth();
78+
int imageSrcHeight = nativeImageIn.getHeight();
79+
80+
while (imageWidth < imageSrcWidth || imageHeight < imageSrcHeight)
81+
{
82+
imageWidth *= 2;
83+
imageHeight *= 2;
84+
}
85+
86+
NativeImage nativeImage = new NativeImage(imageWidth, imageHeight, true);
87+
88+
for (int x = 0; x < imageSrcWidth; x++)
89+
{
90+
for (int y = 0; y < imageSrcHeight; y++)
91+
{
92+
nativeImage.setPixelRGBA(x, y, nativeImageIn.getPixelRGBA(x, y));
93+
}
94+
}
95+
96+
nativeImageIn.close();
97+
98+
return nativeImage;
99+
}
50100
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
public net.minecraft.client.entity.player.AbstractClientPlayerEntity func_175155_b()Lnet/minecraft/client/network/play/NetworkPlayerInfo; # getPlayerInfo
2+
public net.minecraft.client.network.play.NetworkPlayerInfo field_187107_a # textureLocations
Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
11
modLoader="javafml"
2-
loaderVersion="[31,)"
2+
loaderVersion="[29,)"
3+
license="MIT"
34
issueTrackerURL="https://github.com/Nearata/OptifineCapes/issues"
4-
logoFile="logo.png"
5-
65
[[mods]]
76
modId="optifinecapes"
87
version="${file.jarVersion}"
98
displayName="Optifine Capes"
10-
displayURL="https://github.com/Nearata/OptifineCapes"
119
authors="Nearata"
12-
description='''
13-
For those who are only interested in the optifine capes.
14-
'''
15-
16-
[[dependencies.optifinecapes]] #optional
17-
modId="forge"
10+
description="For those who are only interested in the optifine capes."
11+
logoFile="logo.png"
12+
[[dependencies.optifinecapes]]
13+
modId="minecraft"
1814
mandatory=true
19-
versionRange="[31,)"
15+
versionRange="[1.15,1.16)"
2016
ordering="NONE"
21-
side="CLIENT"
17+
side="CLIENT"

0 commit comments

Comments
 (0)