Jump to content

Recommended Posts

Posted (edited)

I feel it is more like a java related problem... anyways, here's my code:

public abstract class GunModel implements IBakedModel
{
    protected IBakedModel origin;
    public GunModel(IBakedModel origin)
    {
        this.origin = origin;
    }

    public abstract static class Overrides extends ItemOverrideList
    {
        public Overrides()
        {
            super();
        }

        @Nullable
        @Override
        public IBakedModel getModelWithOverrides(IBakedModel origin, ItemStack stack, @Nullable World world, @Nullable LivingEntity entity)
        {
            if (!(stack.getItem() instanceof AVAItemGun))
                return origin;
            CompoundNBT compound = ((AVAItemGun) stack.getItem()).initTags(stack);
            return getModel(origin, compound.getInt("fire"), compound.getInt("reload"), compound.getInt("run"));
        }

        protected abstract IBakedModel getModel(IBakedModel origin, int fire, int reload, int run);
    }
}

 

public class P226Model extends GunModel
{
    protected P226Overrides overrides;
    public P226Model(IBakedModel origin)
    {
        super(origin);
        overrides = new P226Overrides();
    }

    @Override
    public ItemOverrideList getOverrides()
    {
        return overrides;
    }

    public static class P226Overrides extends Overrides
    {
        public P226Overrides()
        {
            super();
        }

        @Override
        protected IBakedModel getModel(IBakedModel origin, int fire, int reload, int run)
        {
            return new ModifiedP226Model(origin, fire, reload, run);
        }
    }
}

 

public class ModifiedGunModel implements IBakedModel
{
    protected int fire;
    protected int reload;
    protected int run;
    protected IBakedModel origin;
    public ModifiedGunModel(IBakedModel origin, int fire, int reload, int run)
    {
        this.origin = origin;
        this.fire = fire;
        this.reload = reload;
        this.run = run;
    }

    @Override
    public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, Random rand)
    {
        System.out.println("parent");
        return origin.getQuads(state, side, rand);
    }

    @Override
    public ItemOverrideList getOverrides()
    {
        return null;
    }
}

 

public class ModifiedP226Model extends ModifiedGunModel
{
    public ModifiedP226Model(IBakedModel origin, int fire, int reload, int run)
    {
        super(origin, fire, reload, run);
    }

    @Override
    public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, Random rand)
    {
        System.out.println("inherited");
        return origin.getQuads(state, side, rand);
    }
  
    @Override
    public IBakedModel handlePerspective(ItemCameraTransforms.TransformType type, MatrixStack mat)
    {
        Vector3f rotation = null;
        Vector3f translation = null;
        Vector3f scale = null;
        switch (type)
        {
            case THIRD_PERSON_LEFT_HAND:
            case THIRD_PERSON_RIGHT_HAND:
                rotation = new Vector3f(70, 0, 0);
                translation = new Vector3f(0, 1, 3);
                scale = vector3f(1.65F);
                break;
            case FIRST_PERSON_LEFT_HAND:
            case FIRST_PERSON_RIGHT_HAND:
                rotation = new Vector3f(0, -23, 0);
                translation = new Vector3f(-2, 3.5F, 1.5F);
                scale = new Vector3f(1.5F, 1.5F, 1.5F);
                if (type == ItemCameraTransforms.TransformType.FIRST_PERSON_RIGHT_HAND)
                    this.modify(rotation, translation, scale, ItemCameraTransforms.TransformType.FIRST_PERSON_RIGHT_HAND);
                break;
            case GROUND:
                rotation = new Vector3f(0, 0, -90);
                break;
            case GUI:
                rotation = new Vector3f(0, -90, 0);
                translation = new Vector3f(-1, 1, 0);
                scale = vector3f(1.25F);
                break;
            case FIXED:
                rotation = new Vector3f(0, -90, 0);
                translation = new Vector3f(-1, 1.25F, 0);
                scale = vector3f(2);
                break;
        }
        this.getTransformationMatrix(rotation, translation, scale).push(mat);
        return this.origin.handlePerspective(type, mat);
    }
}

 

So what I'm struggling with is in

        @Override
        protected IBakedModel getModel(IBakedModel origin, int fire, int reload, int run)
        {
            return new ModifiedP226Model(origin, fire, reload, run);
        }

if I return a "ModifiedGunModel", it's getQuads() gets called. However if I return "ModifiedP226Model" which inherits from the "ModifiedGunModel", neither getQuads() gets called. Did I missed something or is this just not how it works?

Edited by poopoodice
Posted

AFAIK, #handlePerspective returns the called model. So

public IBakedModel handlePerspective(ItemCameraTransforms.TransformType transform, MatrixStack stack) {
	// any code
	return original.handlePerspective(transform, stack); // will return `original`, which will bypass whatever custom model you have.
}

You'll have to replicate what #handlePerspective does to the model before it returns the same model. IIRC, it calls ForgeHooksClient.handlePerspective on the model, which actually does the transforming of the model.

  • Like 1
Posted
10 minutes ago, sciwhiz12 said:

AFAIK, #handlePerspective returns the called model. So


public IBakedModel handlePerspective(ItemCameraTransforms.TransformType transform, MatrixStack stack) {
	// any code
	return original.handlePerspective(transform, stack); // will return `original`, which will bypass whatever custom model you have.
}

You'll have to replicate what #handlePerspective does to the model before it returns the same model. IIRC, it calls ForgeHooksClient.handlePerspective on the model, which actually does the transforming of the model.

Hi, I think you are right : )

it came out with if you return

this.origin.handlePerspective(type, mat)

somehow getQuads() will no longer gets called

On the other hand calls super works, or just do what I'm doing now:

        //some modification of rotationing scaling and translationing
	if (!transformationMatrix.isIdentity())
            transformationMatrix.push(mat);
        return getBakedModel();

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Im trying to build my mod using shade since i use the luaj library however i keep getting this error Reason: Task ':reobfJar' uses this output of task ':shadowJar' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed. So i try adding reobfJar.dependsOn shadowJar  Could not get unknown property 'reobfJar' for object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler. my gradle file plugins { id 'eclipse' id 'idea' id 'maven-publish' id 'net.minecraftforge.gradle' version '[6.0,6.2)' id 'com.github.johnrengelman.shadow' version '7.1.2' id 'org.spongepowered.mixin' version '0.7.+' } apply plugin: 'net.minecraftforge.gradle' apply plugin: 'org.spongepowered.mixin' apply plugin: 'com.github.johnrengelman.shadow' version = mod_version group = mod_group_id base { archivesName = mod_id } // Mojang ships Java 17 to end users in 1.18+, so your mod should target Java 17. java.toolchain.languageVersion = JavaLanguageVersion.of(17) //jarJar.enable() println "Java: ${System.getProperty 'java.version'}, JVM: ${System.getProperty 'java.vm.version'} (${System.getProperty 'java.vendor'}), Arch: ${System.getProperty 'os.arch'}" minecraft { mappings channel: mapping_channel, version: mapping_version copyIdeResources = true runs { configureEach { workingDirectory project.file('run') property 'forge.logging.markers', 'REGISTRIES' property 'forge.logging.console.level', 'debug' arg "-mixin.config=derp.mixin.json" mods { "${mod_id}" { source sourceSets.main } } } client { // Comma-separated list of namespaces to load gametests from. Empty = all namespaces. property 'forge.enabledGameTestNamespaces', mod_id } server { property 'forge.enabledGameTestNamespaces', mod_id args '--nogui' } gameTestServer { property 'forge.enabledGameTestNamespaces', mod_id } data { workingDirectory project.file('run-data') args '--mod', mod_id, '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources/') } } } sourceSets.main.resources { srcDir 'src/generated/resources' } repositories { flatDir { dirs './libs' } maven { url = "https://jitpack.io" } } configurations { shade implementation.extendsFrom shade } dependencies { minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}" implementation 'org.luaj:luaj-jse-3.0.2' implementation fg.deobf("com.github.Virtuoel:Pehkui:${pehkui_version}") annotationProcessor 'org.spongepowered:mixin:0.8.5:processor' minecraftLibrary 'luaj:luaj-jse:3.0.2' shade 'luaj:luaj-jse:3.0.2' } // Example for how to get properties into the manifest for reading at runtime. tasks.named('jar', Jar).configure { manifest { attributes([ 'Specification-Title' : mod_id, 'Specification-Vendor' : mod_authors, 'Specification-Version' : '1', // We are version 1 of ourselves 'Implementation-Title' : project.name, 'Implementation-Version' : project.jar.archiveVersion, 'Implementation-Vendor' : mod_authors, 'Implementation-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"), "TweakClass" : "org.spongepowered.asm.launch.MixinTweaker", "TweakOrder" : 0, "MixinConfigs" : "derp.mixin.json" ]) } rename 'mixin.refmap.json', 'derp.mixin-refmap.json' } shadowJar { archiveClassifier = '' configurations = [project.configurations.shade] finalizedBy 'reobfShadowJar' } assemble.dependsOn shadowJar reobf { re shadowJar {} } publishing { publications { mavenJava(MavenPublication) { artifact jar } } repositories { maven { url "file://${project.projectDir}/mcmodsrepo" } } }  
    • All versions of Minecraft Forge suddenly black screen even without mods (tried reinstalling original Minecraft, Java, updating drivers doesn't work)
    • When i join minecraft all ok, when i join world all working fine, but when i open indentity menu, i get this The game crashed whilst unexpected error Error: java.lang.NullPointerException: Cannot invoke "top.ribs.scguns.common.Gun$Projectile.getDamage()" because "this.projectile" is null crash report here https://paste.ee/p/0vKaf
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.