Skip to content

Commit

Permalink
Jade vine internal changes, etc
Browse files Browse the repository at this point in the history
  • Loading branch information
Mechalopa committed Jan 12, 2025
1 parent dd524d5 commit 05f40bc
Show file tree
Hide file tree
Showing 24 changed files with 380 additions and 315 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
import java.util.function.Supplier;

import com.github.mechalopa.jafohana.JAFOhana;
import com.github.mechalopa.jafohana.world.level.levelgen.feature.JadeVinesFeature;
import com.github.mechalopa.jafohana.world.level.levelgen.feature.LayeringFeature;
import com.github.mechalopa.jafohana.world.level.levelgen.feature.VineFlowersFeature;
import com.github.mechalopa.jafohana.world.level.levelgen.feature.configurations.LayeringFeatureConfiguration;
import com.github.mechalopa.jafohana.world.level.levelgen.feature.configurations.VineFlowersConfiguration;

import net.minecraft.core.registries.Registries;
import net.minecraft.world.level.levelgen.feature.Feature;
Expand All @@ -17,7 +18,7 @@ public class ModBiomeFeatures
{
private static final DeferredRegister<Feature<?>> REGISTRY = DeferredRegister.create(Registries.FEATURE, JAFOhana.MODID);

public static final Supplier<Feature<JadeVinesFeature.JadeVinesConfiguration>> JADE_VINES = REGISTRY.register("jade_vines", () -> new JadeVinesFeature(JadeVinesFeature.JadeVinesConfiguration.CODEC));
public static final Supplier<Feature<VineFlowersConfiguration>> JADE_VINES = REGISTRY.register("vine_flowers", () -> new VineFlowersFeature(VineFlowersConfiguration.CODEC));
public static final Supplier<Feature<LayeringFeatureConfiguration>> LAYERING_FEATURE = REGISTRY.register("layering", () -> new LayeringFeature(LayeringFeatureConfiguration.CODEC));

@SubscribeEvent
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/github/mechalopa/jafohana/util/ModTags.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ public static final class BlockTags
{
public static final TagKey<Block> AFFECTS_FASCIATIONS = createBlockTag("affects_fasciations");
public static final TagKey<Block> BADLANDS_FLOWER_PLANTABLE_ON = createBlockTag("badlands_flower_plantable_on");
public static final TagKey<Block> BEACH_SPIDER_LILY_PLANTABLE_ON = createBlockTag("beach_spider_lily_plantable_on");
public static final TagKey<Block> BEACH_FLOWER_PLANTABLE_ON = createBlockTag("beach_flower_plantable_on");
public static final TagKey<Block> CONVERTABLE_TO_CREEPANSY = createBlockTag("convertable_to_creepansy");
public static final TagKey<Block> CONVERTABLE_TO_FASCIATED_DANDELION = createBlockTag("convertable_to_fasciated_dandelion");
public static final TagKey<Block> CONVERTABLE_TO_FASCIATED_OXEYE_DAISY = createBlockTag("convertable_to_fasciated_oxeye_daisy");
public static final TagKey<Block> CRIMSON_CLOVER_PLANTABLE_ON = createBlockTag("crimson_clover_plantable_on");
public static final TagKey<Block> JADE_VINE_PLANTABLE_ON = createBlockTag("jade_vine_plantable_on");
public static final TagKey<Block> RED_SPIDER_LILY_PLANTABLE_ON = createBlockTag("red_spider_lily_plantable_on");
public static final TagKey<Block> VINE_FLOWER_PLANTABLE_ON = createBlockTag("vine_flower_plantable_on");
}

public static final class EntityTypeTags
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ public BeachSpiderLilyBlock(Holder<MobEffect> effect, float seconds)
@Override
protected boolean mayPlaceOn(BlockState state, BlockGetter world, BlockPos pos)
{
return state.is(ModTags.BlockTags.BEACH_SPIDER_LILY_PLANTABLE_ON);
return state.is(ModTags.BlockTags.BEACH_FLOWER_PLANTABLE_ON);
}
}
Original file line number Diff line number Diff line change
@@ -1,204 +1,17 @@
package com.github.mechalopa.jafohana.world.level.block;

import java.util.Optional;

import javax.annotation.Nullable;

import com.github.mechalopa.jafohana.ModConfigs;
import com.github.mechalopa.jafohana.util.ModTags;
import com.github.mechalopa.jafohana.world.level.block.state.properties.JadeVinePart;
import com.github.mechalopa.jafohana.world.level.block.state.properties.ModBlockStateProperties;

import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.RandomSource;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.BonemealableBlock;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.EnumProperty;
import net.minecraft.world.level.material.MapColor;
import net.minecraft.world.level.material.PushReaction;

public class JadeVineBlock extends Block implements BonemealableBlock
public class JadeVineBlock extends VineFlowerBlock
{
public static final EnumProperty<JadeVinePart> PART = ModBlockStateProperties.JADE_VINE_PART;

public JadeVineBlock()
{
super(BlockBehaviour.Properties.of().mapColor(MapColor.PLANT).noCollission().instabreak().sound(SoundType.CAVE_VINES).offsetType(BlockBehaviour.OffsetType.XZ).ignitedByLava().pushReaction(PushReaction.DESTROY));
this.registerDefaultState(this.stateDefinition.any().setValue(PART, JadeVinePart.SINGLE));
}

@Override
public BlockState updateShape(BlockState state, Direction direction, BlockState state1, LevelAccessor levelAccerssor, BlockPos pos, BlockPos pos1)
{
if (direction == Direction.UP && !this.canSurvive(state, levelAccerssor, pos))
{
return Blocks.AIR.defaultBlockState();
}
else if (direction.getAxis() == Direction.Axis.Y)
{
if (levelAccerssor.getBlockState(pos.above()).is(this))
{
if (levelAccerssor.getBlockState(pos.below()).is(this))
{
return state.setValue(PART, JadeVinePart.LONG_BODY);
}
else if (levelAccerssor.getBlockState(pos.above(2)).is(this))
{
return state.setValue(PART, JadeVinePart.LONG_HEAD);
}
else
{
return state.setValue(PART, JadeVinePart.SHORT_HEAD);
}
}
else if (levelAccerssor.getBlockState(pos.below()).is(this))
{
if (levelAccerssor.getBlockState(pos.below(2)).is(this))
{
return state.setValue(PART, JadeVinePart.LONG_STEM);
}
else
{
return state.setValue(PART, JadeVinePart.SHORT_STEM);
}
}
else
{
return state.setValue(PART, JadeVinePart.SINGLE);
}
}
else
{
return super.updateShape(state, direction, state1, levelAccerssor, pos, pos1);
}
}

@Override
public boolean canSurvive(BlockState state, LevelReader levelReader, BlockPos pos)
{
BlockState state1 = levelReader.getBlockState(pos.above());
return state1.is(this) || state1.is(ModTags.BlockTags.JADE_VINE_PLANTABLE_ON);
}

@Nullable
@Override
public BlockState getStateForPlacement(BlockPlaceContext context)
{
BlockState state = this.defaultBlockState();
BlockPos pos = context.getClickedPos();
LevelReader levelReader = context.getLevel();

if (levelReader.getBlockState(pos.above()).is(this))
{
if (levelReader.getBlockState(pos.above(2)).is(this))
{
return state.setValue(PART, JadeVinePart.LONG_HEAD);
}
else
{
return state.setValue(PART, JadeVinePart.SHORT_HEAD);
}
}
else
{
return state.setValue(PART, JadeVinePart.SINGLE);
}
}

@Override
public boolean isValidBonemealTarget(LevelReader levelReader, BlockPos pos, BlockState state)
{
if (state.getValue(PART).isHead())
{
return this.canGrowInto(levelReader.getBlockState(pos.relative(Direction.DOWN)));
}
else
{
Optional<BlockPos> optional = this.getHeadPos(levelReader, pos, state.getBlock());
return optional.isPresent() && this.canGrowInto(levelReader.getBlockState(optional.get().relative(Direction.DOWN)));
}
}

@Override
public boolean isBonemealSuccess(Level level, RandomSource random, BlockPos pos, BlockState state)
{
return (double)level.getRandom().nextFloat() < ModConfigs.cachedServer.JADE_VINE_GROW_CHANCE;
}

@Override
public void performBonemeal(ServerLevel serverLevel, RandomSource random, BlockPos pos, BlockState state)
{
if (state.getValue(PART).isHead())
{
BlockPos pos1 = pos.relative(Direction.DOWN);
JadeVinePart jadevinepart = state.getValue(PART);
serverLevel.setBlockAndUpdate(pos1, state.setValue(PART, jadevinepart == JadeVinePart.SINGLE ? JadeVinePart.SHORT_HEAD : JadeVinePart.LONG_HEAD));
}
else
{
Optional<BlockPos> optional = this.getHeadPos(serverLevel, pos, state.getBlock());

if (optional.isPresent())
{
BlockState blockstate = serverLevel.getBlockState(optional.get());
((JadeVineBlock)blockstate.getBlock()).performBonemeal(serverLevel, random, optional.get(), blockstate);
}
}
}

protected boolean canGrowInto(BlockState state)
{
return state.isAir();
}

private Optional<BlockPos> getHeadPos(BlockGetter getter, BlockPos pos, Block p_153325_)
{
BlockPos.MutableBlockPos blockpos$mutableblockpos = pos.mutable();
BlockState blockstate;

do
{
blockpos$mutableblockpos.move(Direction.DOWN);
blockstate = getter.getBlockState(blockpos$mutableblockpos);
}
while (blockstate.is(this) && !blockstate.getValue(PART).isHead());

return (blockstate.is(this) && blockstate.getValue(PART).isHead()) ? Optional.of(blockpos$mutableblockpos) : Optional.empty();
}

@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder)
{
builder.add(PART);
}

@Override
public boolean isFlammable(BlockState state, BlockGetter getter, BlockPos pos, Direction direction)
{
return true;
}

@Override
public int getFlammability(BlockState state, BlockGetter getter, BlockPos pos, Direction direction)
{
return 60;
super();
}

@Override
public int getFireSpreadSpeed(BlockState state, BlockGetter getter, BlockPos pos, Direction direction)
public double getGrowChance()
{
return 15;
return ModConfigs.cachedServer.JADE_VINE_GROW_CHANCE;
}
}
Loading

0 comments on commit 05f40bc

Please sign in to comment.