Jump to content

TESR down face not rendering


Lyon

Recommended Posts

Hello,

I created a block in which I want to render a smaller cube. As I want to resize the smaller cube I am using a TESR to render it.

The problem is, that the face at the bottom of the block is being rendered like the top face. So, if I look down on it it is visible, but when I look up to it it is invisible.

I really have no clue what the problem is, so every help is appreciated.

 

Images:

Spoiler

1102048077_Anmerkung2020-04-14102358.thumb.png.ba74b47a9abafba51824b5fb5ad3736c.png1043018158_Anmerkung2020-04-14102357.thumb.png.4066a5c37c8e4bb945537af7cab07162.png

BlockVaporator:

Spoiler

public class BlockVaporator extends Block implements IHasModel
{
	private final static AxisAlignedBB boundingBox = new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 2.0D, 1.0D);
	private static BlockFakeVaporator FAKE_BLOCK;
	private static final PropertyDirection FACING = BlockHorizontal.FACING;
	
	public BlockVaporator(String name, Material material) 
	{
		super(material);
		setUnlocalizedName(name);
		setRegistryName(Reference.MODID, name);
		setCreativeTab(Main.AOMTAB);
		
		setSoundType(SoundType.METAL);
		setHarvestLevel("pickaxe", 1);
		setHardness(3.5F);
		setResistance(17.5F);
		
		this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH));
		
		FAKE_BLOCK = new BlockFakeVaporator("fake_block_vaporator", material);
		
		BlockInit.BLOCKS.add(FAKE_BLOCK);
		BlockInit.BLOCKS.add(this);
		ItemInit.ITEMS.add(new BlockItemVaporator(name, this));
	}
	
	@Override
	public boolean canPlaceBlockAt(World worldIn, BlockPos pos) 
	{
		if(worldIn.getBlockState(new BlockPos(pos.getX(), pos.getY() + 1, pos.getZ())).getBlock() instanceof BlockAir)
		{
			return true;
		}
		
		return false;
	}
	
	@Override
	public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state) 
	{
		if(!worldIn.isRemote)
		{
			if(worldIn.getBlockState(new BlockPos(pos.getX(), pos.getY() + 1, pos.getZ())).getBlock() instanceof BlockAir)
			{
				worldIn.setBlockState(new BlockPos(pos.getX(), pos.getY() + 1, pos.getZ()), FAKE_BLOCK.getDefaultState());
			}
		}
	}
	
	@Override
	public void onBlockHarvested(World worldIn, BlockPos pos, IBlockState state, EntityPlayer player) 
	{
		if(!worldIn.isRemote && worldIn.getBlockState(new BlockPos(pos.getX(), pos.getY() + 1, pos.getZ())).getBlock() instanceof BlockFakeVaporator)
		{
			worldIn.setBlockToAir(new BlockPos(pos.getX(), pos.getY() + 1, pos.getZ()));
		}
	}
	
	@Override
	public void onBlockDestroyedByExplosion(World worldIn, BlockPos pos, Explosion explosionIn) 
	{
		if(!worldIn.isRemote && worldIn.getBlockState(new BlockPos(pos.getX(), pos.getY() + 1, pos.getZ())).getBlock() instanceof BlockFakeVaporator)
		{		
			worldIn.setBlockToAir(new BlockPos(pos.getX(), pos.getY() + 1, pos.getZ()));
		}
	}
	
	@Override
	protected BlockStateContainer createBlockState() 
	{
		return new BlockStateContainer(this, new IProperty[]{FACING});
	}
	
	@Override
	public BlockRenderLayer getBlockLayer() 
	{
		return BlockRenderLayer.CUTOUT_MIPPED;
	}
	
	@Override
	public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) 
	{
		return this.boundingBox;
	}
	
	@Override
	public int getLightValue(IBlockState state, IBlockAccess world, BlockPos pos) 
	{
		return 15;
	}
	
	@Override
	public int getMetaFromState(IBlockState state) 
	{
		return state.getValue(FACING).getIndex();
	}
	
	@Override
	public IBlockState getStateFromMeta(int meta) 
	{
		return this.getDefaultState().withProperty(FACING, EnumFacing.getFront(meta));
	}
	
	@Override
	public IBlockState getStateForPlacement(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer, EnumHand hand) 
	{
		return this.getDefaultState().withProperty(FACING, placer.getHorizontalFacing().getOpposite());
	}
	
	@Override
	public boolean isOpaqueCube(IBlockState state) 
	{
		return false;
	}
	
	@Override
	public boolean hasTileEntity(IBlockState state) 
	{
		return true;
	}
	
	@Override
	public TileEntity createTileEntity(World world, IBlockState state) 
	{
		return new TileEntityVaporator();
	}
	
	@Override
	public void registerModels() 
	{
		Main.proxy.registerItemRenderer(Item.getItemFromBlock(this), 0, "inventory");
	}
}

 

TileEntityRendererVaporator:

Spoiler

public class TileEntityRendererVaporator extends TileEntitySpecialRenderer<TileEntityVaporator>
{
	private final static ResourceLocation TEXTURE_GAS = new ResourceLocation(Reference.MODID, "textures/blocks/gas.png");
	
	@Override
	public void render(TileEntityVaporator te, double x, double y, double z, float partialTicks, int destroyStage, float alpha) 
	{
		float height = 0.25F;
		
		this.bindTexture(TEXTURE_GAS);
		
		Tessellator tessellator = Tessellator.getInstance();
        
		GlStateManager.cullFace(CullFace.FRONT);
        GlStateManager.enableBlend();
        GlStateManager.tryBlendFuncSeparate(SourceFactor.SRC_ALPHA, DestFactor.ONE_MINUS_SRC_ALPHA, SourceFactor.ONE, DestFactor.ZERO);

        UtilsRender.renderCuboid(tessellator, x + 1.5, y + 1.0 + (14.0F/16.0F) - (6.5F/16.0F) * height, z + 0.5, 0.8, 0.8, height * (13.0F/16.0F), 0.0F, 0.0F, 0.0F, TEXTURE_GAS);
        
        GlStateManager.cullFace(CullFace.BACK);
        GlStateManager.disableBlend();
		
		super.render(te, x, y, z, partialTicks, destroyStage, alpha);
	}
}

 

 

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.