Skip to content

Commit e7939f3

Browse files
committed
saccharine trees can now spawn with combee
1 parent 422ded9 commit e7939f3

5 files changed

Lines changed: 90 additions & 86 deletions

File tree

src/main/java/com/dtteam/dtcobblemon/branch/SaccharineBranchBlock.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public ItemInteractionResult useItemOn(ItemStack stack, BlockState state, Level
8484

8585
@Override @NotNull
8686
public VoxelShape getCollisionShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) {
87-
if (context instanceof EntityCollisionContext eContext && TreeHelper.getRadius(level, pos) < 8){
87+
if (context instanceof EntityCollisionContext eContext && TreeHelper.getRadius(level, pos) < 5){
8888
Entity entity = eContext.getEntity();
8989
if (entity instanceof MoLangScriptingEntity moEntity && moEntity.getConfig().getMap().getOrDefault("can_path_through_sacc_leaves", DoubleValue.ZERO).asDouble() == 1.0){
9090
return Shapes.empty();
Lines changed: 74 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,35 @@
11
package com.dtteam.dtcobblemon.genfeature;
22

3-
import com.dtteam.dtcobblemon.tree.SaccharineSpecies;
3+
import com.cobblemon.mod.common.api.pokemon.PokemonProperties;
4+
import com.cobblemon.mod.common.entity.pokemon.PokemonEntity;
45
import com.dtteam.dynamictrees.api.configuration.ConfigurationProperty;
56
import com.dtteam.dynamictrees.systems.genfeature.BeeNestGenFeature;
67
import com.dtteam.dynamictrees.systems.genfeature.GenFeatureConfiguration;
78
import net.minecraft.core.BlockPos;
9+
import net.minecraft.core.Direction;
810
import net.minecraft.resources.ResourceLocation;
11+
import net.minecraft.server.level.WorldGenRegion;
912
import net.minecraft.tags.BlockTags;
13+
import net.minecraft.util.RandomSource;
14+
import net.minecraft.world.level.LevelAccessor;
15+
import net.minecraft.world.level.block.BeehiveBlock;
16+
import net.minecraft.world.level.block.Block;
1017
import net.minecraft.world.level.block.Blocks;
18+
import net.minecraft.world.level.block.entity.BlockEntityType;
19+
import net.minecraft.world.level.block.state.BlockState;
20+
import org.apache.commons.lang3.tuple.Pair;
1121
import org.jetbrains.annotations.NotNull;
1222

23+
import java.util.List;
24+
1325
public class SaccharineBeeNestGenFeature extends BeeNestGenFeature {
1426

15-
public static final ConfigurationProperty<Integer> COMBEE_CHANCE = ConfigurationProperty.integer("combee_chance");
27+
public static final ConfigurationProperty<Float> COMBEE_PROBABILITY = ConfigurationProperty.floatProperty("combee_probability");
28+
public static final ConfigurationProperty<Integer> COMBEE_MIN_LEVEL = ConfigurationProperty.integer("combee_min_level");
29+
public static final ConfigurationProperty<Integer> COMBEE_MAX_LEVEL = ConfigurationProperty.integer("combee_max_level");
30+
private static final String PokemonArgs = "combee";
31+
public static double BeeNestWorldGenChance = 0.5;
32+
public static double BeeNestGrowChance = 0.1;
1633

1734
public SaccharineBeeNestGenFeature(ResourceLocation registryName) {
1835
super(registryName);
@@ -21,55 +38,74 @@ public SaccharineBeeNestGenFeature(ResourceLocation registryName) {
2138
@Override
2239
protected void registerProperties() {
2340
super.registerProperties();
24-
this.register(COMBEE_CHANCE);
41+
this.register(COMBEE_PROBABILITY, COMBEE_MIN_LEVEL, COMBEE_MAX_LEVEL);
2542
}
2643

2744
@Override @NotNull
2845
public GenFeatureConfiguration createDefaultConfiguration() {
2946
return super.createDefaultConfiguration()
3047
.with(NEST_BLOCK, Blocks.BEE_NEST)
3148
.with(MAX_HEIGHT, 32)
32-
.with(COMBEE_CHANCE, 2)
49+
.with(COMBEE_PROBABILITY, 0.5f)
50+
.with(COMBEE_MIN_LEVEL, 5)
51+
.with(COMBEE_MAX_LEVEL, 15)
3352
.with(CAN_GROW_PREDICATE, (world, pos) -> {
34-
if (world.getRandom().nextFloat() > SaccharineSpecies.BeeNestGrowChance) {
35-
return false;
36-
}
37-
// Default flower check predicate, straight from AbstractTreeGrower
53+
if (world.getRandom().nextFloat() > BeeNestGrowChance) return false;
3854
for (BlockPos blockpos : BlockPos.betweenClosed(pos.below().north(2).west(2), pos.above().south(2).east(2))) {
39-
if (world.getBlockState(blockpos).is(BlockTags.FLOWERS)) {
40-
return true;
41-
}
55+
if (world.getBlockState(blockpos).is(BlockTags.FLOWERS)) return true;
4256
}
4357
return false;
4458
})
45-
.with(WORLD_GEN_CHANCE_FUNCTION, (world, pos) -> SaccharineSpecies.BeeNestWorldGenChance)
59+
.with(WORLD_GEN_CHANCE_FUNCTION, (world, pos) -> BeeNestWorldGenChance)
4660
.with(MAX_COUNT, 1);
4761
}
4862

49-
//TODO: later, it crashes on Cobblemon's side for some reason.
50-
// @Override
51-
// @SuppressWarnings("deprecation")
52-
// protected boolean placeBeeNestWithBees(LevelAccessor world, Block nestBlock, BlockPos pos, Direction faceDir, boolean worldGen, RandomSource random) {
53-
// BlockState nestState = nestBlock.defaultBlockState();
54-
// if (nestState.hasProperty(BeehiveBlock.FACING)) {
55-
// nestState = nestState.setValue(BeehiveBlock.FACING, faceDir);
56-
// }
57-
// world.setBlock(pos, nestState, 3);
58-
// world.getBlockEntity(pos, BlockEntityType.BEEHIVE).ifPresent((blockEntity) -> {
59-
// int j = 2 + random.nextInt(2);
60-
// int isCombee = random.nextInt(2);
61-
// for(int k = 0; k < j; ++k) {
62-
// if (isCombee == 0 && world instanceof WorldGenRegion level){
63-
// String properties = "${POKEMON_ARGS} lvl=${LEVEL_RANGE.random()}";
64-
// PokemonProperties pokemon = PokemonProperties.Companion.parse(properties);
65-
// PokemonEntity entity = pokemon.createEntity(level.getLevel());
66-
// blockEntity.addOccupant(entity);
67-
// } else {
68-
// storeBee(random, blockEntity);
69-
// }
70-
// }
71-
//
72-
// });
73-
// return true;
74-
// }
63+
@Override
64+
protected boolean placeBeeNestInValidPlace(GenFeatureConfiguration configuration, LevelAccessor world, BlockPos rootPos, boolean worldGen, RandomSource random) {
65+
Block nestBlock = configuration.get(NEST_BLOCK);
66+
67+
int treeHeight = getTreeHeight(world, rootPos, configuration.get(MAX_HEIGHT));
68+
if (nestAlreadyPresent(world, nestBlock, rootPos, treeHeight)) {
69+
return false;
70+
}
71+
List<Pair<BlockPos, List<Direction>>> validSpaces = findBranchPits(configuration, world, rootPos, treeHeight);
72+
if (validSpaces == null) {
73+
return false;
74+
}
75+
if (!validSpaces.isEmpty()) {
76+
Pair<BlockPos, List<Direction>> chosenSpace = validSpaces.get(world.getRandom().nextInt(validSpaces.size()));
77+
Direction chosenDir = chosenSpace.getValue().get(world.getRandom().nextInt(chosenSpace.getValue().size()));
78+
79+
return placeBeeNestWithBees(configuration, world, nestBlock, chosenSpace.getKey(), chosenDir, worldGen, random);
80+
}
81+
return false;
82+
}
83+
84+
@SuppressWarnings("deprecation")
85+
private boolean placeBeeNestWithBees(GenFeatureConfiguration configuration, LevelAccessor world, Block nestBlock, BlockPos pos, Direction faceDir, boolean worldGen, RandomSource random) {
86+
BlockState nestState = nestBlock.defaultBlockState();
87+
if (nestState.hasProperty(BeehiveBlock.FACING)) {
88+
nestState = nestState.setValue(BeehiveBlock.FACING, faceDir);
89+
}
90+
float combeeChance = configuration.get(COMBEE_PROBABILITY);
91+
int combeeMinLevel = configuration.get(COMBEE_MIN_LEVEL);
92+
int combeeMaxLevel = configuration.get(COMBEE_MAX_LEVEL);
93+
world.setBlock(pos, nestState, 3);
94+
world.getBlockEntity(pos, BlockEntityType.BEEHIVE).ifPresent((blockEntity) -> {
95+
int j = 2 + random.nextInt(2);
96+
float isCombee = random.nextFloat();
97+
for(int k = 0; k < j; ++k) {
98+
if (isCombee < combeeChance && world instanceof WorldGenRegion level){
99+
String properties = PokemonArgs+" lvl="+(combeeMinLevel + random.nextInt(combeeMaxLevel-combeeMinLevel+1));
100+
PokemonProperties pokemon = PokemonProperties.Companion.parse(properties);
101+
PokemonEntity entity = pokemon.createEntity(level.getLevel());
102+
blockEntity.addOccupant(entity);
103+
} else {
104+
storeBee(random, blockEntity);
105+
}
106+
}
107+
108+
});
109+
return true;
110+
}
75111
}

src/main/java/com/dtteam/dtcobblemon/init/DTCobblemonRegistries.java

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,35 +6,15 @@
66
import com.dtteam.dtcobblemon.leaves.DTCobblemonCellKits;
77
import com.dtteam.dtcobblemon.leaves.SaccharineLeavesProperties;
88
import com.dtteam.dtcobblemon.tree.SaccharineFamily;
9-
import com.dtteam.dtcobblemon.tree.SaccharineSpecies;
109
import com.dtteam.dynamictrees.api.cell.CellKit;
1110
import com.dtteam.dynamictrees.block.fruit.Fruit;
1211
import com.dtteam.dynamictrees.block.leaves.LeavesProperties;
1312
import com.dtteam.dynamictrees.event.RegistryEvent;
1413
import com.dtteam.dynamictrees.event.TypeRegistryEvent;
15-
import com.dtteam.dynamictrees.systems.cell.CellKits;
16-
import com.dtteam.dynamictrees.systems.genfeature.BeeNestGenFeature;
1714
import com.dtteam.dynamictrees.systems.genfeature.GenFeature;
18-
import com.dtteam.dynamictrees.systems.genfeature.GenFeatureConfiguration;
1915
import com.dtteam.dynamictrees.tree.family.Family;
20-
import com.dtteam.dynamictrees.tree.species.Species;
21-
import net.minecraft.core.BlockPos;
22-
import net.minecraft.core.Direction;
23-
import net.minecraft.tags.BlockTags;
24-
import net.minecraft.util.RandomSource;
25-
import net.minecraft.world.level.LevelAccessor;
26-
import net.minecraft.world.level.block.BeehiveBlock;
27-
import net.minecraft.world.level.block.Block;
28-
import net.minecraft.world.level.block.Blocks;
29-
import net.minecraft.world.level.block.entity.BeehiveBlockEntity;
30-
import net.minecraft.world.level.block.entity.BlockEntityType;
31-
import net.minecraft.world.level.block.state.BlockState;
3216
import net.neoforged.bus.api.SubscribeEvent;
3317
import net.neoforged.fml.common.EventBusSubscriber;
34-
import org.apache.commons.lang3.tuple.Pair;
35-
import org.jetbrains.annotations.NotNull;
36-
37-
import java.util.List;
3818

3919
@EventBusSubscriber(modid = DynamicTreesCobblemon.MOD_ID)
4020
public class DTCobblemonRegistries {
@@ -46,12 +26,12 @@ public static void registerFruitTypes(TypeRegistryEvent<Fruit> event) {
4626
}
4727
}
4828

49-
@SubscribeEvent
50-
public static void registerSpeciesTypes(TypeRegistryEvent<Species> event) {
51-
if (event.isEntryOfType(Species.class)){
52-
event.registerType(DynamicTreesCobblemon.location("saccharine"), SaccharineSpecies.TYPE);
53-
}
54-
}
29+
// @SubscribeEvent
30+
// public static void registerSpeciesTypes(TypeRegistryEvent<Species> event) {
31+
// if (event.isEntryOfType(Species.class)){
32+
//
33+
// }
34+
// }
5535

5636
@SubscribeEvent
5737
public static void registerFamilyTypes(TypeRegistryEvent<Family> event) {

src/main/java/com/dtteam/dtcobblemon/tree/SaccharineSpecies.java

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/main/resources/trees/dtcobblemon/species/saccharine.json

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
2-
"type": "dtcobblemon:saccharine",
32
"family": "dtcobblemon:saccharine",
4-
"tapering": 0.5,
3+
"tapering": 0.4,
54
"signal_energy": 12.0,
65
"up_probability": 3,
76
"lowest_branch_height": 3,
@@ -19,7 +18,14 @@
1918
"acceptable_soils": ["dirt_like"],
2019
"world_gen_acceptable_soils": ["snow_like"],
2120
"features" : [
22-
"dtcobblemon:saccharine_bee_nest"
21+
{
22+
"name": "dtcobblemon:saccharine_bee_nest",
23+
"properties": {
24+
"combee_probability": 0.5,
25+
"combee_min_level": 5,
26+
"combee_max_level": 15
27+
}
28+
}
2329
],
2430
"lang_overrides": {
2531
"seed": "Saccharine Cone"

0 commit comments

Comments
 (0)