#Custom Grass Class

71 messages · Page 1 of 1 (latest)

crimson ibex
#

I need my custom grass class to be edited so it copy's everything from the normal grass except for the spreading that should happen from my custom grass to my custom dirt.Also in vanilla a grass block turns into dirt if its below another block after some time.There my custom block should turn into my custom dirt and not into normal dirt.

stark token
#

I believe you have to override the randomTick event of the GrassBlock

#

although to be completely honest the SpreadableBlock code seems wierd as hell

#

Yeah in random tick you would check the four attached blocks

#

if your grass can survive there than change them into grass

#

the same for the decay

#

check the block directly above it in random tick

#
public abstract class SpreadableBlock extends SnowyBlock {
    protected SpreadableBlock(AbstractBlock.Settings settings) {
        super(settings);
    }

    private static boolean canSurvive(BlockState state, WorldView world, BlockPos pos) {
        BlockPos blockPos = pos.up();
        BlockState blockState = world.getBlockState(blockPos);
        if (blockState.isOf(Blocks.SNOW) && (Integer)blockState.get(SnowBlock.LAYERS) == 1) {
            return true;
        } else if (blockState.getFluidState().getLevel() == 8) {
            return false;
        } else {
            int i = ChunkLightProvider.getRealisticOpacity(world, state, pos, blockState, blockPos, Direction.UP, blockState.getOpacity(world, blockPos));
            return i < world.getMaxLightLevel();
        }
    }

    @Override
    protected abstract MapCodec<? extends SpreadableBlock> getCodec();

    private static boolean canSpread(BlockState state, WorldView world, BlockPos pos) {
        BlockPos blockPos = pos.up();
        return canSurvive(state, world, pos) && !world.getFluidState(blockPos).isIn(FluidTags.WATER);
    }

    @Override
    protected void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
        if (!canSurvive(state, world, pos)) {
            world.setBlockState(pos, Blocks.DIRT.getDefaultState());
        } else {
            if (world.getLightLevel(pos.up()) >= 9) {
                BlockState blockState = this.getDefaultState();

                for (int i = 0; i < 4; i++) {
                    BlockPos blockPos = pos.add(random.nextInt(3) - 1, random.nextInt(5) - 3, random.nextInt(3) - 1);
                    if (world.getBlockState(blockPos).isOf(Blocks.DIRT) && canSpread(blockState, world, blockPos)) {
                        world.setBlockState(blockPos, blockState.with(SNOWY, world.getBlockState(blockPos.up()).isOf(Blocks.SNOW)));
                    }
                }
            }
        }
    }
}
#

you can see it there

#

if !canSurvive set to dirt

#

you just put your dirt item instead

crimson ibex
#

but wouldnt that change that every type turns into my custom dirt?

stark token
#

no

#

you can't actually edit the source code

#

well through mixins but thats besides the point

#

do you have a repository so I could have a crack at it?

#

but effectively you only override it on your own grass block class

crimson ibex
#

how would it do it there in my class?

stark token
#

i'll code it up and then show you

#

what jdk version do you use?

#

cause your datagen is throwing null pointer exception

#

@crimson ibex

crimson ibex
#

master branch is bugged rn 1.21 is the right one

stark token
#

kk thanks

crimson ibex
#

but how can you acess the project without me adding you to it?

stark token
#

i can clone it

#

its public

#

got the decay

crimson ibex
#

okay nice

stark token
#

got it working

crimson ibex
#

you are helping me so its okay but you know that its ilegall what you did right?

stark token
#

it really isn't

crimson ibex
#

ARR license

stark token
#

im not publishing it anywhere

#

as long as i don't distribute it

#

even though it is publicaly accesible

#

if you don't want to have it publicaly accessible make it a private repository

crimson ibex
#

its okay just thats what i mean

#

modify part just wanna tell you so you dont run into issues im okay with you doing it

stark token
#

well bub the license on github is cc0 lol

#

you want to give write rights or should i fork it and make a pull reques?

#

or i can just send you the code i don't really care

crimson ibex
#

you can just send the code

stark token
#

It is identical to the vanilla code

#

just changes the Block state from dirt to stellar dirt

#

Learn about inheritance

#

To see it in action I recommend putting your tick rate way up

#

But if you're worried about people stealing your code then make the repo private

#

Don't think a licence will stop a lot of people

crimson ibex
stark token
#

Np

crimson ibex
#

so its spreads

stark token
#

It has it

#

Just put a bunch of your dirt around your grass

#

It will spread

crimson ibex
#

does not spread on normal dirt aswell even though i wnat it to spread to my custom dirt

stark token
#

Wait you want it on both?

crimson ibex
#

no only the custom dirt but tried both to see if it works on one of them and it does not

stark token
#

How high is your tick rate?

crimson ibex
#

oh wait the light level of my dimension is the problem got it

stark token
#

Yeah that is also a parameter

crimson ibex
#

could i edit it so it spreads at night or with low light level?

stark token
#

Ma there is literally an if for it in the code

#

Just change the 9

crimson ibex
#

thanks just saw it