Skip to content

Commit

Permalink
coconut place
Browse files Browse the repository at this point in the history
  • Loading branch information
AViewFromTheTop committed Dec 2, 2023
1 parent ed686f6 commit 3816726
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 230 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Bug Fixes & Changes
- Tweaked leaf decay distance to 10 in order to accommodate for Palm Fronds, so they now work like regular leaves
- Other leaf types will still cap out at 7, but can be changed with commands or a Debug Stick to go up to 10
- Removed the custom distance detection from Palm Crowns
- Reworked how Coconuts are placed on Palms
- Added Palm Crowns to tags it was missing from
- Added a translation string for Coconut projectiles
- Fixed compatibility between Wilder Wild's Stripped Logs and Create
Expand Down Expand Up @@ -60,6 +61,7 @@ Bug Fixes & Changes
- Swapped the placement of the Misc and Worldgen config tabs

- Refactored many aspects Wilder Wild's configured features' field names to be more consistent with Vanilla
- Replaced LeavesAroundTopTreeDecorator with CoconutTreeDecorator

- Removed the Fabric Loader version requirement in hopes it will fix issues with Quilt
- Changed the grammar of Wilder Wild's advancements to align with Vanilla's
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"state": {
"Name": "wilderwild:palm_fronds",
"Properties": {
"distance": "10",
"distance": "12",
"persistent": "false",
"waterlogged": "false"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,8 @@
"config": {
"decorators": [
{
"type": "wilderwild:leaves_around_top_decorator",
"directions": [
"down"
],
"empty_block_count_for_placement": 4,
"exclusion_radius_xz": 0,
"exclusion_radius_y": 0,
"probability": 0.25,
"state": {
"type": "minecraft:randomized_int_state_provider",
"property": "age",
"source": {
"type": "minecraft:simple_state_provider",
"state": {
"Name": "wilderwild:coconut",
"Properties": {
"age": "0",
"hanging": "true",
"stage": "0"
}
}
},
"values": 0
}
"type": "wilderwild:coconut_tree_decorator",
"placement_chance": 0.25
}
],
"dirt_provider": {
Expand Down Expand Up @@ -68,7 +46,7 @@
"state": {
"Name": "wilderwild:palm_fronds",
"Properties": {
"distance": "10",
"distance": "12",
"persistent": "false",
"waterlogged": "false"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"state": {
"Name": "wilderwild:palm_fronds",
"Properties": {
"distance": "10",
"distance": "12",
"persistent": "false",
"waterlogged": "false"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,8 @@
"config": {
"decorators": [
{
"type": "wilderwild:leaves_around_top_decorator",
"directions": [
"down"
],
"empty_block_count_for_placement": 4,
"exclusion_radius_xz": 0,
"exclusion_radius_y": 0,
"probability": 0.25,
"state": {
"type": "minecraft:randomized_int_state_provider",
"property": "age",
"source": {
"type": "minecraft:simple_state_provider",
"state": {
"Name": "wilderwild:coconut",
"Properties": {
"age": "0",
"hanging": "true",
"stage": "0"
}
}
},
"values": 0
}
"type": "wilderwild:coconut_tree_decorator",
"placement_chance": 0.25
}
],
"dirt_provider": {
Expand Down Expand Up @@ -68,7 +46,7 @@
"state": {
"Name": "wilderwild:palm_fronds",
"Properties": {
"distance": "10",
"distance": "12",
"persistent": "false",
"waterlogged": "false"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,8 @@
"config": {
"decorators": [
{
"type": "wilderwild:leaves_around_top_decorator",
"directions": [
"down"
],
"empty_block_count_for_placement": 4,
"exclusion_radius_xz": 0,
"exclusion_radius_y": 0,
"probability": 0.3,
"state": {
"type": "minecraft:randomized_int_state_provider",
"property": "age",
"source": {
"type": "minecraft:simple_state_provider",
"state": {
"Name": "wilderwild:coconut",
"Properties": {
"age": "0",
"hanging": "true",
"stage": "0"
}
}
},
"values": 0
}
"type": "wilderwild:coconut_tree_decorator",
"placement_chance": 0.3
}
],
"dirt_provider": {
Expand Down Expand Up @@ -55,7 +33,7 @@
"state": {
"Name": "wilderwild:palm_fronds",
"Properties": {
"distance": "10",
"distance": "12",
"persistent": "false",
"waterlogged": "false"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import net.frozenblock.wilderwild.world.generation.foliage.ShortPalmFoliagePlacer;
import net.frozenblock.wilderwild.world.generation.treedecorators.HeightBasedCobwebTreeDecorator;
import net.frozenblock.wilderwild.world.generation.treedecorators.HeightBasedVineTreeDecorator;
import net.frozenblock.wilderwild.world.generation.treedecorators.LeavesAroundTopTreeDecorator;
import net.frozenblock.wilderwild.world.generation.treedecorators.CoconutTreeDecorator;
import net.frozenblock.wilderwild.world.generation.treedecorators.MossCarpetTreeDecorator;
import net.frozenblock.wilderwild.world.generation.treedecorators.PollenTreeDecorator;
import net.frozenblock.wilderwild.world.generation.treedecorators.ShelfFungusTreeDecorator;
Expand Down Expand Up @@ -1238,19 +1238,8 @@ public static void registerTreeConfigured() {
9
).decorators(
List.of(
new LeavesAroundTopTreeDecorator(
0.25F,
0,
0,
new RandomizedIntStateProvider(
BlockStateProvider.simple(RegisterBlocks.COCONUT.defaultBlockState().setValue(BlockStateProperties.HANGING, true)),
CoconutBlock.AGE,
ConstantInt.of(0)
),
4,
List.of(
Direction.DOWN
)
new CoconutTreeDecorator(
0.25F
)
)
).dirt(BlockStateProvider.simple(Blocks.DIRT)).build()
Expand All @@ -1269,19 +1258,8 @@ public static void registerTreeConfigured() {
10
).decorators(
List.of(
new LeavesAroundTopTreeDecorator(
0.25F,
0,
0,
new RandomizedIntStateProvider(
BlockStateProvider.simple(RegisterBlocks.COCONUT.defaultBlockState().setValue(BlockStateProperties.HANGING, true)),
CoconutBlock.AGE,
ConstantInt.of(0)
),
4,
List.of(
Direction.DOWN
)
new CoconutTreeDecorator(
0.25F
)
)
).dirt(BlockStateProvider.simple(Blocks.DIRT)).build()
Expand All @@ -1308,19 +1286,8 @@ public static void registerTreeConfigured() {
2
).decorators(
List.of(
new LeavesAroundTopTreeDecorator(
0.3F,
0,
0,
new RandomizedIntStateProvider(
BlockStateProvider.simple(RegisterBlocks.COCONUT.defaultBlockState().setValue(BlockStateProperties.HANGING, true)),
CoconutBlock.AGE,
ConstantInt.of(0)
),
4,
List.of(
Direction.DOWN
)
new CoconutTreeDecorator(
0.3F
)
)
).dirt(BlockStateProvider.simple(Blocks.DIRT)).build()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Copyright 2023 FrozenBlock
* This file is part of Wilder Wild.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, see <https://www.gnu.org/licenses/>.
*/

package net.frozenblock.wilderwild.world.generation.treedecorators;

import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.frozenblock.wilderwild.registry.RegisterBlocks;
import net.minecraft.Util;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.levelgen.feature.treedecorators.TreeDecorator;
import net.minecraft.world.level.levelgen.feature.treedecorators.TreeDecoratorType;
import org.jetbrains.annotations.NotNull;

public class CoconutTreeDecorator extends TreeDecorator {
public static final Codec<CoconutTreeDecorator> CODEC = RecordCodecBuilder.create((instance) -> instance.group(
Codec.FLOAT.fieldOf("placement_chance").forGetter((treeDecorator) -> treeDecorator.placementChance)
).apply(instance, CoconutTreeDecorator::new));

private final float placementChance;

public CoconutTreeDecorator(float placementChance) {
this.placementChance = placementChance;
}

@Override
@NotNull
protected TreeDecoratorType<?> type() {
return WilderTreeDecorators.COCONUT_TREE_DECORATOR;
}

@Override
public void place(@NotNull Context context) {
RandomSource random = context.random();
BlockPos.MutableBlockPos mutableBlockPos = new BlockPos.MutableBlockPos();
BlockPos.MutableBlockPos mutableCheckBelowPos = new BlockPos.MutableBlockPos();

for (BlockPos blockPos : Util.shuffledCopy(context.leaves(), random)) {
mutableBlockPos.set(blockPos);
if (this.isEmptyBelow(context, mutableCheckBelowPos.set(mutableBlockPos)) && random.nextFloat() <= this.placementChance) {
context.setBlock(mutableBlockPos.move(Direction.DOWN, 1), RegisterBlocks.COCONUT.defaultBlockState().setValue(BlockStateProperties.HANGING, true));
}
}
}

private boolean isEmptyBelow(@NotNull TreeDecorator.Context context, @NotNull BlockPos.MutableBlockPos mutableBlockPos) {
return context.isAir(mutableBlockPos.set(mutableBlockPos).move(Direction.DOWN, 1));
}
}

Loading

0 comments on commit 3816726

Please sign in to comment.