From 38167265ad32eaf6c56a5f5f3be62e8604da64cd Mon Sep 17 00:00:00 2001
From: AViewFromTheTop <87103914+AViewFromTheTop@users.noreply.github.com>
Date: Fri, 1 Dec 2023 21:43:33 -0500
Subject: [PATCH] coconut place
---
CHANGELOG.md | 2 +
.../configured_feature/fallen_palm.json | 2 +-
.../worldgen/configured_feature/palm.json | 28 +----
.../configured_feature/small_wine_palm.json | 2 +-
.../configured_feature/tall_palm.json | 28 +----
.../configured_feature/tall_wine_palm.json | 28 +----
.../feature/WilderTreeConfigured.java | 47 ++------
.../treedecorators/CoconutTreeDecorator.java | 68 +++++++++++
.../LeavesAroundTopTreeDecorator.java | 112 ------------------
.../treedecorators/WilderTreeDecorators.java | 2 +-
10 files changed, 89 insertions(+), 230 deletions(-)
create mode 100644 src/main/java/net/frozenblock/wilderwild/world/generation/treedecorators/CoconutTreeDecorator.java
delete mode 100644 src/main/java/net/frozenblock/wilderwild/world/generation/treedecorators/LeavesAroundTopTreeDecorator.java
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 04259c9d8c..708408114b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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
@@ -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
diff --git a/src/main/generated/data/wilderwild/worldgen/configured_feature/fallen_palm.json b/src/main/generated/data/wilderwild/worldgen/configured_feature/fallen_palm.json
index da90804812..d4ce063b11 100644
--- a/src/main/generated/data/wilderwild/worldgen/configured_feature/fallen_palm.json
+++ b/src/main/generated/data/wilderwild/worldgen/configured_feature/fallen_palm.json
@@ -31,7 +31,7 @@
"state": {
"Name": "wilderwild:palm_fronds",
"Properties": {
- "distance": "10",
+ "distance": "12",
"persistent": "false",
"waterlogged": "false"
}
diff --git a/src/main/generated/data/wilderwild/worldgen/configured_feature/palm.json b/src/main/generated/data/wilderwild/worldgen/configured_feature/palm.json
index d8ae6ef210..68805fc426 100644
--- a/src/main/generated/data/wilderwild/worldgen/configured_feature/palm.json
+++ b/src/main/generated/data/wilderwild/worldgen/configured_feature/palm.json
@@ -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": {
@@ -68,7 +46,7 @@
"state": {
"Name": "wilderwild:palm_fronds",
"Properties": {
- "distance": "10",
+ "distance": "12",
"persistent": "false",
"waterlogged": "false"
}
diff --git a/src/main/generated/data/wilderwild/worldgen/configured_feature/small_wine_palm.json b/src/main/generated/data/wilderwild/worldgen/configured_feature/small_wine_palm.json
index 28c3b43afe..631a8df713 100644
--- a/src/main/generated/data/wilderwild/worldgen/configured_feature/small_wine_palm.json
+++ b/src/main/generated/data/wilderwild/worldgen/configured_feature/small_wine_palm.json
@@ -28,7 +28,7 @@
"state": {
"Name": "wilderwild:palm_fronds",
"Properties": {
- "distance": "10",
+ "distance": "12",
"persistent": "false",
"waterlogged": "false"
}
diff --git a/src/main/generated/data/wilderwild/worldgen/configured_feature/tall_palm.json b/src/main/generated/data/wilderwild/worldgen/configured_feature/tall_palm.json
index 7d348a55bd..93cc647803 100644
--- a/src/main/generated/data/wilderwild/worldgen/configured_feature/tall_palm.json
+++ b/src/main/generated/data/wilderwild/worldgen/configured_feature/tall_palm.json
@@ -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": {
@@ -68,7 +46,7 @@
"state": {
"Name": "wilderwild:palm_fronds",
"Properties": {
- "distance": "10",
+ "distance": "12",
"persistent": "false",
"waterlogged": "false"
}
diff --git a/src/main/generated/data/wilderwild/worldgen/configured_feature/tall_wine_palm.json b/src/main/generated/data/wilderwild/worldgen/configured_feature/tall_wine_palm.json
index f5d56ea84e..131816b287 100644
--- a/src/main/generated/data/wilderwild/worldgen/configured_feature/tall_wine_palm.json
+++ b/src/main/generated/data/wilderwild/worldgen/configured_feature/tall_wine_palm.json
@@ -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": {
@@ -55,7 +33,7 @@
"state": {
"Name": "wilderwild:palm_fronds",
"Properties": {
- "distance": "10",
+ "distance": "12",
"persistent": "false",
"waterlogged": "false"
}
diff --git a/src/main/java/net/frozenblock/wilderwild/world/additions/feature/WilderTreeConfigured.java b/src/main/java/net/frozenblock/wilderwild/world/additions/feature/WilderTreeConfigured.java
index 8571357103..0972874481 100644
--- a/src/main/java/net/frozenblock/wilderwild/world/additions/feature/WilderTreeConfigured.java
+++ b/src/main/java/net/frozenblock/wilderwild/world/additions/feature/WilderTreeConfigured.java
@@ -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;
@@ -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()
@@ -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()
@@ -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()
diff --git a/src/main/java/net/frozenblock/wilderwild/world/generation/treedecorators/CoconutTreeDecorator.java b/src/main/java/net/frozenblock/wilderwild/world/generation/treedecorators/CoconutTreeDecorator.java
new file mode 100644
index 0000000000..09fbca651e
--- /dev/null
+++ b/src/main/java/net/frozenblock/wilderwild/world/generation/treedecorators/CoconutTreeDecorator.java
@@ -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 .
+ */
+
+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 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));
+ }
+}
+
diff --git a/src/main/java/net/frozenblock/wilderwild/world/generation/treedecorators/LeavesAroundTopTreeDecorator.java b/src/main/java/net/frozenblock/wilderwild/world/generation/treedecorators/LeavesAroundTopTreeDecorator.java
deleted file mode 100644
index 72ce5a6e16..0000000000
--- a/src/main/java/net/frozenblock/wilderwild/world/generation/treedecorators/LeavesAroundTopTreeDecorator.java
+++ /dev/null
@@ -1,112 +0,0 @@
-/*
- * 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 .
- */
-
-package net.frozenblock.wilderwild.world.generation.treedecorators;
-
-import com.mojang.serialization.Codec;
-import com.mojang.serialization.codecs.RecordCodecBuilder;
-import java.util.HashSet;
-import java.util.List;
-import net.minecraft.Util;
-import net.minecraft.core.BlockPos;
-import net.minecraft.core.Direction;
-import net.minecraft.util.ExtraCodecs;
-import net.minecraft.util.RandomSource;
-import net.minecraft.world.level.levelgen.feature.stateproviders.BlockStateProvider;
-import net.minecraft.world.level.levelgen.feature.treedecorators.TreeDecorator;
-import net.minecraft.world.level.levelgen.feature.treedecorators.TreeDecoratorType;
-import net.minecraft.world.phys.Vec3;
-import org.jetbrains.annotations.NotNull;
-
-public class LeavesAroundTopTreeDecorator extends TreeDecorator {
- public static final Codec CODEC = RecordCodecBuilder.create((instance) -> instance.group(
- Codec.FLOAT.fieldOf("probability").forGetter((treeDecorator) -> treeDecorator.probability),
- Codec.intRange(0, 16).fieldOf("exclusion_radius_xz").forGetter((treeDecorator) -> treeDecorator.exclusionRadiusXZ),
- Codec.intRange(0, 16).fieldOf("exclusion_radius_y").forGetter((treeDecorator) -> treeDecorator.exclusionRadiusY),
- BlockStateProvider.CODEC.fieldOf("state").forGetter((treeDecorator) -> treeDecorator.state),
- Codec.INT.fieldOf("empty_block_count_for_placement").forGetter((treeDecorator) -> treeDecorator.emptyBlockCountForPlacement),
- ExtraCodecs.nonEmptyList(Direction.CODEC.listOf()).fieldOf("directions").forGetter((treeDecorator) -> treeDecorator.directions)
- ).apply(instance, LeavesAroundTopTreeDecorator::new));
-
- private final float probability;
- private final int exclusionRadiusXZ;
- private final int exclusionRadiusY;
- private final BlockStateProvider state;
- private final int emptyBlockCountForPlacement;
- private final List directions;
-
- public LeavesAroundTopTreeDecorator(float probability, int exclusionRadiusXZ, int exclusionRadiusY, @NotNull BlockStateProvider state, int emptyBlockCountForPlacement, @NotNull List directions) {
- this.probability = probability;
- this.exclusionRadiusXZ = exclusionRadiusXZ;
- this.exclusionRadiusY = exclusionRadiusY;
- this.state = state;
- this.emptyBlockCountForPlacement = emptyBlockCountForPlacement;
- this.directions = directions;
- }
-
- @Override
- @NotNull
- protected TreeDecoratorType> type() {
- return WilderTreeDecorators.LEAVES_AROUND_TOP_TREE_DECORATOR;
- }
-
- @Override
- public void place(@NotNull Context context) {
- BlockPos highestPos = context.logs().get(1);
- for (BlockPos logPos : context.logs()) {
- if (logPos.getY() > highestPos.getY()) {
- highestPos = logPos;
- }
- }
- HashSet set = new HashSet<>();
- RandomSource randomSource = context.random();
- Vec3 highPos = new Vec3(highestPos.getX() + 0.5, highestPos.getY() + 0.5, highestPos.getZ() + 0.5);
- BlockPos.MutableBlockPos mutableBlockPos = new BlockPos.MutableBlockPos();
- BlockPos.MutableBlockPos mutableBlockPos2 = new BlockPos.MutableBlockPos();
- BlockPos.MutableBlockPos mutableBlockPos3 = new BlockPos.MutableBlockPos();
- BlockPos.MutableBlockPos mutableCheckPos = new BlockPos.MutableBlockPos();
-
- for (BlockPos blockPos : Util.shuffledCopy(context.leaves(), randomSource)) {
- if (((int) (Math.sqrt(blockPos.distToCenterSqr(highPos)))) <= 2) {
- Direction direction;
- mutableBlockPos.setWithOffset(blockPos, direction = Util.getRandom(this.directions, randomSource));
- if (set.contains(mutableBlockPos) || !(randomSource.nextFloat() < this.probability) || !this.hasRequiredEmptyBlocks(context, blockPos, mutableCheckPos, direction))
- continue;
-
- for (BlockPos blockPos5 : BlockPos.betweenClosed(
- mutableBlockPos2.setWithOffset(mutableCheckPos, -this.exclusionRadiusXZ, -this.exclusionRadiusY, -this.exclusionRadiusXZ),
- mutableBlockPos3.setWithOffset(mutableCheckPos, this.exclusionRadiusXZ, this.exclusionRadiusY, this.exclusionRadiusXZ)
- )
- ) {
- set.add(blockPos5);
- }
- context.setBlock(mutableBlockPos, this.state.getState(randomSource, mutableBlockPos));
- }
- }
- }
-
- private boolean hasRequiredEmptyBlocks(@NotNull TreeDecorator.Context context, @NotNull BlockPos pos, @NotNull BlockPos.MutableBlockPos mutableBlockPos, @NotNull Direction direction) {
- for (int i = 1; i <= this.emptyBlockCountForPlacement; ++i) {
- mutableBlockPos.set(pos).move(direction, i);
- if (context.isAir(mutableBlockPos)) continue;
- return false;
- }
- return true;
- }
-}
-
diff --git a/src/main/java/net/frozenblock/wilderwild/world/generation/treedecorators/WilderTreeDecorators.java b/src/main/java/net/frozenblock/wilderwild/world/generation/treedecorators/WilderTreeDecorators.java
index cd5c4108a5..7555cc2a78 100644
--- a/src/main/java/net/frozenblock/wilderwild/world/generation/treedecorators/WilderTreeDecorators.java
+++ b/src/main/java/net/frozenblock/wilderwild/world/generation/treedecorators/WilderTreeDecorators.java
@@ -29,7 +29,7 @@
public final class WilderTreeDecorators {
public static final TreeDecoratorType FUNGUS_TREE_DECORATOR = register("shelf_fungus_tree_decorator", ShelfFungusTreeDecorator.CODEC);
public static final TreeDecoratorType HEIGHT_BASED_VINE_TREE_DECORATOR = register("height_based_vine_tree_decorator", HeightBasedVineTreeDecorator.CODEC);
- public static final TreeDecoratorType LEAVES_AROUND_TOP_TREE_DECORATOR = register("leaves_around_top_decorator", LeavesAroundTopTreeDecorator.CODEC);
+ public static final TreeDecoratorType COCONUT_TREE_DECORATOR = register("coconut_tree_decorator", CoconutTreeDecorator.CODEC);
public static final TreeDecoratorType HEIGHT_BASED_COBWEB_TREE_DECORATOR = register("height_based_cobweb_tree_decorator", HeightBasedCobwebTreeDecorator.CODEC);
public static final TreeDecoratorType POLLEN_TREE_DECORATOR = register("pollen_tree_decorator", PollenTreeDecorator.CODEC);
public static final TreeDecoratorType MOSS_CARPET_TREE_DECORATOR = register("moss_carpet_tree_decorator", MossCarpetTreeDecorator.CODEC);