Jump to content

Problem creating custom sign type


jhonny97

Recommended Posts

Hi,

in my mod in Minecraft 1.15.2, i added a new type of wood and i want to create the sign for it, but when i place down the block, it has no texture and the GUI don't open.

 

I'm missing something that i don't know?

 

Here is the TileEntityClass

public class JapaneseCherrySignTileEntity extends SignTileEntity {
    public JapaneseCherrySignTileEntity() {
        super();
    }

    @Override
    public TileEntityType<?> getType() {
        return TileEntityInit.INSTANCE.getJapCherrySignTileEntity();
    }
}

 

The Block initialization

public class BlockInit {
    public static final DeferredRegister<Block> blocks = DeferredRegister.create(ForgeRegistries.BLOCKS, MoreStuffMod.MODID);
    public static final RegistryObject<Block> japCherrySign = blocks.register("jap_cherry_sign", () -> new JapaneseCherrySignBlock(Block.Properties.create(Material.WOOD).doesNotBlockMovement().hardnessAndResistance(1.0F).sound(SoundType.WOOD), null));
}

 

The tile entities initialization

public class TileEntityInit {
    public static final DeferredRegister<TileEntityType<?>> tileEntities = DeferredRegister.create(ForgeRegistries.TILE_ENTITIES, MoreStuffMod.MODID);

    public static final RegistryObject<TileEntityType<JapaneseCherrySignTileEntity>> japCherrySignTileEntity = tileEntities.register("jap_cherry_sign", () -> TileEntityType.Builder.create(JapaneseCherrySignTileEntity::new, BlockInit.japCherrySign.get()).build(null));
}

And the TileEntityRenderer

@OnlyIn(Dist.CLIENT)
public class JapaneseCherrySignTileEntityRenderer extends SignTileEntityRenderer {
    private final SignTileEntityRenderer.SignModel model = new SignTileEntityRenderer.SignModel();

    public JapaneseCherrySignTileEntityRenderer(TileEntityRendererDispatcher rendererDispatcherIn) {
        super(rendererDispatcherIn);
    }

    @Override
    public void render(SignTileEntity tileEntityIn, float partialTicks, MatrixStack matrixStackIn, IRenderTypeBuffer bufferIn, int combinedLightIn, int combinedOverlayIn) {
        BlockState blockstate = tileEntityIn.getBlockState();
        matrixStackIn.push();
        float f = 0.6666667F;
        if (blockstate.getBlock() instanceof StandingSignBlock) {
            matrixStackIn.translate(0.5D, 0.5D, 0.5D);
            float f1 = -((float)(blockstate.get(StandingSignBlock.ROTATION) * 360) / 16.0F);
            matrixStackIn.rotate(Vector3f.YP.rotationDegrees(f1));
            this.model.signStick.showModel = true;
        } else {
            matrixStackIn.translate(0.5D, 0.5D, 0.5D);
            float f4 = -blockstate.get(WallSignBlock.FACING).getHorizontalAngle();
            matrixStackIn.rotate(Vector3f.YP.rotationDegrees(f4));
            matrixStackIn.translate(0.0D, -0.3125D, -0.4375D);
            this.model.signStick.showModel = false;
        }

        matrixStackIn.push();
        matrixStackIn.scale(0.6666667F, -0.6666667F, -0.6666667F);
        RenderMaterial rendermaterial = getMaterial(blockstate.getBlock());
        IVertexBuilder ivertexbuilder = rendermaterial.getBuffer(bufferIn, this.model::getRenderType);
        this.model.signBoard.render(matrixStackIn, ivertexbuilder, combinedLightIn, combinedOverlayIn);
        this.model.signStick.render(matrixStackIn, ivertexbuilder, combinedLightIn, combinedOverlayIn);
        matrixStackIn.pop();
        FontRenderer fontrenderer = this.renderDispatcher.getFontRenderer();
        float f2 = 0.010416667F;
        matrixStackIn.translate(0.0D, (double)0.33333334F, (double)0.046666667F);
        matrixStackIn.scale(0.010416667F, -0.010416667F, 0.010416667F);
        int i = tileEntityIn.getTextColor().getTextColor();
        double d0 = 0.4D;
        int j = (int)((double) NativeImage.getRed(i) * 0.4D);
        int k = (int)((double)NativeImage.getGreen(i) * 0.4D);
        int l = (int)((double)NativeImage.getBlue(i) * 0.4D);
        int i1 = NativeImage.getCombined(0, l, k, j);
        int j1 = 20;

        for(int k1 = 0; k1 < 4; ++k1) {
            ITextProperties itextproperties = tileEntityIn.func_235677_a_(k1, (p_239309_1_) -> {
                List<ITextProperties> list = fontrenderer.func_238420_b_().func_238362_b_(p_239309_1_, 90, Style.EMPTY);
                return list.isEmpty() ? ITextProperties.field_240651_c_ : list.get(0);
            });
            if (itextproperties != null) {
                float f3 = (float)(-fontrenderer.func_238414_a_(itextproperties) / 2);
                fontrenderer.func_238416_a_(itextproperties, f3, (float)(k1 * 10 - 20), i1, false, matrixStackIn.getLast().getMatrix(), bufferIn, false, 0, combinedLightIn);
            }
        }

        matrixStackIn.pop();
    }

    public static RenderMaterial getMaterial(Block blockIn) {
        return new RenderMaterial(Atlases.SIGN_ATLAS, new ResourceLocation(MoreStuffMod.MODID, "textures/entity/signs/jap_cherry.png"));
    }
}

 

And the setup event

private void setup(final FMLCommonSetupEvent event)
{
	ClientRegistry.bindTileEntityRenderer(TileEntityInit.japCherrySignTileEntity.get(), JapaneseCherrySignTileEntityRenderer::new);
}

 

 

2020-08-19_00.16.43.jpg

Edited by jhonny97
Link to comment
Share on other sites

Besides the abysmal programming + copy-paste, it's probably because your texture doesn't exist in the specified Atlas location. I believe it even tells you that in the stacktrace/log when it tries to find it. Read over it again and fix. If you're lucky with this very cutout code, you won't even need to use TextureStitchEvent$Pre.

Link to comment
Share on other sites

1 hour ago, ChampionAsh5357 said:

Besides the abysmal programming + copy-paste, it's probably because your texture doesn't exist in the specified Atlas location. I believe it even tells you that in the stacktrace/log when it tries to find it. Read over it again and fix. If you're lucky with this very cutout code, you won't even need to use TextureStitchEvent$Pre.

I copy-pasted the renderer from the original sign renderer, because afaik I cannot instantiate a new woodtype, that has a protected constructor. So i overrided the getRenderMaterial to find my texture and there isn't a error in the log.

How can I add that texture to the Atlas? There are some resources where I can learn this type of things about rendering and so on?

Edited by jhonny97
Link to comment
Share on other sites

16 hours ago, jhonny97 said:

How can I add that texture to the Atlas?

 

18 hours ago, ChampionAsh5357 said:

TextureStitchEvent$Pre

From there, you can figure it out.

16 hours ago, jhonny97 said:

There are some resources where I can learn this type of things about rendering and so on?

Learn 3d dimensional rotation, translation, and scaling based around a specific point. From there, take a look at how stacks work. For mc in particular, take a look at how they compress textures into an atlas (the sign type points to a location holding the sign textures). Now you have a decent understanding on how rendering works without understanding the complications of rendering types, culling, raytracing, overlays, etc. You probably won't need to know this anyways, but its always helpful.

Link to comment
Share on other sites

On 8/20/2020 at 1:50 AM, ChampionAsh5357 said:

 

From there, you can figure it out.

Learn 3d dimensional rotation, translation, and scaling based around a specific point. From there, take a look at how stacks work. For mc in particular, take a look at how they compress textures into an atlas (the sign type points to a location holding the sign textures). Now you have a decent understanding on how rendering works without understanding the complications of rendering types, culling, raytracing, overlays, etc. You probably won't need to know this anyways, but its always helpful.

Ok thanks, i resolved using only using a custom Renderer for the sign and adding the sprite to the atlas and it works. the only problem is the EditSignScreen that show the default Oak WoodType instead of my texture because the screen, call "SignTileEntity.getMaterial" that search for the texture in the minecraft namespace and not my mod namespace. I tried creating a new EditSignScreen, but unfortunately when i try to display the screen, Minecraft crash without error. I checked the original call to display the gui and is done Server side, maybe there is some sort of synchronization between server and client that i have to implement myself.

Link to comment
Share on other sites

  • 1 month later...
On 8/21/2020 at 4:17 AM, jhonny97 said:

Ok thanks, i resolved using only using a custom Renderer for the sign and adding the sprite to the atlas and it works. the only problem is the EditSignScreen that show the default Oak WoodType instead of my texture because the screen, call "SignTileEntity.getMaterial" that search for the texture in the minecraft namespace and not my mod namespace. I tried creating a new EditSignScreen, but unfortunately when i try to display the screen, Minecraft crash without error. I checked the original call to display the gui and is done Server side, maybe there is some sort of synchronization between server and client that i have to implement myself.

 

How did you add to the sign atlas? I'm experiencing the same issue. 

Link to comment
Share on other sites

21 hours ago, jhonny97 said:

You have to add sprite in TextureStitchEvent.Pre Event

Like this?

@Mod.EventBusSubscriber(modid = BiomeEnhancements.MOD_ID, value = Dist.CLIENT, bus = Mod.EventBusSubscriber.Bus.MOD)
public class ModSignTextureStitch {

	public static final ResourceLocation BAOBAB = new ResourceLocation(BiomeEnhancements.MOD_ID, "entity/signs/baobab");
	public static final ResourceLocation MANGROVE = new ResourceLocation(BiomeEnhancements.MOD_ID, "entity/signs/mangrove");
	public static final ResourceLocation PALM = new ResourceLocation(BiomeEnhancements.MOD_ID, "entity/signs/palm");
	
	@SubscribeEvent
    public static void onStitchEvent(TextureStitchEvent.Pre event)
    {
		ResourceLocation stitching = event.getMap().getTextureLocation();
        if(!stitching.equals(Atlases.SIGN_ATLAS))
        {
            return;
        }
        
        boolean added = event.addSprite(BAOBAB);
        added = event.addSprite(MANGROVE);
        added = event.addSprite(PALM);
     
    }

}

 

The signs have texture, but when you "type" in them the visual is the missing texture thing. Here's how I load the textures in the sign renderer. 

 public static Material getMaterial(Block blockIn) {
	 	      WoodType woodtype;
	 	      if (blockIn instanceof AbstractSignBlock) {
	 	         woodtype = ((AbstractSignBlock)blockIn).getWoodType();
	 	      } else {
	 	         woodtype = WoodType.OAK;
	 	      }
	 	      
	 	      return getSignMaterial(woodtype);
	 	   }

	 	   public static Material getSignMaterial(WoodType woodtype) {
	 	      return new Material(Atlases.SIGN_ATLAS, new ResourceLocation(BiomeEnhancements.MOD_ID, "entity/signs/" + woodtype.getName()));
	 	   }
}

 

Edited by killerjdog51
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.