Posted November 3, 20186 yr I want to use the TileEntityItemStackRenderer for my weapons to use java models etc so I decided to go through the Forge docs. I'm confused a bit by it because I tried to follow it but I can't understand few things: 1) Is my implementation correct? (Atleast a bit?) 2) Do I need to implement the baked model on the item as I do or different way? 3) From my understanding I don't need anything else than setTileEntityItemStackRenderer, isBuiltinRenderer and getOverrides methods? There is what I have tried for now: Spoiler public class PistolP92 extends GunBase implements IBakedModel { public PistolP92(String name) { super(name); this.setMaxStackSize(1); this.setCreativeTab(Main.pmcgunstab); this.setDamage(ConfigHandler.p92); this.setVelocity(7); this.setGravityModifier(0.015); this.setGravityStartTime(5); this.setFireRate(6); this.setMaxAmmo(15); this.setReloadTime(50); this.canSwitchMode(false); this.setVerticalRecoil(2.0f); this.setHorizontalRecoil(0.5f); this.setAmmoType(AmmoType.AMMO9MM); this.setFiremode(Firemode.SINGLE); this.setReloadType(ReloadType.MAGAZINE); this.setGunType(GunType.PISTOL); this.setGunSound(PMCSounds.gun_p92); this.setGunSoundVolume(5f); this.setGunSilencedSound(PMCSounds.gun_p92_silenced); this.setGunSilencedSoundVolume(getGunVolume() * 0.4f); this.setMaxDamage(this.getMaxAmmo()); } //============================= @Override public boolean isBuiltInRenderer() { return true; } //This is propably problem @Override public ItemOverrideList getOverrides() { return null; } @Override public TextureAtlasSprite getParticleTexture() { return null; } @Override public List<BakedQuad> getQuads(IBlockState state, EnumFacing side, long rand) { return null; } @Override public boolean isAmbientOcclusion() { return false; } @Override public boolean isGui3d() { return false; } //============================== @Override public void setTileEntityItemStackRenderer(TileEntityItemStackRenderer teisr) { teisr = new WeaponTeisr(); } public class WeaponTeisr extends TileEntityItemStackRenderer { private final ModelShield modelShield = new ModelShield(); @Override public void renderByItem(ItemStack itemStackIn, float ticks) { if(itemStackIn.getItem() == PMCItems.P92) { this.modelShield.render(); } } } } Also I decided to use the vanilla shield model for it now since I don't have the model yet. The TEISR class is copied from vanilla. The code doesn't crash or anything like that, it doesn't do anything at all. Maybe that's because the ItemOverrideList is null.
November 3, 20186 yr 45 minutes ago, Toma™ said: public class PistolP92 extends GunBase implements IBakedModel Why is your Item an instance of IBakedModel? That makes no sense. First of all IBakedModel is client-only while items are common, this will crash the server. Second of all items are not models. 46 minutes ago, Toma™ said: public ItemOverrideList getOverrides() { return null; } You can't return null here, you need to return ItemOverrideList.NONE. 46 minutes ago, Toma™ said: @Override public TextureAtlasSprite getParticleTexture() { return null; } You can't return null here, you need to return a particle texture of some kind. At least a TextureMap#getMissingSprite. 47 minutes ago, Toma™ said: @Override public List<BakedQuad> getQuads(IBlockState state, EnumFacing side, long rand) { return null; } You can't return null here, return a Collections.EMPTY_LIST. 48 minutes ago, Toma™ said: @Override public void setTileEntityItemStackRenderer(TileEntityItemStackRenderer teisr) { teisr = new WeaponTeisr(); } Well, good job. For whatever reason you've overridden the setter for a TEISR. It used to set the TEISR of the item to the one passed as it's parameter. Now it sets the local teisr variable to a new WeaponTeisr. Which gets discarded immediately because that's not how java works. And even if it somehow worked this way you are not even calling this method from anywhere. And you have also provided no code responsible for registering the item's model. You need to do that too.
November 3, 20186 yr Author Okay so I have reworked it a bit the teisr is now at the item, however nothing is rendering except my normal item model. I'm pretty sure that is because the ItemOverrideList is empty. I created my own model class which extends the Shield model and implements the baked model. I'm new to all this stuff so I might be making some terrible mistake somewhere... So there's the updated code: The item class: Spoiler public class PistolP92 extends GunBase { public PistolP92(String name) { super(name); this.setMaxStackSize(1); this.setCreativeTab(Main.pmcgunstab); this.setDamage(ConfigHandler.p92); this.setVelocity(7); this.setGravityModifier(0.015); this.setGravityStartTime(5); this.setFireRate(6); this.setMaxAmmo(15); this.setReloadTime(50); this.canSwitchMode(false); this.setVerticalRecoil(2.0f); this.setHorizontalRecoil(0.5f); this.setAmmoType(AmmoType.AMMO9MM); this.setFiremode(Firemode.SINGLE); this.setReloadType(ReloadType.MAGAZINE); this.setGunType(GunType.PISTOL); this.setGunSound(PMCSounds.gun_p92); this.setGunSoundVolume(5f); this.setGunSilencedSound(PMCSounds.gun_p92_silenced); this.setGunSilencedSoundVolume(getGunVolume() * 0.4f); this.setMaxDamage(this.getMaxAmmo()); this.setTileEntityItemStackRenderer(new WeaponTeisr()); } public class WeaponTeisr extends TileEntityItemStackRenderer { private final ModelP92 model = new ModelP92(); @Override public void renderByItem(ItemStack itemStackIn) { if(itemStackIn.getItem() == PMCItems.P92) { this.model.render(); } } } } The model class: Spoiler package com.toma.pubgmc.render.model; import java.util.Collections; import java.util.List; import net.minecraft.block.state.IBlockState; import net.minecraft.client.Minecraft; import net.minecraft.client.model.ModelShield; import net.minecraft.client.renderer.block.model.BakedQuad; import net.minecraft.client.renderer.block.model.IBakedModel; import net.minecraft.client.renderer.block.model.ItemOverrideList; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.client.renderer.texture.TextureMap; import net.minecraft.util.EnumFacing; public class ModelP92 extends ModelShield implements IBakedModel { @Override public ItemOverrideList getOverrides() { return ItemOverrideList.NONE; } @Override public TextureAtlasSprite getParticleTexture() { TextureMap map = Minecraft.getMinecraft().getTextureMapBlocks(); return map.getMissingSprite(); } @Override public List<BakedQuad> getQuads(IBlockState state, EnumFacing side, long rand) { return Collections.EMPTY_LIST; } @Override public boolean isAmbientOcclusion() { // TODO Auto-generated method stub return false; } @Override public boolean isBuiltInRenderer() { // TODO Auto-generated method stub return true; } @Override public boolean isGui3d() { // TODO Auto-generated method stub return false; } } And also you wanted the registry code (I don't know if I need to rewrite it, but most likely I will have to since a lot of the code is old and I was following some registry tutorials for this) Spoiler @EventBusSubscriber public class RegistryHandler { @SubscribeEvent public static void onItemRegister(RegistryEvent.Register<Item> event) { event.getRegistry().registerAll(PMCItems.ITEMS.toArray(new Item[0])); } @SubscribeEvent public static void onBlockRegister(RegistryEvent.Register<Block> event) { event.getRegistry().registerAll(PMCBlocks.BLOCKS.toArray(new Block[0])); } @SubscribeEvent public static void onModelRegister(ModelRegistryEvent event) { for(Item item : PMCItems.ITEMS) { if(item instanceof IModItem) { ((IModItem)item).registerModels(); } } for(Block block : PMCBlocks.BLOCKS) { if(block instanceof IModItem) { ((IModItem)block).registerModels(); } } } public static void serverRegistries(FMLServerStartingEvent event) { event.registerServerCommand(new Leavecmd()); event.registerServerCommand(new GenerateLootcmd()); event.registerServerCommand(new CommandClearPlayerCrates()); } }
November 3, 20186 yr 5 minutes ago, Toma™ said: public class ModelP92 extends ModelShield implements IBakedModel This makes no sense. ModelShield is a BipedModel which has nothing to do with baked models. You don't even need to extend ModelShield here at all. 6 minutes ago, Toma™ said: I'm pretty sure that is because the ItemOverrideList is empty. First of all the ItemOverrideList has nothing to do with a TEISR. Second of all most models have empty ItemOverrideLists and work just fine. 7 minutes ago, Toma™ said: this.setTileEntityItemStackRenderer(new WeaponTeisr()); You can't do this in the item's constructor because this method is client-side only. It will crash the server. 8 minutes ago, Toma™ said: also you wanted the registry code No I didn't. 52 minutes ago, V0idWa1k3r said: you have also provided no code responsible for registering the item's model. You need to do that too. I told you that you need to register your IBakedModel as the item's new model using either a custom ICustomModelLoader implementation or a ModelBakeEvent. But now when I see your registry... 9 minutes ago, Toma™ said: event.getRegistry().registerAll(PMCItems.ITEMS.toArray(new Item[0])); Don't ever use static initializers. Instantinate your things directly in the registry event. 10 minutes ago, Toma™ said: if(item instanceof IModItem) { ((IModItem)item).registerModels(); } IHasModel is stupid and yes, this is a renamed IHasModel. All items need models, no exception and nothing about model registration requires access to private/protected data of the item. Register your models in the ModelRegistryEvent directly.
November 3, 20186 yr Author Okay, thanks for your time, I see I have lot of pretty stupid code here. One last question regarding setting the teisr. When or where am I supposed to set it?
November 3, 20186 yr 3 minutes ago, Toma™ said: One last question regarding setting the teisr. When or where am I supposed to set it? In your client proxy/client only class after the item has been initialized.
November 3, 20186 yr Author Just now, V0idWa1k3r said: In your client proxy/client only class after the item has been initialized. Alright, thanks a lot
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.