Posted April 22, 20205 yr Hi, I have a problem with my blockmodels or maybe it's in my code. I am trying to add a transparent texture to my blockmodels, so it has two layers. However, ingame, the transparent parts become black. Here's a screenshot: //Block implementation public static Block candle = new VaseBlocks(Block.Properties.create(Material.ROCK) .hardnessAndResistance(2.0f, 3.0f) .sound(SoundType.STONE) .lightValue(10) ).setRegistryName(MainClass.location("candle")); //VaseBlock class //The candles use the same class for my vases package com.bajtix.onesblocks.blocks; import com.bajtix.onesblocks.lists.BlockItemList; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.HorizontalBlock; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.BlockItemUseContext; import net.minecraft.state.DirectionProperty; import net.minecraft.state.IntegerProperty; import net.minecraft.state.StateContainer; import net.minecraft.util.*; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockRayTraceResult; import net.minecraft.util.math.shapes.IBooleanFunction; import net.minecraft.util.math.shapes.ISelectionContext; import net.minecraft.util.math.shapes.VoxelShape; import net.minecraft.util.math.shapes.VoxelShapes; import net.minecraft.world.IBlockReader; import net.minecraft.world.World; import net.minecraft.world.server.ServerWorld; import java.util.Optional; import java.util.stream.Stream; public class VaseBlocks extends Block { public static final DirectionProperty FACING = HorizontalBlock.HORIZONTAL_FACING; private static final Optional<VoxelShape> SHAPE = Stream.of( Block.makeCuboidShape(2, 0, 2, 14, 5, 14) ).reduce((v1, v2) -> { return VoxelShapes.combineAndSimplify(v1, v2, IBooleanFunction.OR); }); public static IntegerProperty COUNT = ModBlockStateProperties.VASE_COUNT; public VaseBlocks(Properties p_i48440_1_) { super(p_i48440_1_); this.setDefaultState(this.getStateContainer().getBaseState().with(FACING, Direction.NORTH).with(COUNT, 1)); } @Override public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { return SHAPE.get(); } @Override public BlockState getStateForPlacement(BlockItemUseContext context) { return this.getDefaultState().with(FACING, context.getPlacementHorizontalFacing().getOpposite()); } @Override public BlockState rotate(BlockState state, Rotation rotation) { return state.with(FACING, rotation.rotate(state.get(FACING))); } @Override public BlockState mirror(BlockState state, Mirror mirrorIn) { return state.rotate(mirrorIn.toRotation(state.get(FACING))); } @Override protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) { builder.add(FACING); builder.add(COUNT); } @Override public ActionResultType func_225533_a_(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand hand, BlockRayTraceResult result) { if (!worldIn.isRemote) { ServerWorld serverWorld = (ServerWorld) worldIn; if (state.get(COUNT) < 3 && player.getHeldItem(hand).getItem() == BlockItemList.vase) { if (!player.isCreative()) player.inventory.getCurrentItem().setCount(player.inventory.getCurrentItem().getCount() - 1); serverWorld.setBlockState(pos, state.with(COUNT, state.get(COUNT) + 1)); } } return ActionResultType.SUCCESS; } }
April 22, 20205 yr You may need to use RenderTypeLookup.setRenderLayer on your blocks in FMLClientSetupEvent, i.e. RenderTypeLookup.setRenderLayer(NEWBLOCKS.FIREFLOWER.get(), RenderType.getCutout()); I believe this needs to be done using a DeferredWorkQueue *edit: I guess I should have asked what version, this is how I fixed a similar issue in 1.15.2. Edited April 22, 20205 yr by Ugdhar
April 23, 20205 yr Hi Do you mean * fully transparent (i.e. each pixel is either present or absent) - in which case getCutout is the right renderlayer * partially transparent (i.e. alpha blending - like glass panes where you can see through them) - in which case you will probably need to use a Forge multilayer block { "loader": "forge:multi-layer", "credit": "Made with Blockbench", "layers": { "solid": { "parent": "block/block", "textures": { "1": "block/frosted_ice_0", "2": "block/ice", "3": "block/white_stained_glass", "particle": "block/lantern", "all": "block/lantern" }, "elements": [ { "name": "top", "from": [5, 6, 5], "to": [11, 7, 11], "faces": { "north": {"uv": [0, 2, 6, 3], "texture": "#all"}, "east": {"uv": [0, 2, 6, 3], "texture": "#all"}, "south": {"uv": [0, 2, 6, 3], "texture": "#all"}, "west": {"uv": [0, 2, 6, 3], "texture": "#all"}, "up": {"uv": [0, 9, 6, 15], "texture": "#all"}, "down": {"uv": [0, 9, 6, 15], "texture": "#all", "cullface": "down"} } } ] }, "translucent": { "parent": "block/block", "textures": { "1": "block/frosted_ice_0", "2": "block/ice", "3": "block/white_stained_glass", "particle": "block/lantern", "all": "block/lantern" }, "elements": [ { "name": "glass", "from": [5, 1, 5], "to": [11, 6, 11], "faces": { "east": {"uv": [5, 1, 10, 7], "texture": "#3"}, "south": {"uv": [0, 0, 5, 5], "texture": "#1"}, "west": {"uv": [0, 0, 5, 5], "texture": "#2"} } } ] } } } Cheers TGG PS forgot to mention - for multilayer you will also need to set the RenderLayer like this: @SubscribeEvent public static void onClientSetupEvent(FMLClientSetupEvent event) { RenderTypeLookup.setRenderLayer(StartupCommon.blockGlassLantern, StartupClientOnly::isGlassLanternValidLayer); } // does the Glass Lantern render in the given layer (RenderType) - used as Predicate<RenderType> lambda for setRenderLayer public static boolean isGlassLanternValidLayer(RenderType layerToCheck) { return layerToCheck == RenderType.getSolid() || layerToCheck == RenderType.getTranslucent(); } Edited April 23, 20205 yr by TheGreyGhost
April 25, 20205 yr Author Thanks to all people who answered, I'm going to give the solutions a try tommorow. On 4/22/2020 at 6:38 PM, diesieben07 said: Do not create blocks and other registry entries in static initializers. I am going to rewrite it to deffered registries. I thought I'd do it later, but i think i should do it ASAP.
April 30, 20205 yr Just want to say thank you for this thread - it has solved several hours of headaches. I thought I had issues with my textures and/or code for registering new blocks, and had been going over everything, again and again.
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.