Jump to content

Recommended Posts

Posted (edited)

Hello !

I am creating a custom flower for my mod, and I've encountered an issue. When rendering it, it seems to be rendered as a full block, whereas I'd like it to render as a flower.

I've attached a picture showing how it looks like in the game and one that show the texture file, and the code is available below the message.

Because it is rendering black faces, I sought and found out about a "isOpaqueBlock" method, yet I can't find it anywhere in the code and using the annotation @Override shows that no such method can be found is super-classes. My class extends FlowerBlock which extends BushBlock which extends Block, so I would assume I should encounter the method somewhere, but it is yet to be found.

Also, I think the problem has a second part. The block is on a proper location (has a slight offset), I set the noCollision and stuff, but I can't seem to make it small enough, and use the texture accordingly. By that, I mean not use the texture on every face but the same way a flower does. I tried creating different types of blocks, I sought everywhere for rendering explanations but tutorials are 7 to 8 years old and looks nothing like today's modding.

I've been stuck on this for a few days now and I'm quite new to modding, so please be kind :)

 

Code :

package net.Nephty.rgbee.data.blocks;

import net.Nephty.rgbee.setup.ModItems;
import net.minecraft.block.BlockState;
import net.minecraft.block.FlowerBlock;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.potion.Effect;
import net.minecraft.util.ActionResultType;
import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.world.World;

public class CustomFlower extends FlowerBlock {
    public CustomFlower(Effect p_i49984_1_, int p_i49984_2_, Properties p_i49984_3_) {
        super(p_i49984_1_, p_i49984_2_, p_i49984_3_);
    }

    @SuppressWarnings("deprecation")
    @Override
    public ActionResultType use(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockRayTraceResult rayTrace) {
        if (world.isClientSide) {
            return ActionResultType.SUCCESS;
        }
        super.use(state, world, pos, player, hand, rayTrace);
        if (player.isHolding(Items.GLASS_BOTTLE)) {
            // if the player has a free slot
            if (player.inventory.getFreeSlot() != -1) {
                // remove 1 glass bottle and add 1 liquid pollen
                player.inventory.removeItem(player.inventory.selected, 1);
                player.inventory.add(new ItemStack(ModItems.LIQUID_POLLEN::get));
            } else {
                // no free slot, remove 1 glass bottle and drop the item on the ground
                player.inventory.removeItem(player.inventory.selected, 1);
                popResource(world, pos, new ItemStack(ModItems.LIQUID_POLLEN::get));
            }
            return ActionResultType.SUCCESS;
        }
        return ActionResultType.PASS;
    }

    /*
    Tried this, but doesn't help :

    @Override
    public boolean isOpaqueBlock() { return false; }
     */
}

 

Capture.PNG

Capture.PNG

Edited by Nephty
Posted (edited)
1 hour ago, Nephty said:

I sought and found out about a "isOpaqueBlock" method, yet I can't find it anywhere

These sorts of properties are now part of the AbstractBlock.Properties object that you pass to the Block constructor. The methods you're probably interested in are noOcclusion and noCollission. The Material of the Properties is also relevant here, since they have the nonSolid building method.

The reason your flower is rendered on the outside of a cube is that its model defines that to be the case. You should look at the model file of a block with the relevant model to determine how to change this. models/block/dead_bush.json, for example, uses the parent block/cross, which I think is what you're after.

Edited by SerpentDagger
Typo
  • Thanks 1

Fancy 3D Graphing Calculator mod, with many different coordinate systems.

Lightweight 3D/2D position/vector transformations library, also with support for different coordinate systems.

Posted
Quote

These sorts of properties are now part of the AbstractBlock.Properties object that you pass to the Block constructor. The methods you're probably interested in are noOcclusion and noCollission.

I have found the methods noOcclusion and noCollision when looking at the source code, which was really helpful.

Quote

The Material of the Properties is also relevant here, since they have the nonSolid building method.

What Material could I reference here ? I tried Plant, Decoration, Bamboo Sapling, Grass and Coral but the final result is always the same : the flower looks like what's shown in the picture. In the source code, a Poppy is created using Properties.of(Material.PLANT), so I guessed I'd go with that too.

Quote

The reason your flower is rendered on the outside of a cube is that its model defines that to be the case. You should look at the model file of a block with the relevant model to determine how to change this. models/block/dead_bush.json, for example, uses the parent block/cross, which I think is what you're after.

How can I access this json file ? And what can I do to modify the BlockState of my flower ? I found a json file in a ressource pack that has the parent block/cross, but I don't really know how to apply this to my flower.

Thank you for the reply !

Posted
8 minutes ago, Nephty said:

What Material could I reference here ? I tried Plant, Decoration, Bamboo Sapling, Grass and Coral but the final result is always the same : the flower looks like what's shown in the picture. In the source code, a Poppy is created using Properties.of(Material.PLANT), so I guessed I'd go with that too.

The Material specifies generic properties like whether or not the block can be collided with, how it interacts with pistons, whether it burns, etc. It won't solve your rendering problem, but will dictate some other relevant behaviors. Using the settings of PLANT is probably exactly what you want in this regard.

7 minutes ago, Nephty said:

How can I access this json file ? And what can I do to modify the BlockState of my flower ? I found a json file in a ressource pack that has the parent block/cross, but I don't really know how to apply this to my flower.

In .minecraft/versions/[version_folder] there is a jar file, which you can extract somewhere convenient. In this extracted folder, there is an assets/minecraft folder, which contains the Minecraft assets which you can use as reference.

BlockState describes a combination of IProperty<?>s. Your Block's blockstate file maps these combinations to a number of model files to use for each one. You don't need to alter the BlockState of your flower to change its default model, but if you want to add different models for different combinations of IProperty<?>s, you would do so with BlockStates. Here is a link to how one interacts with BlockStates in code. Here is a link to documentation on writing a blockstate file.

What you're looking for to change the default model of the block is the model file, not the blockstate file. A model file defines the elements and textures of a model in the world. Alternatively, the model file can reference a different model file that is already defined (the "parent" model), and simply alter the textures of that parent model. This is what the line "parent": "block/cross" does. It defines the parent model as being the one named cross in the folder block. To make your flower render with a cross model, then, you would use its model file to define its parent to be block/cross, and then alter the textures tag to use your own flower texture.

textures is a tag containing a number of String variables, whose names should correspond to the parent model's definitions. The cross model has only one textures variable, which is named cross.

  • Thanks 1

Fancy 3D Graphing Calculator mod, with many different coordinate systems.

Lightweight 3D/2D position/vector transformations library, also with support for different coordinate systems.

Posted
25 minutes ago, SerpentDagger said:

To make your flower render with a cross model, then, you would use its model file to define its parent to be block/cross, and then alter the textures tag to use your own flower texture.

I guess this is something I must modify in the json file ? I changed it by hand but I don't know how to make it automatic. I use the simpleBlock() method to create a block and I would assume this is what changes the parent.

I've realized that no json file is being created when executing task runData or runClient. The thing is, I'm creating another block and it's "itemized" version, and everything works fine. I copied every single step for the flower, and yet it doesn't have any json file.

I edited a few json files located in : assets\mod\blockstates and in : assets\mod\models and it seeems to do something. I know have a proper cross rendering, but the texture is still the purple and black squares one. It seems like it doesn't find the texture file.

I am thinking that modifying the files by hand is not the best method. I wonder if executing the task runData will overwrite the previous file ? Or if the data is in any danger of potential erasure ?  As an example, I said previously that I use the simpleBlock() method and that I think this is what tells the game to create a full block. If I runData, will it overwrite the parent and replace it with a full block again ?

Sorry for the messy response, I tried to make it as clear as possible and I am very new to the modding area.

Posted

Small update about this topic : whenever I change the string referring to the texture in the json file located in generated\resources\assets\mod\blockstates, there are three scenarios :

1. I use a texture located in the items folder instead of the blocks folder : the rendered block becomes a flat image, as if you simply put the item from your hand on the ground. Not a cross texture, neither a full block.
2. I use the correct texture in the blocks folder : the rendered block is a cross block but the texture is the "missing texture" one, purple and black squares.
3. I use the name of a texture that doesn't exite : the rendered block is a full block with the missing texture.

Posted
10 hours ago, Nephty said:

I wonder if executing the task runData will overwrite the previous file ? Or if the data is in any danger of potential erasure ?  As an example, I said previously that I use the simpleBlock() method and that I think this is what tells the game to create a full block. If I runData, will it overwrite the parent and replace it with a full block again ?

runData has an output folder that is specified by the build.gradle file. I think the default is src/generated. It will overwrite files that it's previously put there. The idea, I think, is that you move the files you need from the generated folder into your main resources folder, but the problem I found there is that the build.gradle file by default allows assets to be kept in the src/generated folder, and will look for them there, which causes weird conflicts if you don't delete everything from the generated folder and refresh the IDE. That's not very convenient, so I changed my build.gradle to ignore the assets in src/generated.

3 hours ago, Nephty said:

the string referring to the texture in the json file located in generated\resources\assets\mod\blockstates

These strings do not refer to textures, they refer to models, as I mentioned in my previous post. BlockState → Model → Shape & Texture.

3 hours ago, Nephty said:

1. I use a texture located in the items folder instead of the blocks folder : the rendered block becomes a flat image, as if you simply put the item from your hand on the ground. Not a cross texture, neither a full block.

Because of the previous point, you are referencing the item model, which is a flat image that generally appears in the hand. The texture reference in the item model is defined correctly.

3 hours ago, Nephty said:

2. I use the correct texture in the blocks folder : the rendered block is a cross block but the texture is the "missing texture" one, purple and black squares.

Again, this is the block model, not the texture. The model is found correctly, and the parent is defined correctly, resulting in the correct shape, but the texture is not found. There should be an error message in the console window that tells you more information about the problem. These error messages tend to be quite helpful, so do look for it. It's probably a typo in the model json, a typo in the texture file's name, or a misplaced texture file.

3 hours ago, Nephty said:

3. I use the name of a texture that doesn't exite : the rendered block is a full block with the missing texture.

Since the model (again: model, not texture) doesn't exist, neither the shape nor the texture (both of these are defined by the model file) can be determined. This means that the game uses the default shape (a block) with the default texture (the "missing" texture).

Fancy 3D Graphing Calculator mod, with many different coordinate systems.

Lightweight 3D/2D position/vector transformations library, also with support for different coordinate systems.

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.