Reduce the number of Mixin Class modifications in Gecko Addon

- Reduced Mixin Requirement to 0.7.11
This commit is contained in:
Kam committed 2024-01-24 18:36:32 -05:00
1 parent e2777528c8
commit 27c9b92f3d
10 files changed
+168 -165

No files matched your search

@@ -5,18 +5,28 @@ import com.goodbird.cnpcgeckoaddon.mixin.IDataDisplay;
import com.goodbird.cnpcgeckoaddon.utils.NpcTextureUtils;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.util.ResourceLocation;
import noppes.npcs.client.EntityUtil;
import kamkeel.addon.GeckoAddon;
import noppes.npcs.entity.EntityCustomNpc;
import noppes.npcs.entity.EntityNPCInterface;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
@Mixin(EntityUtil.class)
public class MixinEntityUtil {
@Mixin(GeckoAddon.class)
public class MixinGeckoAddon {
@Shadow(remap = false) public boolean supportEnabled;
/**
* @author Goodbird
* @reason Allow for Copying of Data for Custom Model information
*/
@Overwrite(remap = false)
public void geckoCopyData(EntityLivingBase copied, EntityLivingBase entity) {
if(!supportEnabled)
return;
@Inject(method = "Copy", at = @At("TAIL"), remap = false)
private static void copy(EntityLivingBase copied, EntityLivingBase entity, CallbackInfo ci) {
if (entity instanceof EntityCustomModel modelEntity && copied instanceof EntityNPCInterface npc) {
IDataDisplay display = (IDataDisplay) npc.display;
modelEntity.textureResLoc = NpcTextureUtils.getNpcTexture((EntityNPCInterface) copied);
@@ -0,0 +1,146 @@
package com.goodbird.cnpcgeckoaddon.mixin.impl;
import com.goodbird.cnpcgeckoaddon.client.gui.GuiStringSelection;
import com.goodbird.cnpcgeckoaddon.client.gui.SubGuiModelAnimation;
import com.goodbird.cnpcgeckoaddon.entity.EntityCustomModel;
import com.goodbird.cnpcgeckoaddon.mixin.IDataDisplay;
import com.goodbird.cnpcgeckoaddon.utils.NpcTextureUtils;
import kamkeel.addon.GeckoAddon;
import kamkeel.addon.client.GeckoAddonClient;
import net.minecraft.client.Minecraft;
import net.minecraft.client.model.ModelBase;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.entity.EntityList;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.util.ResourceLocation;
import noppes.npcs.client.gui.model.GuiCreationScreen;
import noppes.npcs.client.gui.util.GuiNPCInterface2;
import noppes.npcs.client.gui.util.GuiNpcButton;
import noppes.npcs.client.gui.util.GuiNpcLabel;
import noppes.npcs.client.model.ModelMPM;
import noppes.npcs.entity.EntityNPCInterface;
import org.lwjgl.opengl.GL11;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import software.bernie.geckolib3.core.IAnimatable;
import software.bernie.geckolib3.resource.GeckoLibCache;
import java.util.Vector;
@Mixin(GeckoAddonClient.class)
public class MixinGeckoAddonClient {
@Shadow(remap = false) public boolean supportEnabled;
/**
* @author Goodbird
* @reason Show Custom Model Selection button for Custom Entities
*/
@Overwrite(remap = false)
public void showGeckoButtons(GuiCreationScreen creationScreen, EntityLivingBase entity){
if(!supportEnabled)
return;
if(EntityList.getEntityString(entity).equals("cnpcgeckoaddon.CustomModelEntity") || EntityList.getEntityString(entity).equals("Geckolib Model")){
creationScreen.addButton(new GuiNpcButton(202, creationScreen.guiLeft-60, creationScreen.guiTop+40, 180, 20, ((IDataDisplay)creationScreen.npc.display).getCustomModelData().getModel()));
}
}
/**
* @author Goodbird
* @reason Add support for new showGeckoButtons() in GuiCreationScreen
*/
@Overwrite(remap = false)
public void geckoGuiCreationScreenActionPerformed(GuiCreationScreen creationScreen, GuiNpcButton button){
if(!supportEnabled)
return;
if(button.id == 202){
Vector<String> list = new Vector<>();
for(ResourceLocation resLoc : GeckoLibCache.getInstance().getGeoModels().keySet()){
list.add(resLoc.toString());
}
creationScreen.setSubGui(new GuiStringSelection(creationScreen,"Selecting geckolib model:", list, name -> {
((IDataDisplay)creationScreen.npc.display).getCustomModelData().setModel(name);
creationScreen.getButton(202).setDisplayText(name);
}));
}
}
/**
* @author Goodbird
* @reason Init Model Animation Button for NPCs
*/
@Overwrite(remap = false)
public void geckoNpcDisplayInitGui(GuiNPCInterface2 gui){
if(!supportEnabled)
return;
int y = 319;
gui.addLabel(new GuiNpcLabel(212,"Model Animation", gui.guiLeft + 185, y + 5));
gui.addButton(new GuiNpcButton(212, gui.guiLeft + 300, y, 100, 20, "selectServer.edit"));
if (!((IDataDisplay)gui.npc.display).hasCustomModel()) {
gui.getLabel(212).enabled=false;
gui.getButton(212).setVisible(false);
gui.getButton(212).setEnabled(false);
}
}
/**
* @author Goodbird
* @reason Add Support for Model Animation button on Npc Display
*/
@Overwrite(remap = false)
public void geckoNpcDisplayActionPerformed(GuiNPCInterface2 gui, GuiNpcButton btn){
if(!supportEnabled)
return;
if(btn.id == 212){
gui.setSubGui(new SubGuiModelAnimation(gui.npc));
}
}
/**
* @author KAMKEEEL
* @reason Check if Entity is a Gecko Model
*/
@Overwrite(remap = false)
public boolean isGeckoModel(ModelBase mainModel){
if(!supportEnabled)
return false;
return (mainModel instanceof ModelMPM && ((ModelMPM) mainModel).entity instanceof IAnimatable);
}
/**
* @author Goodbird
* @reason Render Gecko Model Support
*/
@Overwrite(remap = false)
public void geckoRenderModel(ModelMPM mainModel, EntityNPCInterface npc, float rot, float partial){
GL11.glRotatef(180, 1,0,0);
GL11.glTranslated(0, -1.5,0);
(mainModel).entity.renderYawOffset = (mainModel).entity.prevRenderYawOffset = 0;
if (!npc.isInvisible())
{
RenderManager.instance.renderEntityWithPosYaw(((ModelMPM) mainModel).entity, 0,0,0,rot,partial);
}
else if (!npc.isInvisibleToPlayer(Minecraft.getMinecraft().thePlayer))
{
GL11.glPushMatrix();
GL11.glColor4f(1.0F, 1.0F, 1.0F, 0.15F);
GL11.glDepthMask(false);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glAlphaFunc(GL11.GL_GREATER, 0.003921569F);
RenderManager.instance.renderEntityWithPosYaw(((ModelMPM) mainModel).entity, 0,0,0,rot,partial);
GL11.glDisable(GL11.GL_BLEND);
GL11.glAlphaFunc(GL11.GL_GREATER, 0.1F);
GL11.glPopMatrix();
GL11.glDepthMask(true);
}
}
}
@@ -1,48 +0,0 @@
package com.goodbird.cnpcgeckoaddon.mixin.impl;
import com.goodbird.cnpcgeckoaddon.client.gui.GuiStringSelection;
import com.goodbird.cnpcgeckoaddon.mixin.IDataDisplay;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.entity.EntityList;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.util.ResourceLocation;
import noppes.npcs.client.gui.model.GuiCreationScreen;
import noppes.npcs.client.gui.util.GuiModelInterface;
import noppes.npcs.client.gui.util.GuiNpcButton;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import software.bernie.geckolib3.resource.GeckoLibCache;
import java.util.Vector;
@Mixin(GuiCreationScreen.class)
public class MixinGuiCreationScreen extends GuiModelInterface {
public MixinGuiCreationScreen() {
super(null);
}
@Inject(method = "showEntityButtons", at = @At("TAIL"), remap = false)
private void showEntityButtons(EntityLivingBase entity, CallbackInfo ci) {
if(EntityList.getEntityString(entity).equals("cnpcgeckoaddon.CustomModelEntity") || EntityList.getEntityString(entity).equals("Geckolib Model")){
this.addButton(new GuiNpcButton(202, guiLeft-60, this.guiTop+40, 180, 20, ((IDataDisplay)npc.display).getCustomModelData().getModel()));
}
}
@Inject(method = "actionPerformed", at = @At("TAIL"))
protected void actionPerformed(GuiButton btn, CallbackInfo ci) {
GuiNpcButton button = (GuiNpcButton) btn;
if(button.id == 202){
Vector<String> list = new Vector<>();
for(ResourceLocation resLoc : GeckoLibCache.getInstance().getGeoModels().keySet()){
list.add(resLoc.toString());
}
setSubGui(new GuiStringSelection(this,"Selecting geckolib model:", list, name -> {
((IDataDisplay)npc.display).getCustomModelData().setModel(name);
getButton(202).setDisplayText(name);
}));
}
}
}
@@ -1,41 +0,0 @@
package com.goodbird.cnpcgeckoaddon.mixin.impl;
import com.goodbird.cnpcgeckoaddon.client.gui.SubGuiModelAnimation;
import com.goodbird.cnpcgeckoaddon.mixin.IDataDisplay;
import net.minecraft.client.gui.GuiButton;
import noppes.npcs.client.gui.mainmenu.GuiNpcDisplay;
import noppes.npcs.client.gui.util.GuiNPCInterface2;
import noppes.npcs.client.gui.util.GuiNpcButton;
import noppes.npcs.client.gui.util.GuiNpcLabel;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(GuiNpcDisplay.class)
public abstract class MixinGuiNpcDisplay extends GuiNPCInterface2 {
public MixinGuiNpcDisplay() {
super(null);
}
@Inject(method = "initGui", at = @At("TAIL"))
public void initGui(CallbackInfo ci){
int y = 319;
addLabel(new GuiNpcLabel(212,"Model Animation", guiLeft + 185, y + 5));
this.addButton(new GuiNpcButton(212, guiLeft + 300, y, 100, 20, "selectServer.edit"));
if (!((IDataDisplay)npc.display).hasCustomModel()) {
this.getLabel(212).enabled=false;
this.getButton(212).setVisible(false);
this.getButton(212).setEnabled(false);
}
}
@Inject(method = "actionPerformed", at = @At("TAIL"))
public void actionPerformed(GuiButton guibutton, CallbackInfo ci){
GuiNpcButton button = (GuiNpcButton) guibutton;
if(button.id == 212){
setSubGui(new SubGuiModelAnimation(npc));
}
}
}
@@ -1,59 +0,0 @@
package com.goodbird.cnpcgeckoaddon.mixin.impl;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.client.renderer.entity.RendererLivingEntity;
import net.minecraft.entity.EntityLivingBase;
import noppes.npcs.client.model.ModelMPM;
import noppes.npcs.client.renderer.RenderNPCInterface;
import noppes.npcs.entity.EntityNPCInterface;
import org.lwjgl.opengl.GL11;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import software.bernie.geckolib3.core.IAnimatable;
@Mixin(RenderNPCInterface.class)
public abstract class MixinRenderNPCInterface extends RendererLivingEntity {
public MixinRenderNPCInterface() {
super(null,0);
}
@Inject(method = "renderModel",at=@At("HEAD"), cancellable = true)
protected void renderModel(EntityLivingBase entityliving, float par2, float par3, float par4, float par5, float par6, float par7, CallbackInfo ci) {
EntityNPCInterface npc = (EntityNPCInterface)entityliving;
if(mainModel instanceof ModelMPM && ((ModelMPM) mainModel).entity instanceof IAnimatable){
GL11.glRotatef(180, 1,0,0);
GL11.glTranslated(0, -1.5,0);
customNPC_Gecko_Addon$renderGeoModel(npc, npc.rotationYaw, Minecraft.getMinecraft().timer.renderPartialTicks);
ci.cancel();
}
}
@Unique
private void customNPC_Gecko_Addon$renderGeoModel(EntityNPCInterface npc, float rot, float partial)
{
((ModelMPM) mainModel).entity.renderYawOffset = ((ModelMPM) mainModel).entity.prevRenderYawOffset = 0;
if (!npc.isInvisible())
{
RenderManager.instance.renderEntityWithPosYaw(((ModelMPM) mainModel).entity, 0,0,0,rot,partial);
}
else if (!npc.isInvisibleToPlayer(Minecraft.getMinecraft().thePlayer))
{
GL11.glPushMatrix();
GL11.glColor4f(1.0F, 1.0F, 1.0F, 0.15F);
GL11.glDepthMask(false);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glAlphaFunc(GL11.GL_GREATER, 0.003921569F);
RenderManager.instance.renderEntityWithPosYaw(((ModelMPM) mainModel).entity, 0,0,0,rot,partial);
GL11.glDisable(GL11.GL_BLEND);
GL11.glAlphaFunc(GL11.GL_GREATER, 0.1F);
GL11.glPopMatrix();
GL11.glDepthMask(true);
}
}
}
@@ -13,7 +13,6 @@ import noppes.npcs.client.renderer.ImageBufferDownloadAlt;
import noppes.npcs.client.renderer.RenderNPCInterface;
import noppes.npcs.entity.EntityCustomNpc;
import noppes.npcs.entity.EntityNPCInterface;
import com.goodbird.cnpcgeckoaddon.mixin.impl.MixinRenderNPCInterface;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;