Jump to content

Recommended Posts

Posted

I'm trying to make a block that only renders it's side when it touches a block that is not air. This sort of works so far, the problem is that the block is only visible from the outside. Here is a screenshot to explain:

DyKdeCu.png

 

The block is only visible through the grass, not if I stand inside or behind the block.

I think, what I need to do is tell the game to render the insides of the block as well. How would I do that?

 

Block Class:

package tschipp.buildingblocks.blocks;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Nullable;

import net.minecraft.block.Block;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.MapColor;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumBlockRenderType;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.IShearable;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import tschipp.buildingblocks.BBMod;

public class BlockOvergrowth extends Block implements IShearable {

public static final AxisAlignedBB boundingBox = new AxisAlignedBB(0.0D, 0.0D, 0.0D, 0.0625D, 0.0625D,0.0625D);

public BlockOvergrowth()
{
	super(Material.PLANTS, MapColor.GRASS);
	this.setCreativeTab(BBMod.buildingBlocks);
	this.setUnlocalizedName("overgrowth");
	this.setSoundType(SoundType.PLANT);
	this.setHardness(0.1F);
	this.setResistance(1F);

}

@Override
public boolean isShearable(ItemStack item, IBlockAccess world, BlockPos pos)
{
	return true;
}

@Override
@Deprecated
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos)
{
	return boundingBox;
}


@Nullable
@Override
public AxisAlignedBB getCollisionBoundingBox(IBlockState blockState, World worldIn, BlockPos pos)
{
	return NULL_AABB;
}

@Override
public boolean isReplaceable(IBlockAccess worldIn, BlockPos pos)
{
	return true;
}

@Override
public boolean isOpaqueCube(IBlockState state)
{
	return false;
}

@Override
public boolean isFullCube(IBlockState state)
{
	return false;
}


@Override
@SideOnly(Side.CLIENT)
public BlockRenderLayer getBlockLayer()
{
	return BlockRenderLayer.CUTOUT;
}

@Override
public boolean isCollidable()
{
	return false;
}

@Deprecated
@Override
public boolean shouldSideBeRendered(IBlockState blockState, IBlockAccess world, BlockPos pos, EnumFacing side)
{
	Block nextTo = world.getBlockState(pos.offset(side)).getBlock();
	if(nextTo != Blocks.AIR)
	{
		return true;
	}
	return false;
}



@Override
public List<ItemStack> onSheared(ItemStack item, IBlockAccess world, BlockPos pos, int fortune)
{
	List<ItemStack> drops = new ArrayList<ItemStack>();
	drops.add(new ItemStack(BBBlocks.overgrowth));
	return drops;
}

}

 

Posted

Show your model. You're probably only adding a quad for one side. Quads are only rendered from one side, from the opposite side they'll be invisible, so if you want your block to have the same texture on both sides, you'll need to quads.

Don't make mods if you don't know Java.

Check out my website: http://shadowfacts.net

Developer of many mods

Posted

Show your model. You're probably only adding a quad for one side. Quads are only rendered from one side, from the opposite side they'll be invisible, so if you want your block to have the same texture on both sides, you'll need to quads.

 

I am using the cube_all model

Posted

Show your model. You're probably only adding a quad for one side. Quads are only rendered from one side, from the opposite side they'll be invisible, so if you want your block to have the same texture on both sides, you'll need to quads.

 

I just realized I'm probably a idiot for using a block model that only has one element. I'll add some planes and get back to you.

 

I am using the cube_all model

Posted

You need to edit your model and add planes for the inside.

 

Alright, I made some progress: The sides now all get rendered, the problem is, they get rendered even when touching air. How do I need to alter my code / blockmodel?

 

here is my model, I made it using MrCrayfish's model maker, because I have no idea how to model by hand:

{
    "textures": {
    },
    "elements": [
        {
            "name": "Cube",
            "from": [ 0.0, 0.0, 0.0 ], 
            "to": [ 0.0, 16.0, 16.0 ], 
            "faces": {
                "north": { "texture": "#all", "uv": [ 0.0, 0.0, 0.0, 16.0 ] },
                "east": { "texture": "#all", "uv": [ 0.0, 0.0, 16.0, 16.0 ] },
                "south": { "texture": "#all", "uv": [ 0.0, 0.0, 0.0, 16.0 ] },
                "west": { "texture": "#all", "uv": [ 0.0, 0.0, 16.0, 16.0 ] },
                "up": { "texture": "#all", "uv": [ 0.0, 0.0, 0.0, 16.0 ] },
                "down": { "texture": "#all", "uv": [ 0.0, 0.0, 0.0, 16.0 ] }
            }
        },
        {
            "name": "Cube",
            "from": [ 0.0, 0.0, 0.0 ], 
            "to": [ 16.0, 16.0, 0.0 ], 
            "faces": {
                "north": { "texture": "#all", "uv": [ 0.0, 0.0, 16.0, 16.0 ] },
                "east": { "texture": "#all", "uv": [ 0.0, 0.0, 0.0, 16.0 ] },
                "south": { "texture": "#all", "uv": [ 0.0, 0.0, 16.0, 16.0 ] },
                "west": { "texture": "#all", "uv": [ 0.0, 0.0, 0.0, 16.0 ] },
                "up": { "texture": "#all", "uv": [ 0.0, 0.0, 16.0, 0.0 ] },
                "down": { "texture": "#all", "uv": [ 0.0, 0.0, 16.0, 0.0 ] }
            }
        },
        {
            "name": "Cube",
            "from": [ 16.0, 0.0, 0.0 ], 
            "to": [ 16.0, 16.0, 16.0 ], 
            "faces": {
                "north": { "texture": "#all", "uv": [ 0.0, 0.0, 0.0, 16.0 ] },
                "east": { "texture": "#all", "uv": [ 0.0, 0.0, 16.0, 16.0 ] },
                "south": { "texture": "#all", "uv": [ 0.0, 0.0, 0.0, 16.0 ] },
                "west": { "texture": "#all", "uv": [ 0.0, 0.0, 16.0, 16.0 ] },
                "up": { "texture": "#all", "uv": [ 0.0, 0.0, 0.0, 16.0 ] },
                "down": { "texture": "#all", "uv": [ 0.0, 0.0, 0.0, 16.0 ] }
            }
        },
        {
            "name": "Cube",
            "from": [ 0.0, 0.0, 16.0 ], 
            "to": [ 16.0, 16.0, 16.0 ], 
            "faces": {
                "north": { "texture": "#all", "uv": [ 0.0, 0.0, 16.0, 16.0 ] },
                "east": { "texture": "#all", "uv": [ 0.0, 0.0, 0.0, 16.0 ] },
                "south": { "texture": "#all", "uv": [ 0.0, 0.0, 16.0, 16.0 ] },
                "west": { "texture": "#all", "uv": [ 0.0, 0.0, 0.0, 16.0 ] },
                "up": { "texture": "#all", "uv": [ 0.0, 0.0, 16.0, 0.0 ] },
                "down": { "texture": "#all", "uv": [ 0.0, 0.0, 16.0, 0.0 ] }
            }
        },
        {
            "name": "Cube",
            "from": [ 0.0, 16.0, 0.0 ], 
            "to": [ 16.0, 16.0, 16.0 ], 
            "faces": {
                "north": { "texture": "#all", "uv": [ 0.0, 0.0, 16.0, 0.0 ] },
                "east": { "texture": "#all", "uv": [ 0.0, 0.0, 16.0, 0.0 ] },
                "south": { "texture": "#all", "uv": [ 0.0, 0.0, 16.0, 0.0 ] },
                "west": { "texture": "#all", "uv": [ 0.0, 0.0, 16.0, 0.0 ] },
                "up": { "texture": "#all", "uv": [ 0.0, 0.0, 16.0, 16.0 ] },
                "down": { "texture": "#all", "uv": [ 0.0, 0.0, 16.0, 16.0 ] }
            }
        },
        {
            "name": "Cube",
            "from": [ 0.0, 0.0, 0.0 ], 
            "to": [ 16.0, 0.0, 16.0 ], 
            "shade": false,
            "faces": {
                "north": { "texture": "#all", "uv": [ 0.0, 0.0, 16.0, 0.0 ] },
                "east": { "texture": "#all", "uv": [ 0.0, 0.0, 16.0, 0.0 ] },
                "south": { "texture": "#all", "uv": [ 0.0, 0.0, 16.0, 0.0 ] },
                "west": { "texture": "#all", "uv": [ 0.0, 0.0, 16.0, 0.0 ] },
                "up": { "texture": "#all", "uv": [ 0.0, 0.0, 16.0, 16.0 ] },
                "down": { "texture": "#all", "uv": [ 0.0, 0.0, 16.0, 16.0 ] }
            }
        }
    ]
}

Posted

How did you do it before?

I didn't change any of my code, just the block model.

In the shouldSideBeRendered method I check if the side is touching air. If it is, I return false.

Posted

I think

shouldSideBeRendered

only works with cube_all models. Otherwise there'd be no way for the code to know which faces of which shapes count as each 'side'.

 

You can definitely use blockstates to adapt the model depending on the blocks around it, as an alternative.

Posted

I think

shouldSideBeRendered

only works with cube_all models. Otherwise there'd be no way for the code to know which faces of which shapes count as each 'side'.

 

You can definitely use blockstates to adapt the model depending on the blocks around it, as an alternative.

There would be a way...

"north": { "texture": "#all", "uv": [ 0.0, 0.0, 0.0, 16.0 ] },

You specify the face in the model. But the BlockState part is definitely the correct way to go.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted

There would be a way...

"north": { "texture": "#all", "uv": [ 0.0, 0.0, 0.0, 16.0 ] },

You specify the face in the model. But the BlockState part is definitely the correct way to go.

 

What do you mean? I know Blockstates would probably be better but I find it a pain setting up the blockstates and all...

Posted

There would be a way...

"north": { "texture": "#all", "uv": [ 0.0, 0.0, 0.0, 16.0 ] },

You specify the face in the model. But the BlockState part is definitely the correct way to go.

 

What do you mean? I know Blockstates would probably be better but I find it a pain setting up the blockstates and all...

 

I think I found it! I just had to set a cullface for the elements! But now the planes of the block below and my block are z-fighting (I think that's the right word). How do I fix that?

Posted

You override getActualState in your Block class. This will return the default state with 6 values; boolean values. Each one will represent if there is a block that is not air. If there is a block that is not air it will add to the model using forges submodel system. Meaning you will use a forge style BlockState. You will also have to override getMetaFromState, getStateFromMeta, createBlockState.

 

There would be a way...

"north": { "texture": "#all", "uv": [ 0.0, 0.0, 0.0, 16.0 ] },

You specify the face in the model. But the BlockState part is definitely the correct way to go.

 

What do you mean? I know Blockstates would probably be better but I find it a pain setting up the blockstates and all...

 

I think I found it! I just had to set a cullface for the elements! But now the planes of the block below and my block are z-fighting (I think that's the right word). How do I fix that?

You will have to make one face slightly closer to the middle of the block or slightly farther from the block.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

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.