MagmaGuy / EliteMobs

This is a spigot plugin that aims to extend Minecraft's survival endgame by making mobs more interesting.
http://www.magmaguy.com
GNU General Public License v3.0
162 stars 61 forks source link

Add support ModelEngine 4 #173

Open Euphillya opened 2 weeks ago

Euphillya commented 2 weeks ago

Version Minecraft : [10:30:19 INFO]: This server is running Paper version 1.21.1-DEV-HEAD@5757f1f (2024-08-19T11:28:52Z) (Implementing API version 1.21.1-R0.1-SNAPSHOT) Error obtaining version information Previous version: 1.21.1-38-e4b38b4 (MC: 1.21.1)

Version EliteMobs [10:30:51 INFO]: EliteMobs version 9.1.8 [10:30:51 INFO]: Author: MagmaGuy

Version ModelEngine : [10:31:09 INFO]: ModelEngine version R4.0.7 [10:31:09 INFO]: Author: Ticxo

Config

isEnabled: true
entityType: HUSK
name: $eventBossLevel &3MINOTAUR
level: dynamic
onSpawnBlockStates: []
onRemoveBlockStates: []
bossType: NORMAL
customModel: minotaur

Description :

I tried using FreeMinecraftModels and it works, but I need ModelEngine for Bedrock players.

When I put the ModelEngine resource pack in my Minecraft, the mobs have no texture, just the default mob.

Euphillya commented 2 weeks ago

Change code for support R4

package com.magmaguy.elitemobs.thirdparty.custommodels.modelengine;

import com.magmaguy.elitemobs.mobconstructor.custombosses.CustomBossEntity;
import com.magmaguy.elitemobs.thirdparty.custommodels.CustomModelInterface;
import com.magmaguy.magmacore.util.Logger;
import com.ticxo.modelengine.api.ModelEngineAPI;
import com.ticxo.modelengine.api.generator.blueprint.ModelBlueprint;
import com.ticxo.modelengine.api.model.ActiveModel;
import com.ticxo.modelengine.api.model.ModeledEntity;
import com.ticxo.modelengine.api.model.bone.ModelBone;
import com.ticxo.modelengine.api.mount.controller.MountControllerTypes;
import lombok.Getter;
import org.bukkit.entity.LivingEntity;

public class CustomModelMEG implements CustomModelInterface {

    ActiveModel activeModel;
    ModeledEntity modeledEntity;

    ModelBlueprint modelBlueprint;

    @Getter
    private boolean success = false;

    public CustomModelMEG(LivingEntity livingEntity, String modelName, String nametagName) {
        try {
            if (ModelEngineAPI.getBlueprint(modelName) == null) {
                Logger.info("Model " + modelName + " was not found! Make sure you install the model correctly if you have it. This entry will be skipped!");
                return;
            }
        } catch (NoSuchMethodError ex) {
            Logger.warn("Model Engine API version is not supported. Currently Elitemobs can only support ModelEngine R3.0.0.");
            return;
        }

        modelBlueprint = ModelEngineAPI.getBlueprint(modelName);

        activeModel = ModelEngineAPI.createActiveModel(modelBlueprint);

        if (activeModel == null) {
            Logger.warn("Failed to load model from " + modelName + " ! Is the model name correct, and has the model been installed correctly?");
            return;
        }

        modeledEntity = ModelEngineAPI.createModeledEntity(livingEntity);

        if (modeledEntity == null) {
            Logger.warn("Failed to create model entity " + modelName + " ! This means the entity that was meant to get disguised has a problem!");
            return;
        }

        try {
            modeledEntity.addModel(activeModel, true);
            modeledEntity.setBaseEntityVisible(false);
            setName(nametagName, true);
            success = true;
        } catch (Exception exception) {
            modeledEntity.removeModel(modelName);
            Logger.warn("Failed to make model entity " + modelName + " ! Couldn't assign model or visibility status.");
            exception.printStackTrace();
        }

    }

    public static CustomModelMEG generateCustomModel(LivingEntity livingEntity, String modelName, String nametagName) {
        CustomModelMEG customModel = new CustomModelMEG(livingEntity, modelName, nametagName);
        return customModel.isSuccess() ? customModel : null;
    }

    public static void reloadModels() {
        try {
            ModelEngineAPI.getAPI().getModelGenerator().importModels();
        } catch (Exception ex) {
            Logger.warn("Model Engine API version is not supported. Currently Elitemobs can only support ModelEngine R3.0.0.");
        }
    }

    public static boolean modelExists(String modelName) {
        if (modelName == null || modelName.isEmpty()) return false;
        try {
            if (ModelEngineAPI.getBlueprint(modelName) == null) {
                Logger.info("Model " + modelName + " was not found! Make sure you install the model correctly if you have it. This entry will be skipped!");
                return false;
            }
        } catch (NoSuchMethodError ex) {
            Logger.warn("Model Engine API version is not supported. Currently Elitemobs can only support ModelEngine R3.0.0, documentation for other versions doesn't exist.");
            return false;
        }

        return true;
    }

    public void shoot() {
        if (activeModel == null) return;
        if (modelBlueprint.getAnimations().containsKey("attack_ranged"))
            activeModel.getAnimationHandler().playAnimation("attack_ranged", .1, .1, 1, true);
        else
            activeModel.getAnimationHandler().playAnimation("attack", .1, .1, 1, true);
    }

    public void melee() {
        if (activeModel == null) return;
        if (modelBlueprint.getAnimations().containsKey("attack_melee"))
            activeModel.getAnimationHandler().playAnimation("attack_melee", .1, .1, 1, true);
        else
            activeModel.getAnimationHandler().playAnimation("attack", .1, .1, 1, true);
    }

    public void playAnimationByName(String string) {
        if (activeModel == null) return;
        if (!modelBlueprint.getAnimations().containsKey(string)) return;
        activeModel.getAnimationHandler().playAnimation(string, .1, .1, 1, true);
    }

    @Override
    public void setName(String nametagName, boolean visible) {
        if (modeledEntity == null) return;
        ModelBone nametag = getNameableBone();
        if (nametag == null) {
            Logger.warn("Failed to get hitbox nametag for disguise!");
            return;
        }
        nametag.setCustomId(nametagName);
        nametag.setVisible(visible);
    }

    public void setNameVisible(boolean visible) {
        ModelBone nametag = getNameableBone();
        if (nametag == null) {
            return;
        }
        nametag.setVisible(visible);
    }

    private ModelBone getNameableBone() {
        for (ModelBone nameable : activeModel.getBones().values()) return nameable;
        return null;
    }

    public void addPassenger(CustomBossEntity passenger) {
        if (passenger.getCustomBossesConfigFields().getCustomModelMountPointID() == null) {
            Logger.warn("Attempted to add " + passenger.getCustomBossesConfigFields().getFilename() + " as a mounted entity for a custom model but it does not have customModelMountPointID set! The boss can't guess where it needs to be mounted, and therefore this will not work.");
            return;
        }
        activeModel.getMountManager().ifPresent(mountManager -> {
            mountManager.mountPassenger(modelBlueprint.getName(), passenger.getLivingEntity(), MountControllerTypes.WALKING);
            mountManager.setDriverBone(modeledEntity.getMountData().getMainMountManager().getDriverBone());
        });
    }

    public void switchPhase() {
        activeModel.getAnimationHandler().forceStopAllAnimations();
    }

}
MagmaGuy commented 2 weeks ago

Version Minecraft : [10:30:19 INFO]: This server is running Paper version 1.21.1-DEV-HEAD@5757f1f (2024-08-19T11:28:52Z) (Implementing API version 1.21.1-R0.1-SNAPSHOT) Error obtaining version information Previous version: 1.21.1-38-e4b38b4 (MC: 1.21.1)

Version EliteMobs [10:30:51 INFO]: EliteMobs version 9.1.8 [10:30:51 INFO]: Author: MagmaGuy

Version ModelEngine : [10:31:09 INFO]: ModelEngine version R4.0.7 [10:31:09 INFO]: Author: Ticxo

Config

isEnabled: true
entityType: HUSK
name: $eventBossLevel &3MINOTAUR
level: dynamic
onSpawnBlockStates: []
onRemoveBlockStates: []
bossType: NORMAL
customModel: minotaur

Description :

I tried using FreeMinecraftModels and it works, but I need ModelEngine for Bedrock players.

When I put the ModelEngine resource pack in my Minecraft, the mobs have no texture, just the default mob.

FreeMinecraftModels works for bedrock players as well

Euphillya commented 2 weeks ago

Are you any examples? Because I have trying without success

MagmaGuy commented 2 weeks ago

Are you any examples? Because I have trying without success

It shouldn't require doing anything, assuming you're using floodgate, the idea would be that it detects you are using a bedrock client and automatically send you the appropriate packets

Euphillya commented 2 weeks ago

A Java Edition texture pack does not work on Bedrock Edition, so unless there is a functionality that I am not aware of, there is definitely an intervention to be carried.

MagmaGuy commented 2 weeks ago

Ok, to be clear, you don't need to do anything as a developer, or as a player. However, as an admin, you do need to convert the resource pack and then put it somewhere where geyser can distribute it to players. Doing this automatically is in the planned features of ResourcePackManager, which currently does it for java edition resources, but it hasn't been added yet.

Euphillya commented 2 weeks ago

Ah I need ResourcePackManager, ok good I will trying this night ! Verry thx for your helps