generated from FabricMC/fabric-example-mod
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
174 lines (141 loc) · 4.13 KB
/
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
//file:noinspection GroovyAssignabilityCheck
plugins {
id 'fabric-loom' version '0.9-SNAPSHOT'
id 'maven-publish'
}
sourceCompatibility = JavaVersion.VERSION_16
targetCompatibility = JavaVersion.VERSION_16
archivesBaseName = project.archives_base_name
version = project.mod_version
group = project.maven_group
repositories {
maven {
name 'TerraformersMC'
url 'https://maven.terraformersmc.com/releases'
content {
includeGroup 'com.terraformersmc'
}
}
}
loom {
accessWidenerPath.set file("src/main/resources/generated.accesswidener")
}
dependencies {
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
modRuntime "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
modRuntime "com.terraformersmc:modmenu:${project.modmenu_version}"
}
processResources {
inputs.property "version", project.version
filesMatching("fabric.mod.json") {
expand "version": project.version
}
}
tasks.withType(JavaCompile).configureEach {
it.options.encoding "UTF-8"
it.options.release.set 16
}
java {
withSourcesJar()
}
jar {
from("LICENSE") {
rename { "${it}_${project.archivesBaseName}"}
}
}
public class WidenerSpec {
String keyword = "mutable";
String className;
String descriptor;
public WidenerSpec(String keyword, String name, String descriptor) {
this.keyword = keyword;
this.className = name;
this.descriptor = descriptor;
}
@Override
public int hashCode() {
int result = keyword.hashCode();
result *= 31;
result += className.hashCode();
result *= 31;
result += descriptor.hashCode();
return result;
}
}
public WidenerSpec mutable(String className, String descriptor) {
return new WidenerSpec("mutable", className, descriptor);
}
public List<String> expandWideners(List<WidenerSpec> wideners) {
Set<String> classNames = new HashSet<>();
for(WidenerSpec widener : wideners) classNames.add(widener.className);
def mappingsJar = configurations.mappingsFinal.find { true }
def mappingsFile = new File(mappingsJar.parentFile, "mappings/"+mappingsJar.getName().replace("-final.jar", ".tiny"))
String curClass = "java/lang/Void";
List<String> result = new ArrayList<>();
mappingsFile.eachLine {
if (it.startsWith('c\t')) {
def parts = it.split('\t');
curClass = parts[3];
} else if (it.trim().startsWith('f\t')) {
if (classNames.contains(curClass)) {
def parts = it.trim().split('\t');
def fieldName = parts[4];
for(WidenerSpec widener : wideners) {
if (widener.className.equals(curClass)) {
result.add(widener.keyword+"\tfield\t"+widener.className+"\t"+fieldName+"\t"+widener.descriptor);
}
}
/*
//if (curClass.equals(className)) {
def parts = it.trim().split('\t');
def fieldName = parts[4];
//println blockName;
curFields.add(fieldName);
}*/
}
}
}
return result;
}
/**
* Given a map of binary class names to field lists, such as the one returned by getAllFields, generate an accesswidener
* file called generated.accesswidener which forces each field specified to be mutable (non-final).
*/
public void writeAccessWidener(List<String> wideners) {
def widenerFile = new File(project.projectDir, "src/main/resources/generated.accesswidener");
def writer = new FileWriter(widenerFile);
writer.println("accessWidener\tv1\tnamed");
for(String s : wideners) {
writer.println(s);
}
writer.flush();
writer.close();
}
tasks.register("accesswidener") {
doLast {
//def allBlocks = getAllFinalFields("net/minecraft/block/Blocks");
def allBlocks = expandWideners([
mutable("net/minecraft/block/Blocks", "Lnet/minecraft/block/Block;"),
mutable("net/minecraft/world/gen/surfacebuilder/SurfaceBuilder", "Lnet/minecraft/block/Block;")
]);
writeAccessWidener(allBlocks);
}
}
// configure the maven publication
publishing {
publications {
mavenJava(MavenPublication) {
// add all the jars that should be included when publishing to maven
artifact(remapJar) {
builtBy remapJar
}
artifact(sourcesJar) {
builtBy remapSourcesJar
}
}
}
repositories {
}
}