Jump to content

[Solved][1.12.2]How to get a model for a shield


_Cruelar_

Recommended Posts

I'm making a mod which adds a huge amount of shields. My problem is I've no idea how to give them a model like the vanilla shield. I know vanilla uses

"parent": "builtin/entity"

in the shield.json. But as far as I found out that searches for the vanilla shield so when I use it the shield is invisible.

Also vanilla uses ItemModelMesher what modders shouldn't use (Problematic code #2)

So how do I get a model for my custom shield?

My Code:

ModShield(Basecode for most shields):

package com.cruelar.cruelars_triforcemod.init;

import com.cruelar.cruelars_triforcemod.Cruelars_Triforcemod_Core;
import com.cruelar.cruelars_triforcemod.inventory.cruelars_triforcemod;
import net.minecraft.block.BlockDispenser;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.*;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import javax.annotation.Nullable;

public class ModShields extends Item {
    public int damage;

    public ModShields(int maxDamage,String name) {
        damage = maxDamage;
        this.canRepair = true;
        this.isDamageable();
        this.isRepairable();
        this.showDurabilityBar(new ItemStack(this));
        this.setUnlocalizedName(Cruelars_Triforcemod_Core.MODID+"."+name);
        this.setRegistryName(name);
        this.maxStackSize = 1;
        this.setCreativeTab(cruelars_triforcemod.CRUELARS_TRIFORCEMOD_SHIELDS);
        this.setMaxDamage(damage);
        this.addPropertyOverride(new ResourceLocation("blocking"), new IItemPropertyGetter() {
            @SideOnly(Side.CLIENT)
            public float apply(ItemStack p_apply_1_, @Nullable World p_apply_2_, @Nullable EntityLivingBase p_apply_3_) {
                return p_apply_3_ != null && p_apply_3_.isHandActive() && p_apply_3_.getActiveItemStack() == p_apply_1_ ? 1.0F : 0.0F;
            }
        });
        BlockDispenser.DISPENSE_BEHAVIOR_REGISTRY.putObject(this, ItemArmor.DISPENSER_BEHAVIOR);
    }

    public EnumAction getItemUseAction(ItemStack p_getItemUseAction_1_) {
        return EnumAction.BLOCK;
    }

    public int getMaxItemUseDuration(ItemStack p_getMaxItemUseDuration_1_) {
        return 72000;
    }

    public ActionResult<ItemStack> onItemRightClick(World p_onItemRightClick_1_, EntityPlayer p_onItemRightClick_2_, EnumHand p_onItemRightClick_3_) {
        ItemStack lvt_4_1_ = p_onItemRightClick_2_.getHeldItem(p_onItemRightClick_3_);
        p_onItemRightClick_2_.setActiveHand(p_onItemRightClick_3_);
        return new ActionResult(EnumActionResult.SUCCESS, lvt_4_1_);
    }

    public boolean isRepairable(){
        return true;
    }

    public boolean getIsRepairable(ItemStack p_getIsRepairable_1_, ItemStack p_getIsRepairable_2_) {
        return p_getIsRepairable_2_.getItem() == Item.getItemFromBlock(Blocks.PLANKS) ? true : super.getIsRepairable(p_getIsRepairable_1_, p_getIsRepairable_2_);
    }

    public boolean isDamageable(){
        return true;
    }
}

Phantom_Shield(example):

package com.cruelar.cruelars_triforcemod.items;

import com.cruelar.cruelars_triforcemod.init.ModShields;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import java.util.Objects;

public class PhantomShieldPH extends ModShields {
    public PhantomShieldPH() {
        super(1248,"phantom_shield_ph");
    }

    @SideOnly(Side.CLIENT)
    public void initModel(){
        ModelLoader.setCustomModelResourceLocation(this, 0, new ModelResourceLocation(Objects.requireNonNull(getRegistryName()), "inventory"));

    }
}

phantom_shield_ph.json:

{
  "parent":"builtin/entity",
  "display": {
    "thirdperson_righthand": {
      "rotation": [ 0, 90, 0 ],
      "translation": [ 10.51, 6, -4 ],
      "scale": [ 1, 1, 1 ]
    },
    "thirdperson_lefthand": {
      "rotation": [ 0, 90, 0 ],
      "translation": [ 10.51, 6, 12 ],
      "scale": [ 1, 1, 1 ]
    },
    "firstperson_righthand": {
      "rotation": [ 0, 180, 5 ],
      "translation": [ -10, 2, -10 ],
      "scale": [ 1.25, 1.25, 1.25 ]
    },
    "firstperson_lefthand": {
      "rotation": [ 0, 180, 5 ],
      "translation": [ 10, 0, -10 ],
      "scale": [ 1.25, 1.25, 1.25 ]
    },
    "gui": {
      "rotation": [ 15, -25, -5 ],
      "translation": [ 2, 3, 0 ],
      "scale": [ 0.65, 0.65, 0.65 ]
    },
    "fixed": {
      "rotation": [ 0, 180, 0 ],
      "translation": [ -2, 4, -5],
      "scale":[ 0.5, 0.5, 0.5]
    },
    "ground": {
      "rotation": [ 0, 0, 0 ],
      "translation": [ 4, 4, 2],
      "scale":[ 0.25, 0.25, 0.25]
    }
  },
  "overrides": [
    {
      "predicate": {
        "blocking": 1
      },
      "model": "cruelars_triforcemod:item/phantom_shield_ph_blocking"
    }
  ]
}

phantom_shield_ph_blocking.json:

{
  "parent":"builtin/entity",
  "display": {
    "thirdperson_righthand": {
      "rotation": [ 45, 135, 0 ],
      "translation": [ 3.51, 11, -2 ],
      "scale": [ 1, 1, 1 ]
    },
    "thirdperson_lefthand": {
      "rotation": [ 45, 135, 0 ],
      "translation": [ 13.51, 3, 5 ],
      "scale": [ 1, 1, 1 ]
    },
    "firstperson_righthand": {
      "rotation": [ 0, 180, -5 ],
      "translation": [ -15, 5, -11 ],
      "scale": [ 1.25, 1.25, 1.25 ]
    },
    "firstperson_lefthand": {
      "rotation": [ 0, 180, -5 ],
      "translation": [ 5, 5, -11 ],
      "scale": [ 1.25, 1.25, 1.25 ]
    },
    "gui": {
      "rotation": [ 15, -25, -5 ],
      "translation": [ 2, 3, 0 ],
      "scale": [ 0.65, 0.65, 0.65 ]
    }
  }
}

 

I hope this is enough for you to help me, otherwise ask for the missing code.

Edited by _Cruelar_

My Projects:

Cruelars Triforcemod (1.12 release; 1.14 alpha soon coming)

 

Important:

As my mod is on at least 10 different third party sites without my permission, I want to warn you about that with a link to StopModReposts

Link to comment
Share on other sites

6 minutes ago, _Cruelar_ said:

I hope this is enough for you to help me, otherwise ask for the missing code.

The vanilla shield isn't actually rendered in the normal fashion. It is rendered in TileEntityItemStackRenderer. However you can create your own custom model for it however you want, though it may be a pain to acheive the proper positioning.

Edited by Animefan8888

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

Where would I give the model to the Item because

1 minute ago, Animefan8888 said:

It is rendered in TileEntityItemStackRenderer.

I already know. My Problem is more about how to bind an Model to an item

My Projects:

Cruelars Triforcemod (1.12 release; 1.14 alpha soon coming)

 

Important:

As my mod is on at least 10 different third party sites without my permission, I want to warn you about that with a link to StopModReposts

Link to comment
Share on other sites

2 minutes ago, _Cruelar_ said:

I already know. My Problem is more about how to bind an Model to an item

Just how you would any other item...ModelLoader.setCustomModelResourceLocation along with the ModelRegistryEvent.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

So this?

ModelLoader.setCustomModelResourceLocation(this, 0, new ModelResourceLocation(Objects.requireNonNull(getRegistryName()), "inventory"));

Cause then I need something in the Json to give it the actual model. So what goes into the json?

My Projects:

Cruelars Triforcemod (1.12 release; 1.14 alpha soon coming)

 

Important:

As my mod is on at least 10 different third party sites without my permission, I want to warn you about that with a link to StopModReposts

Link to comment
Share on other sites

1 minute ago, _Cruelar_ said:

So what goes into the json?

You will have to define your model yourself. I use cubik studios for my Minecraft modeling.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

So a Model as java file and refer in the Json to it or everything in the json?

Edited by _Cruelar_

My Projects:

Cruelars Triforcemod (1.12 release; 1.14 alpha soon coming)

 

Important:

As my mod is on at least 10 different third party sites without my permission, I want to warn you about that with a link to StopModReposts

Link to comment
Share on other sites

6 minutes ago, _Cruelar_ said:

everything in the json

This, it won't look anything like the Vanilla Shield's json except maybe the translations and rotations. Or you could try to give your item a custom TileEntityItemStackRenderer by calling setTileEntityItemStackRenderer in your items constructor.

  • Thanks 1

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

Just now, Animefan8888 said:

you could try to give your item a custom TileEntityItemStackRenderer by calling setTileEntityItemStackRenderer in your items constructor.

I'll try that cause that sounds simpler to me (I've always problems with json) but if it fails I'll try Cubik Studio sounds very useful.

My Projects:

Cruelars Triforcemod (1.12 release; 1.14 alpha soon coming)

 

Important:

As my mod is on at least 10 different third party sites without my permission, I want to warn you about that with a link to StopModReposts

Link to comment
Share on other sites

1 hour ago, _Cruelar_ said:

It works ?

 

 

BlockBench is also a good modeling tool, though it doesn’t often get the texture paths right due to it thinking every texture is a vanilla one. It also has a display tab that lets you edit the model transforms. I rate it about 8/10 give a try!

you can also do a lot with custom model loaders, having half your stuff in json and the other half in code

  • Thanks 1

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

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



×
×
  • Create New...

Important Information

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