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.
#Custom Grass Class
71 messages · Page 1 of 1 (latest)
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
but wouldnt that change that every type turns into my custom dirt?
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
how would it do it there in my class?
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
master branch is bugged rn 1.21 is the right one
kk thanks
but how can you acess the project without me adding you to it?
okay nice
got it working
you are helping me so its okay but you know that its ilegall what you did right?
it really isn't
ARR license
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
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
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
you can just send the code
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
thanks anyway
Np
does not spread on normal dirt aswell even though i wnat it to spread to my custom dirt
Wait you want it on both?
no only the custom dirt but tried both to see if it works on one of them and it does not
How high is your tick rate?
oh wait the light level of my dimension is the problem got it
Yeah that is also a parameter
could i edit it so it spreads at night or with low light level?
thanks just saw it