diff --git a/build.gradle b/build.gradle index 2b8ebee..d871efe 100644 --- a/build.gradle +++ b/build.gradle @@ -15,13 +15,11 @@ import com.matthewprenger.cursegradle.CurseArtifact import com.matthewprenger.cursegradle.CurseRelation import com.modrinth.minotaur.dependencies.ModDependency import com.modrinth.minotaur.dependencies.VersionDependency -import org.gradle.internal.logging.text.StyledTextOutput.Style import org.gradle.internal.logging.text.StyledTextOutputFactory import org.gradle.internal.xml.XmlTransformer import org.jetbrains.gradle.ext.Application import org.jetbrains.gradle.ext.Gradle -import javax.inject.Inject import java.nio.file.Files import java.nio.file.Paths import java.util.concurrent.TimeUnit diff --git a/dependencies.gradle b/dependencies.gradle index 9ca379e..a5b8d60 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -34,6 +34,6 @@ * For more details, see https://docs.gradle.org/8.0.1/userguide/java_library_plugin.html#sec:java_library_configurations_graph */ dependencies { - implementation name: "CustomNPC-Plus-1.8.6-dev" + implementation name: "CustomNPC-Plus-1.9-beta5" implementation name: "geckolib-forge-1.7.10-3.0.32" } diff --git a/lib/CustomNPC-Plus-1.8.6-dev.jar b/lib/CustomNPC-Plus-1.9-beta5.jar similarity index 61% rename from lib/CustomNPC-Plus-1.8.6-dev.jar rename to lib/CustomNPC-Plus-1.9-beta5.jar index 2478098..c10564d 100644 Binary files a/lib/CustomNPC-Plus-1.8.6-dev.jar and b/lib/CustomNPC-Plus-1.9-beta5.jar differ diff --git a/src/main/java/com/goodbird/cnpcgeckoaddon/mixin/impl/MixinEntityUtil.java b/src/main/java/com/goodbird/cnpcgeckoaddon/mixin/impl/MixinGeckoAddon.java similarity index 68% rename from src/main/java/com/goodbird/cnpcgeckoaddon/mixin/impl/MixinEntityUtil.java rename to src/main/java/com/goodbird/cnpcgeckoaddon/mixin/impl/MixinGeckoAddon.java index b15d930..d803954 100644 --- a/src/main/java/com/goodbird/cnpcgeckoaddon/mixin/impl/MixinEntityUtil.java +++ b/src/main/java/com/goodbird/cnpcgeckoaddon/mixin/impl/MixinGeckoAddon.java @@ -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); diff --git a/src/main/java/com/goodbird/cnpcgeckoaddon/mixin/impl/MixinGeckoAddonClient.java b/src/main/java/com/goodbird/cnpcgeckoaddon/mixin/impl/MixinGeckoAddonClient.java new file mode 100644 index 0000000..8620ce0 --- /dev/null +++ b/src/main/java/com/goodbird/cnpcgeckoaddon/mixin/impl/MixinGeckoAddonClient.java @@ -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 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); + } + } +} diff --git a/src/main/java/com/goodbird/cnpcgeckoaddon/mixin/impl/MixinGuiCreationScreen.java b/src/main/java/com/goodbird/cnpcgeckoaddon/mixin/impl/MixinGuiCreationScreen.java deleted file mode 100644 index fa6c2a6..0000000 --- a/src/main/java/com/goodbird/cnpcgeckoaddon/mixin/impl/MixinGuiCreationScreen.java +++ /dev/null @@ -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 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); - })); - } - } -} diff --git a/src/main/java/com/goodbird/cnpcgeckoaddon/mixin/impl/MixinGuiNpcDisplay.java b/src/main/java/com/goodbird/cnpcgeckoaddon/mixin/impl/MixinGuiNpcDisplay.java deleted file mode 100644 index e830271..0000000 --- a/src/main/java/com/goodbird/cnpcgeckoaddon/mixin/impl/MixinGuiNpcDisplay.java +++ /dev/null @@ -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)); - } - } -} diff --git a/src/main/java/com/goodbird/cnpcgeckoaddon/mixin/impl/MixinRenderNPCInterface.java b/src/main/java/com/goodbird/cnpcgeckoaddon/mixin/impl/MixinRenderNPCInterface.java deleted file mode 100644 index 5a7c39c..0000000 --- a/src/main/java/com/goodbird/cnpcgeckoaddon/mixin/impl/MixinRenderNPCInterface.java +++ /dev/null @@ -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); - } - } -} diff --git a/src/main/java/com/goodbird/cnpcgeckoaddon/utils/NpcTextureUtils.java b/src/main/java/com/goodbird/cnpcgeckoaddon/utils/NpcTextureUtils.java index f56d78e..a5faf2a 100644 --- a/src/main/java/com/goodbird/cnpcgeckoaddon/utils/NpcTextureUtils.java +++ b/src/main/java/com/goodbird/cnpcgeckoaddon/utils/NpcTextureUtils.java @@ -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; diff --git a/src/main/resources/mixins.cnpcgeckoaddon.json b/src/main/resources/mixins.cnpcgeckoaddon.json index e6405a0..b6d471e 100644 --- a/src/main/resources/mixins.cnpcgeckoaddon.json +++ b/src/main/resources/mixins.cnpcgeckoaddon.json @@ -1,18 +1,16 @@ { "required": true, - "minVersion": "0.8.5-GTNH", + "minVersion": "0.7.11", "package": "com.goodbird.cnpcgeckoaddon.mixin.impl", "refmap": "mixins.cnpcgeckoaddon.refmap.json", "target": "@env(DEFAULT)", "compatibilityLevel": "JAVA_8", "mixins": [ "MixinDataDisplay", - "MixinEntityUtil" + "MixinGeckoAddon" ], "client": [ - "MixinGuiCreationScreen", - "MixinGuiNpcDisplay", - "MixinRenderNPCInterface" + "MixinGeckoAddonClient" ], "server": [] }