Jump to content

[1.12.2] Custom TEISR question


Toma™

Recommended Posts

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. 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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());
	}
}

 

 

Link to comment
Share on other sites

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.

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.