Jump to content

Recommended Posts

Posted

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:

L2sVXja.png

 

//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;
    }


}

 

Posted (edited)

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 by Ugdhar
Posted (edited)

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 by TheGreyGhost
Posted

Thanks to all people who answered, I'm going to give the solutions a try tommorow.

On 4/22/2020 at 8: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.

Posted

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.

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Maybe there are other mods, not compatible with 47.4.4 - the 2nd 4 indicates mayor changes - so some mods may not compatible with it
    • Nope still the same issue exit code 1
    • I have no idea what the flip is going on, I can load the modpack just fine at forge 42.2.0 but any forge version above it insta-crashes with exit code 1. Can somebody tell me what's going on, this is minecraft 1.20.1 Latest.log: https://pastebin.com/pBUL1ZFa
    • does anyone know how to incorporate custom noise settings into a custom dimension through the use of datagen, I have created a custon json file for the noise settings that I want but I just don't know how to get it to register with the generated json file of the custom dimension.   here is the code for the dimension class package net.hurst.lustria.worldgen.dimension; import com.mojang.datafixers.util.Pair; import net.hurst.lustria.Lustria; import net.hurst.lustria.worldgen.biome.ModBiomes; import net.hurst.lustria.worldgen.registries.LustriaNoiseSettings; import net.minecraft.core.HolderGetter; import net.minecraft.core.registries.Registries; import net.minecraft.data.worldgen.BootstapContext; import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; import net.minecraft.tags.BlockTags; import net.minecraft.util.valueproviders.ConstantInt; import net.minecraft.world.level.Level; import net.minecraft.world.level.biome.*; import net.minecraft.world.level.dimension.BuiltinDimensionTypes; import net.minecraft.world.level.dimension.DimensionType; import net.minecraft.world.level.dimension.LevelStem; import net.minecraft.world.level.levelgen.NoiseBasedChunkGenerator; import net.minecraft.world.level.levelgen.NoiseGeneratorSettings; import java.util.List; import java.util.OptionalLong; public class ModDimensions { public static final ResourceKey<LevelStem> LUSTRIA_KEY = ResourceKey.create(Registries.LEVEL_STEM, ResourceLocation.fromNamespaceAndPath(Lustria.MOD_ID, "lustriadim")); public static final ResourceKey<Level> LUSTRIA_LEVEL_KEY = ResourceKey.create(Registries.DIMENSION, ResourceLocation.fromNamespaceAndPath(Lustria.MOD_ID, "lustriadim")); public static final ResourceKey<DimensionType> LUSTRIA_DIM_TYPE = ResourceKey.create(Registries.DIMENSION_TYPE, ResourceLocation.fromNamespaceAndPath(Lustria.MOD_ID, "lustriadim_type")); public static void bootstrapType(BootstapContext<DimensionType> context) { context.register(LUSTRIA_DIM_TYPE, new DimensionType( OptionalLong.of(12000), // fixedTime false, // hasSkylight true, // hasCeiling false, // ultraWarm false, // natural 1.0, // coordinateScale true, // bedWorks false, // respawnAnchorWorks -64, // minY 256, // height 256, // logicalHeight BlockTags.INFINIBURN_OVERWORLD, // infiniburn BuiltinDimensionTypes.OVERWORLD_EFFECTS, // effectsLocation 0.0f, // ambientLight new DimensionType.MonsterSettings(false, false, ConstantInt.of(0), 0))); } public static void bootstrapStem(BootstapContext<LevelStem> context) { HolderGetter<Biome> biomeRegistry = context.lookup(Registries.BIOME); HolderGetter<DimensionType> dimTypes = context.lookup(Registries.DIMENSION_TYPE); HolderGetter<NoiseGeneratorSettings> noiseGenSettings = context.lookup(Registries.NOISE_SETTINGS); NoiseBasedChunkGenerator wrappedChunkGenerator = new NoiseBasedChunkGenerator( new FixedBiomeSource(biomeRegistry.getOrThrow(Biomes.BEACH)), noiseGenSettings.getOrThrow(NoiseGeneratorSettings.CAVES)); NoiseBasedChunkGenerator noiseBasedChunkGenerator = new NoiseBasedChunkGenerator( MultiNoiseBiomeSource.createFromList( new Climate.ParameterList<>(List.of(Pair.of( Climate.parameters(0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F), biomeRegistry.getOrThrow(Biomes.BEACH)), Pair.of( Climate.parameters(0.1F, 0.2F, 0.0F, 0.2F, 0.0F, 0.0F, 0.0F), biomeRegistry.getOrThrow(Biomes.BIRCH_FOREST)), Pair.of( Climate.parameters(0.3F, 0.6F, 0.1F, 0.1F, 0.0F, 0.0F, 0.0F), biomeRegistry.getOrThrow(Biomes.OCEAN)), Pair.of( Climate.parameters(0.4F, 0.3F, 0.2F, 0.1F, 0.0F, 0.0F, 0.0F), biomeRegistry.getOrThrow(Biomes.DARK_FOREST)) ))), noiseGenSettings.getOrThrow(NoiseGeneratorSettings.CAVES)); LevelStem stem = new LevelStem(dimTypes.getOrThrow(ModDimensions.LUSTRIA_DIM_TYPE), noiseBasedChunkGenerator); context.register(LUSTRIA_KEY, stem); } } minecraft version is 1.20.1
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

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