From 15ce8e7ed068358a7a1cd1fec6202ae84f5d0930 Mon Sep 17 00:00:00 2001 From: Matthew Messinger Date: Fri, 15 Jan 2016 02:59:50 -0500 Subject: [PATCH] Port to Mixin --- .gitignore | 2 + build.gradle | 26 +++++++++---- .../MixinRenderPlayer.java} | 37 ++++++++++--------- .../transformers/RenderPlayerTransformer.java | 12 ------ src/main/resources/litemod.json | 2 +- src/main/resources/mixin.minelp.json | 7 ++++ 6 files changed, 49 insertions(+), 37 deletions(-) rename src/main/java/com/brohoof/minelittlepony/{renderer/RenderPony.java => mixin/MixinRenderPlayer.java} (82%) delete mode 100644 src/main/java/com/brohoof/minelittlepony/transformers/RenderPlayerTransformer.java create mode 100644 src/main/resources/mixin.minelp.json diff --git a/.gitignore b/.gitignore index 463f065f..cec4fab5 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,5 @@ run/ .classpath .project *.launch +/.apt_generated/ +.factorypath diff --git a/build.gradle b/build.gradle index be844a38..5f3b6187 100644 --- a/build.gradle +++ b/build.gradle @@ -5,18 +5,25 @@ buildscript { name 'forge' url 'http://files.minecraftforge.net/maven' } + maven { + name = 'sponge' + url = 'http://repo.spongepowered.org/maven' + } } dependencies { classpath 'net.minecraftforge.gradle:ForgeGradle:2.0-SNAPSHOT' + classpath 'org.spongepowered:mixingradle:0.1-SNAPSHOT' } } plugins { + id 'mnm.gradle.ap-ide' version '1.0.2' } ext.voxellib = project ':voxellib' ext.revision = 186 apply plugin: 'net.minecraftforge.gradle.tweaker-client' +apply plugin: 'org.spongepowered.mixin' archivesBaseName = "MineLittlePony" group = 'com.brohoof.minelp' @@ -24,7 +31,7 @@ version = '1.8' minecraft { version = "1.8" - mappings = 'snapshot_20151027' + mappings = 'stable_18' runDir = 'run' replace '@VERSION@',project.version tweakClass = 'com.mumfrey.liteloader.launch.LiteLoaderTweaker' @@ -75,12 +82,14 @@ processResources { exclude 'litemod.json' } } -allprojects {repositories{ - maven { - name 'sponge' - url 'http://repo.spongepowered.org/maven' +allprojects { + repositories{ + maven { + name 'sponge' + url 'http://repo.spongepowered.org/maven' + } } -}} +} dependencies { provided project('LiteLoader') provided voxellib @@ -109,7 +118,10 @@ reobf { jar.task.enabled = false standaloneJar{} } - +sourceSets.main.refMap = 'mixin.minelp.refmap.json' +mixin { + defaultObfuscationEnv notch +} task installMod(type: Copy, dependsOn: build) { from standaloneJar.archivePath into file("$System.env.APPDATA/.minecraft/mods") diff --git a/src/main/java/com/brohoof/minelittlepony/renderer/RenderPony.java b/src/main/java/com/brohoof/minelittlepony/mixin/MixinRenderPlayer.java similarity index 82% rename from src/main/java/com/brohoof/minelittlepony/renderer/RenderPony.java rename to src/main/java/com/brohoof/minelittlepony/mixin/MixinRenderPlayer.java index 0ab6ffd2..c110abca 100644 --- a/src/main/java/com/brohoof/minelittlepony/renderer/RenderPony.java +++ b/src/main/java/com/brohoof/minelittlepony/mixin/MixinRenderPlayer.java @@ -1,19 +1,24 @@ -package com.brohoof.minelittlepony.renderer; +package com.brohoof.minelittlepony.mixin; import static net.minecraft.client.renderer.GlStateManager.scale; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + import com.brohoof.minelittlepony.MineLittlePony; import com.brohoof.minelittlepony.Pony; import com.brohoof.minelittlepony.PonySize; import com.brohoof.minelittlepony.model.PMAPI; import com.brohoof.minelittlepony.model.PlayerModel; import com.brohoof.minelittlepony.model.pony.ModelHumanPlayer; +import com.brohoof.minelittlepony.renderer.IRenderPony; import com.brohoof.minelittlepony.renderer.layer.LayerHeldPonyItem; import com.brohoof.minelittlepony.renderer.layer.LayerPonyArmor; import com.brohoof.minelittlepony.renderer.layer.LayerPonyCape; import com.brohoof.minelittlepony.renderer.layer.LayerPonySkull; -import com.mumfrey.liteloader.transformers.AppendInsns; -import com.mumfrey.liteloader.transformers.Obfuscated; import net.minecraft.client.entity.AbstractClientPlayer; import net.minecraft.client.entity.EntityPlayerSP; @@ -26,19 +31,18 @@ import net.minecraft.item.EnumAction; import net.minecraft.item.ItemStack; import net.minecraft.util.ResourceLocation; -public abstract class RenderPony extends RendererLivingEntity implements IRenderPony { - @SuppressWarnings("unused") - private static RenderPlayer __TARGET; +@Mixin(RenderPlayer.class) +public abstract class MixinRenderPlayer extends RendererLivingEntity implements IRenderPony { + private PlayerModel playerModel; private Pony thePony; - private RenderPony(RenderManager renderManager) { + private MixinRenderPlayer(RenderManager renderManager) { super(renderManager, null, 0.5F); - throw new InstantiationError("Overlay classes must not be instantiated"); } - @AppendInsns("") - private void init(RenderManager renderManager, boolean useSmallArms) { + @Inject(method="(Lnet/minecraft/client/renderer/entity/RenderManager;Z)V", at=@At("RETURN")) + private void init(RenderManager renderManager, boolean useSmallArms, CallbackInfo ci) { this.playerModel = PMAPI.pony; this.mainModel = this.playerModel.getModel(); this.shadowSize = this.playerModel.getShadowsize(); @@ -51,7 +55,7 @@ public abstract class RenderPony extends RendererLivingEntity implements IRender this.addLayer(new LayerPonyCape(this)); } - @Obfuscated({ "a", "func_180596_a" }) + @Overwrite public void doRender(AbstractClientPlayer player, double x, double y, double z, float yaw, float partialTicks) { ItemStack currentItemStack = player.inventory.getCurrentItem(); this.thePony = MineLittlePony.getInstance().getManager().getPonyFromResourceRegistry(player); @@ -106,9 +110,8 @@ public abstract class RenderPony extends RendererLivingEntity implements IRender this.playerModel.getModel().heldItemRight = 0; } - @AppendInsns("renderLivingAt") - @Obfuscated({ "a", "func_77039_a" }) - public void setupPlayerScale(AbstractClientPlayer player, double xPosition, double yPosition, double zPosition) { + @Inject(method = "renderLivingAt", at = @At("RETURN")) + private void setupPlayerScale(AbstractClientPlayer player, double xPosition, double yPosition, double zPosition, CallbackInfo ci) { if (MineLittlePony.getConfig().getShowScale().get() && !(playerModel.getModel() instanceof ModelHumanPlayer)) { PonySize size = thePony.metadata.getSize(); @@ -119,17 +122,17 @@ public abstract class RenderPony extends RendererLivingEntity implements IRender } } - public ResourceLocation getEntityTexture(AbstractClientPlayer player) { + private ResourceLocation getEntityTexture(AbstractClientPlayer player) { Pony thePony = MineLittlePony.getInstance().getManager().getPonyFromResourceRegistry(player); return thePony.getTextureResourceLocation(); } @Override - public ResourceLocation getEntityTexture(Entity entity) { + public final ResourceLocation getEntityTexture(Entity entity) { return this.getEntityTexture((AbstractClientPlayer) entity); } - protected PlayerModel getModel(AbstractClientPlayer player) { + private PlayerModel getModel(AbstractClientPlayer player) { Pony thePony = MineLittlePony.getInstance().getManager().getPonyFromResourceRegistry(player); return thePony.getModel(); } diff --git a/src/main/java/com/brohoof/minelittlepony/transformers/RenderPlayerTransformer.java b/src/main/java/com/brohoof/minelittlepony/transformers/RenderPlayerTransformer.java deleted file mode 100644 index 8a37afff..00000000 --- a/src/main/java/com/brohoof/minelittlepony/transformers/RenderPlayerTransformer.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.brohoof.minelittlepony.transformers; - -import com.mumfrey.liteloader.transformers.ClassOverlayTransformer; - -public class RenderPlayerTransformer extends ClassOverlayTransformer { - - private static final String overlayClassName = "com.brohoof.minelittlepony.renderer.RenderPony"; - - public RenderPlayerTransformer() { - super(overlayClassName); - } -} diff --git a/src/main/resources/litemod.json b/src/main/resources/litemod.json index 682ae243..946bd556 100644 --- a/src/main/resources/litemod.json +++ b/src/main/resources/litemod.json @@ -5,7 +5,7 @@ "revision": "${revision}", "author": "Verdana, Rene_Z, Mumfrey, JoyJoy", "voxelCommonJarName": "voxelcommon-2.4.0.jar", - "classTransformerClasses": "com.brohoof.minelittlepony.transformers.RenderPlayerTransformer", + "mixinConfigs": "mixin.minelp.json", "description": "Mine Little Pony turns players and mobs into ponies", "description.minelittlepony": "Mine Little Pony turns players and mobs into ponies", "description.hdskins": "Seperate skin server for Mine Little Pony that also supports HD skins. Access via Skin Manager key binding (default: F1) in the main menu." diff --git a/src/main/resources/mixin.minelp.json b/src/main/resources/mixin.minelp.json new file mode 100644 index 00000000..ca85db1b --- /dev/null +++ b/src/main/resources/mixin.minelp.json @@ -0,0 +1,7 @@ +{ + "package": "com.brohoof.minelittlepony.mixin", + "refmap": "mixin.minelp.refmap.json", + "mixins": [ + "MixinRenderPlayer" + ] +} \ No newline at end of file