Jump to content

Change vanilla item model based off of name/lore


Miclebrick

Recommended Posts

I'm trying to make a mod that changes vanilla item model based off of its name or lore. But before I get to that, I'm trying to get it to even change the model in the first place! Nothing seems to happen. Am I missing anything?

 

Main mod file:

http://pastebin.com/KKhrD2bC

 

CustomItemModel:

http://pastebin.com/sEXEffZ9

 

TestDiamondSwordModel:

http://pastebin.com/hbjSJsaN

Link to comment
Share on other sites

Make a class that implements

ICustomModelLoader

. In

accepts

return true if it is the RL for your Item. In loadModel return a new IModel. In the IModel:

bake

: return a new instance of your ISmartItemModel.

getDependencies

/

getTextures

: Return ImmutableList.of() (the empty list).

getDefaultState

: Return TRSRTransformation.identiy.

 

Then register your loader using

ModelLoaderRegistry.registerLoader

in preInit. You now no longer need the bake event handler.

The difference for you is that you have a texture to return and you will probably be using IBakedModle instead of ISmartItemModel

Current Project: Armerger 

Planned mods: Light Drafter  | Ore Swords

Looking for help getting a mod off the ground? Coding  | Textures

Link to comment
Share on other sites

I haven't done that myself but minecrafts model loader also implements ICustomModelLoader so if you look around through that you should be able to see how they do it.

 

In case you don't know:

right click -> the 3 opens are a great way to trace through classes and method calls.

 

Current Project: Armerger 

Planned mods: Light Drafter  | Ore Swords

Looking for help getting a mod off the ground? Coding  | Textures

Link to comment
Share on other sites

I discovered in ItemModelMesher:

 

public IBakedModel getItemModel(ItemStack stack)

    {

        Item item = stack.getItem();

        IBakedModel ibakedmodel = this.getItemModel(item, this.getMetadata(stack));

 

        if (ibakedmodel == null)

        {

            ItemMeshDefinition itemmeshdefinition = (ItemMeshDefinition)this.shapers.get(item);

 

            if (itemmeshdefinition != null)

            {

                ibakedmodel = this.modelManager.getModel(itemmeshdefinition.getModelLocation(stack));

            }

        }

 

        if (ibakedmodel == null)

        {

            ibakedmodel = this.modelManager.getMissingModel();

        }

 

        return ibakedmodel;

    }

 

Does that mean that it's only called for nonexistent meshes? (It checks if baked mesh is null first)

Link to comment
Share on other sites

@SuppressWarnings("unchecked")

private void removeItemFromMesher(Item item, int meta) {

try {

Field field1 = ItemModelMesher.class.getDeclaredField("simpleShapesCache");

field1.setAccessible(true);

Map<Integer, IBakedModel> simpleShapesCache = (Map<Integer, IBakedModel>) field1.get(getMesher());

simpleShapesCache.remove(getIndex(item, meta));

field1.set(getMesher(), simpleShapesCache);

Field field2 = ItemModelMesher.class.getDeclaredField("simpleShapes");

field2.setAccessible(true);

Map<Integer, ModelResourceLocation> simpleShapes = (Map<Integer, ModelResourceLocation>) field2.get(getMesher());

simpleShapes.remove(getIndex(item, meta));

field2.set(getMesher(), simpleShapes);

} catch (NoSuchFieldException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (SecurityException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (IllegalArgumentException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (IllegalAccessException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

 

 

I tried doing this on postinit, but it did nothing.

Link to comment
Share on other sites

I GOT IT TO WORK WITH ICUSTOMMODELLOADER! :D

 

It now looks like a potato unless it is named Apple, in which case it looks like an apple. It works as expected :)

 

My new code: http://pastebin.com/bQAWSUVx

 

Now that I know how, I can use that same concept to make an actual system for it. (Code is very hacky, so anyone reading this shouldn't copy and paste ;))

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • They were already updated, and just to double check I even did a cleanup and fresh update from that same page. I'm quite sure drivers are not the problem here. 
    • i tried downloading the drivers but it says no AMD graphics hardware has been detected    
    • Update your AMD/ATI drivers - get the drivers from their website - do not update via system  
    • As the title says i keep on crashing on forge 1.20.1 even without any mods downloaded, i have the latest drivers (nvidia) and vanilla minecraft works perfectly fine for me logs: https://pastebin.com/5UR01yG9
    • Hello everyone, I'm making this post to seek help for my modded block, It's a special block called FrozenBlock supposed to take the place of an old block, then after a set amount of ticks, it's supposed to revert its Block State, Entity, data... to the old block like this :  The problem I have is that the system breaks when handling multi blocks (I tried some fix but none of them worked) :  The bug I have identified is that the function "setOldBlockFields" in the item's "setFrozenBlock" function gets called once for the 1st block of multiblock getting frozen (as it should), but gets called a second time BEFORE creating the first FrozenBlock with the data of the 1st block, hence giving the same data to the two FrozenBlock :   Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=head] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@73681674 BlockEntityData : id:"minecraft:bed",x:3,y:-60,z:-6} Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=3, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=2, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} here is the code inside my custom "freeze" item :    @Override     public @NotNull InteractionResult useOn(@NotNull UseOnContext pContext) {         if (!pContext.getLevel().isClientSide() && pContext.getHand() == InteractionHand.MAIN_HAND) {             BlockPos blockPos = pContext.getClickedPos();             BlockPos secondBlockPos = getMultiblockPos(blockPos, pContext.getLevel().getBlockState(blockPos));             if (secondBlockPos != null) {                 createFrozenBlock(pContext, secondBlockPos);             }             createFrozenBlock(pContext, blockPos);             return InteractionResult.SUCCESS;         }         return super.useOn(pContext);     }     public static void createFrozenBlock(UseOnContext pContext, BlockPos blockPos) {         BlockState oldState = pContext.getLevel().getBlockState(blockPos);         BlockEntity oldBlockEntity = oldState.hasBlockEntity() ? pContext.getLevel().getBlockEntity(blockPos) : null;         CompoundTag oldBlockEntityData = oldState.hasBlockEntity() ? oldBlockEntity.serializeNBT() : null;         if (oldBlockEntity != null) {             pContext.getLevel().removeBlockEntity(blockPos);         }         BlockState FrozenBlock = setFrozenBlock(oldState, oldBlockEntity, oldBlockEntityData);         pContext.getLevel().setBlockAndUpdate(blockPos, FrozenBlock);     }     public static BlockState setFrozenBlock(BlockState blockState, @Nullable BlockEntity blockEntity, @Nullable CompoundTag blockEntityData) {         BlockState FrozenBlock = BlockRegister.FROZEN_BLOCK.get().defaultBlockState();         ((FrozenBlock) FrozenBlock.getBlock()).setOldBlockFields(blockState, blockEntity, blockEntityData);         return FrozenBlock;     }  
  • Topics

×
×
  • Create New...

Important Information

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