Skip to content

Commit b93da96

Browse files
committed
attempt color block
1 parent c6a8129 commit b93da96

File tree

5 files changed

+178
-39
lines changed

5 files changed

+178
-39
lines changed

build.gradle

Lines changed: 105 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ repositories {
3535
}
3636

3737
apply plugin: 'forge'
38+
apply plugin: 'idea'
3839

3940
// These settings allow you to choose what version of Java you want to be compatible with. Forge 1.7.10 runs on Java 6 to 8.
4041
sourceCompatibility = 1.8
@@ -47,25 +48,10 @@ minecraft {
4748
version = project.minecraft_version + "-" + project.forge_version
4849
runDir = "run"
4950
}
50-
51-
dependencies {
52-
// you may put jars on which you depend on in ./libs
53-
// or you may define them like so..
54-
//compile "some.group:artifact:version:classifier"
55-
//compile "some.group:artifact:version"
56-
57-
// real examples
58-
//compile 'com.mod-buildcraft:buildcraft:6.0.8:dev' // adds buildcraft to the dev env
59-
//compile 'com.googlecode.efficient-java-matrix-library:ejml:0.24' // adds ejml to the dev env
60-
61-
// for more info...
62-
// http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html
63-
// http://www.gradle.org/docs/current/userguide/dependency_management.html
64-
65-
implementation "codechicken:CodeChickenLib:1.7.10-1.1.3.140:dev"
66-
implementation "codechicken:CodeChickenCore:1.7.10-1.0.7.47:dev"
51+
configurations {
52+
embed
53+
compile.extendsFrom(embed)
6754
}
68-
6955
processResources {
7056
// This will ensure that this task is redone when the versions change.
7157
inputs.property "version", project.version
@@ -95,31 +81,111 @@ task devJar(type: Jar) {
9581
from sourceSets.main.output
9682
}
9783

98-
// Creates the listed artifacts on building the mod.
99-
artifacts {
100-
archives sourcesJar
101-
archives devJar
84+
85+
//##########################################################################################################
86+
//######################################## Mixin Part ################################################
87+
//##########################################################################################################
88+
//Add
89+
//--tweakClass org.spongepowered.asm.launch.MixinTweaker --mixin mixins.examplemod.json
90+
//to your client and server program arguments if working in a dev environment.
91+
def yourMixinConfig = "mixins.${modId}.json"
92+
def refMapForYourConfig = "mixins.${modId}.refmap.json"
93+
def relativePathToMixinAP = 'libs/mixin-0.8-SNAPSHOT.jar'
94+
95+
def embedMixin = false
96+
97+
if (!embedMixin) {
98+
version += "-mixinless"
99+
}
100+
101+
repositories {
102+
maven {
103+
name = "sponge"
104+
url = "https://repo.spongepowered.org/maven/"
105+
}
102106
}
103107

104-
// This block configures any maven publications you want to make.
105-
publishing {
106-
publications {
107-
mavenJava(MavenPublication) {
108-
// Add any other artifacts here that you would like to publish!
109-
artifact(jar) {
110-
builtBy build
111-
}
112-
artifact(sourcesJar) {
113-
builtBy sourcesJar
114-
}
115-
artifact(devJar) {
116-
builtBy devJar
117-
}
108+
dependencies {
109+
110+
implementation "codechicken:CodeChickenLib:1.7.10-1.1.3.140:dev"
111+
implementation "codechicken:CodeChickenCore:1.7.10-1.0.7.47:dev"
112+
113+
if (embedMixin) {
114+
embed('org.spongepowered:mixin:0.7.11-SNAPSHOT') {
115+
// Mixin includes a lot of dependencies that are too up-to-date
116+
exclude module: 'launchwrapper'
117+
exclude module: 'guava'
118+
exclude module: 'gson'
119+
exclude module: 'commons-io'
120+
exclude module: 'log4j-core'
121+
}
122+
} else {
123+
compile('org.spongepowered:mixin:0.7.11-SNAPSHOT') {
124+
// Mixin includes a lot of dependencies that are too up-to-date
125+
exclude module: 'launchwrapper'
126+
exclude module: 'guava'
127+
exclude module: 'gson'
128+
exclude module: 'commons-io'
129+
exclude module: 'log4j-core'
118130
}
119131
}
132+
}
133+
134+
def refMap = "${tasks.compileJava.temporaryDir}" + File.separator + refMapForYourConfig
135+
136+
def mixinSrg = "${tasks.reobf.temporaryDir}" + File.separator + "mixins.srg"
137+
138+
jar {
139+
from refMap
140+
manifest {
141+
attributes.put("TweakClass", "org.spongepowered.asm.launch.MixinTweaker")
142+
attributes.put("FMLCorePluginContainsFMLMod", true)
143+
attributes.put("ForceLoadAsMod", true)
144+
attributes.put("MixinConfigs", yourMixinConfig)
145+
}
146+
147+
// embed libraries in jar
148+
from configurations.embed.collect {
149+
exclude '**/LICENSE.txt'
150+
it.isDirectory() ? it : zipTree(it)
151+
}
152+
}
153+
154+
reobf {
155+
addExtraSrgFile mixinSrg
156+
}
157+
158+
afterEvaluate {
159+
def fixedRelPathToAP = relativePathToMixinAP
160+
if (fixedRelPathToAP.startsWith('./') || fixedRelPathToAP.startsWith('.\\')) {
161+
fixedRelPathToAP = fixedRelPathToAP.substring(2)
162+
} else if (fixedRelPathToAP.startsWith('/') || fixedRelPathToAP.startsWith('\\')) {
163+
fixedRelPathToAP = fixedRelPathToAP.substring(1)
164+
}
165+
166+
tasks.compileJava {
167+
println "Path: " + projectDir.absolutePath
168+
options.compilerArgs += [
169+
// There's a bug in the AnnotationProcessor for 0.7.11 that will generate the annotations pointing to the parent class instead of subclass
170+
// resulting in the mixin not being applied. This is fixed in 0.8, however 0.8 needs guava > 21.0, and minecraft ships with 17.0.
171+
// So as a hacky workaround... ship with 0.7.11, but use the AP from 0.8 for compiling
172+
173+
"-processor", "org.spongepowered.tools.obfuscation.MixinObfuscationProcessorInjection,org.spongepowered.tools.obfuscation.MixinObfuscationProcessorTargets",
174+
"-Xlint:-sunapi", "-XDenableSunApiLintControl", "-XDignore.symbol.file",
175+
"-AreobfSrgFile=${tasks.reobf.srg}", "-AoutSrgFile=${mixinSrg}", "-AoutRefMapFile=${refMap}"
176+
]
177+
options.annotationProcessorPath = files(projectDir.absolutePath + '/' + fixedRelPathToAP)
178+
}
179+
tasks.runClient{
120180

121-
// This block selects the repositories you want to publish to.
122-
repositories {
123-
// Add the repositories you want to publish to here.
124181
}
125182
}
183+
184+
sourceSets {
185+
main {
186+
java {
187+
outputDir = file("$buildDir/classes/java/main")
188+
}
189+
ext.refMap = refMapForYourConfig
190+
}
191+
}

libs/mixin-0.8-SNAPSHOT.jar

3.67 MB
Binary file not shown.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* This class was created by <kuzuanpa>. It is a part of Thinker.
3+
* Get the Source Code in github:
4+
* https://github.com/kuzuanpa/Thinker
5+
*
6+
* Thinker is distributed in the hope that it will be useful,
7+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
8+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9+
* GNU Lesser General Public License for more details.
10+
*
11+
* Thinker is Open Source and distributed under the
12+
* LGPLv3 License: https://www.gnu.org/licenses/lgpl-3.0.txt
13+
*
14+
*/
15+
16+
package cn.kuzuanpa.thinker.mixin;
17+
18+
import cn.kuzuanpa.thinker.mixinHandler.mixinRenderBlockHandler;
19+
import net.minecraft.block.Block;
20+
import net.minecraft.client.renderer.RenderBlocks;
21+
import net.minecraft.world.IBlockAccess;
22+
import org.spongepowered.asm.mixin.Mixin;
23+
import org.spongepowered.asm.mixin.Shadow;
24+
import org.spongepowered.asm.mixin.injection.At;
25+
import org.spongepowered.asm.mixin.injection.Redirect;
26+
27+
@Mixin(RenderBlocks.class)
28+
public class mixinRenderBlock {
29+
@Redirect(method = "renderStandardBlock",at = @At(value = "INVOKE", target = "Lnet/minecraft/block/Block;colorMultiplier(Lnet/minecraft/world/IBlockAccess;III)I"))
30+
public int modifyColor(Block block, IBlockAccess ba, int x, int y, int z){
31+
int originColor = block.colorMultiplier(ba, x, y, z);
32+
return mixinRenderBlockHandler.isColorOverwrite?mixinRenderBlockHandler.color:originColor;
33+
}
34+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* This class was created by <kuzuanpa>. It is a part of Thinker.
3+
* Get the Source Code in github:
4+
* https://github.com/kuzuanpa/Thinker
5+
*
6+
* Thinker is distributed in the hope that it will be useful,
7+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
8+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9+
* GNU Lesser General Public License for more details.
10+
*
11+
* Thinker is Open Source and distributed under the
12+
* LGPLv3 License: https://www.gnu.org/licenses/lgpl-3.0.txt
13+
*
14+
*/
15+
16+
package cn.kuzuanpa.thinker.mixinHandler;
17+
18+
public class mixinRenderBlockHandler {
19+
public static int color=0xbbffffff;
20+
public static boolean isColorOverwrite=true;
21+
public static void setColor(int color){
22+
mixinRenderBlockHandler.color=color;
23+
}
24+
public static void setColor(int color,boolean overwrite){
25+
mixinRenderBlockHandler.color=color;
26+
isColorOverwrite=overwrite;
27+
}
28+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"required": true,
3+
"minVersion": "0.7.11",
4+
"package": "cn.kuzuanpa.thinker.mixin",
5+
"refmap": "mixins.thinker.refmap.json",
6+
"target": "@env(DEFAULT)",
7+
"compatibilityLevel": "JAVA_8",
8+
"client": [
9+
"mixinRenderBlock"
10+
]
11+
}

0 commit comments

Comments
 (0)