Jump to content

[1.19.2] BlockEntity invisible when placed by world gen


SnakerBone

Recommended Posts

Hi again, I'm having trouble with my block entity being invisible when placed by world gen, It works fine when Its placed by a player. My block also uses a shader for its texture. It looks like this in game:

2023-03-08-18-32-42.png

Here's my current code:

// Biome

import com.mojang.datafixers.util.Pair;
import net.minecraft.core.Registry;
import net.minecraft.data.worldgen.BiomeDefaultFeatures;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.sounds.Music;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.MobCategory;
import net.minecraft.world.level.biome.*;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.levelgen.SurfaceRules;
import net.minecraftforge.registries.RegistryObject;
import snaker.snakerbone.registry.SnakerBoneContentRegistry;
import snaker.snakerbone.registry.SnakerBoneEntityRegistry;
import snaker.snakerbone.registry.SnakerBoneWorldGenRegistry;
import terrablender.api.Region;
import terrablender.api.RegionType;

import javax.annotation.Nullable;
import java.util.function.Consumer;

import static net.minecraft.world.level.biome.Biomes.PLAINS;
import static snaker.snakerbone.util.SnakerBonePolicy.WarningSuppression.CUSTOM_SET;
import static snaker.snakerbone.util.SnakerBoneTools.hexToInt;

public class ShaderPlains {
    public static Biome getBiome() {

        MobSpawnSettings.Builder SpawnBuilder = new MobSpawnSettings.Builder();
        BiomeGenerationSettings.Builder BiomeBuilder = new BiomeGenerationSettings.Builder();

        addMobSpawn(SpawnBuilder, MobCategory.MONSTER, SnakerBoneEntityRegistry.COSMO, 15, 1, 3);
        addMobSpawn(SpawnBuilder, MobCategory.MONSTER, SnakerBoneEntityRegistry.FLARE, 15, 1, 3);

        return generateBiome(Biome.Precipitation.NONE, 0.8F, 0, hexToInt("18ADBD"), hexToInt("58AAB2"), hexToInt("064C53"), SpawnBuilder, BiomeBuilder, AmbientMoodSettings.LEGACY_CAVE_SETTINGS, null);

    }

    protected static int calculateSkyColor(float colour) {

        float hsv = colour / 3;

        hsv = Mth.clamp(hsv, -1, 1);

        return Mth.hsvToRgb(0.62222224F - hsv * 0.05F, 0.5F + hsv * 0.1F, 1);

    }

    private static Biome generateBiome(Biome.Precipitation precipitation, float temperature, float downfall, int fogColour, int waterColour, int waterFogColour, MobSpawnSettings.Builder spawnBuilder, BiomeGenerationSettings.Builder biomeBuilder, AmbientMoodSettings mood, @Nullable Music music) {

        return new Biome.BiomeBuilder().precipitation(precipitation).temperature(temperature).downfall(downfall).specialEffects(new BiomeSpecialEffects.Builder().waterColor(waterColour).waterFogColor(waterFogColour).fogColor(fogColour).skyColor(calculateSkyColor(temperature)).ambientMoodSound(mood).backgroundMusic(music).build()).mobSpawnSettings(spawnBuilder.build()).generationSettings(biomeBuilder.build()).build();

    }

    private static <M extends Mob> void addMobSpawn(MobSpawnSettings.Builder builder, MobCategory category, EntityType<M> type, int weight, int min, int max) {

        builder.addSpawn(category, new MobSpawnSettings.SpawnerData(type, weight, min, max));

        BiomeDefaultFeatures.commonSpawns(builder);

    }

    private static <M extends Mob> void addMobSpawn(MobSpawnSettings.Builder builder, MobCategory category, RegistryObject<EntityType<M>> type, int weight, int min, int max) {

        builder.addSpawn(category, new MobSpawnSettings.SpawnerData(type.get(), weight, min, max));

        BiomeDefaultFeatures.commonSpawns(builder);

    }

    private static void addDefaultFeatures(BiomeGenerationSettings.Builder builder) {

        BiomeDefaultFeatures.addDefaultOres(builder);
        BiomeDefaultFeatures.addDefaultSoftDisks(builder);
        BiomeDefaultFeatures.addExtraEmeralds(builder);
        BiomeDefaultFeatures.addInfestedStone(builder);
        BiomeDefaultFeatures.addDefaultCarversAndLakes(builder);
        BiomeDefaultFeatures.addDefaultCrystalFormations(builder);
        BiomeDefaultFeatures.addDefaultUndergroundVariety(builder);
        BiomeDefaultFeatures.addDefaultSprings(builder);

    }

    public static class RuleData {
        private static final SurfaceRules.RuleSource SWIRL_BLOCK = makeStateRule(SnakerBoneContentRegistry.SWIRL_BLOCK);
        private static final SurfaceRules.RuleSource STARS_BLOCK = makeStateRule(SnakerBoneContentRegistry.STARS_BLOCK);
        private static final SurfaceRules.RuleSource WATERCOLOUR_BLOCK = makeStateRule(SnakerBoneContentRegistry.WATERCOLOUR_BLOCK);

        public static SurfaceRules.RuleSource getRules() {

            SurfaceRules.ConditionSource WaterBlockCheck = SurfaceRules.waterBlockCheck(-1, 0);

            SurfaceRules.RuleSource surface = SurfaceRules.sequence(SurfaceRules.ifTrue(WaterBlockCheck, STARS_BLOCK), SWIRL_BLOCK);

            return SurfaceRules.sequence(SurfaceRules.ifTrue(SurfaceRules.isBiome(SnakerBoneWorldGenRegistry.SHADER_PLAINS), WATERCOLOUR_BLOCK), SurfaceRules.ifTrue(SurfaceRules.ON_FLOOR, surface));

        }

        private static SurfaceRules.RuleSource makeStateRule(RegistryObject<Block> block) {

            return SurfaceRules.state(block.get().defaultBlockState());

        }

        private static SurfaceRules.RuleSource makeStateRule(Block block) {

            return SurfaceRules.state(block.defaultBlockState());

        }
    }

    public static class BiomeRegion extends Region {
        public BiomeRegion(ResourceLocation name, int weight) {

            super(name, RegionType.OVERWORLD, weight);

        }

        @Override
        public void addBiomes(Registry<Biome> registry, Consumer<Pair<Climate.ParameterPoint, ResourceKey<Biome>>> mapper) {

            this.addModifiedVanillaOverworldBiomes(mapper, builder -> builder.replaceBiome(PLAINS, SnakerBoneWorldGenRegistry.SHADER_PLAINS));

        }
    }
}
// BlockEntity

import net.minecraft.core.BlockPos;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import snaker.snakerbone.registry.SnakerBoneContentRegistry;
import software.bernie.geckolib3.core.IAnimatable;
import software.bernie.geckolib3.core.PlayState;
import software.bernie.geckolib3.core.controller.AnimationController;
import software.bernie.geckolib3.core.event.predicate.AnimationEvent;
import software.bernie.geckolib3.core.manager.AnimationData;
import software.bernie.geckolib3.core.manager.AnimationFactory;
import software.bernie.geckolib3.util.GeckoLibUtil;

import static snaker.snakerbone.util.SnakerBonePolicy.WarningSuppression.CUSTOM_SET;

public class WaterColourBlockEntity extends BlockEntity implements IAnimatable {

    private final AnimationFactory FACTORY = GeckoLibUtil.createFactory(this);

    public WaterColourBlockEntity(BlockPos pos, BlockState state) {

        super(SnakerBoneContentRegistry.WATERCOLOUR_BE.get(), pos, state);

    }

    private <E extends IAnimatable> PlayState predicate(AnimationEvent<E> entity) {

        return PlayState.CONTINUE;

    }

    @Override
    public void registerControllers(AnimationData data) {

        data.addAnimationController(new AnimationController<>(this, "controller", 0, this::predicate));

    }

    @Override
    public AnimationFactory getFactory() {

        return FACTORY;

    }
}
// Block

import net.minecraft.core.BlockPos;
import net.minecraft.world.level.block.BaseEntityBlock;
import net.minecraft.world.level.block.RenderShape;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import org.jetbrains.annotations.Nullable;
import snaker.snakerbone.registry.SnakerBoneContentRegistry;

import static net.minecraft.world.level.material.Material.METAL;
import static snaker.snakerbone.util.SnakerBonePolicy.WarningSuppression.CUSTOM_SET;

public class WaterColourBlock extends BaseEntityBlock {

    public WaterColourBlock() {

        super(Properties.of(METAL).requiresCorrectToolForDrops().strength(5));

    }

    @Nullable
    @Override
    public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {

        return SnakerBoneContentRegistry.WATERCOLOUR_BE.get().create(pos, state);

    }

    @Override
    public RenderShape getRenderShape(BlockState pState) {

        return RenderShape.ENTITYBLOCK_ANIMATED;

    }
}
Link to comment
Share on other sites

I figured it out! I had to change the buffer size on the render type from 256 to Integer.POSITIVE_INFINITY. This gives it an infinite buffer size with no limit. Though it makes the game EXTREMELY laggy (obviously). So I've scrapped the original idea I had for world gen with shader blocks and moved on because I'm not really the biggest fan of trying to optimise shaders as I hate coding in C++ with a passion lol

Link to comment
Share on other sites

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.