From 38d6404b62d080dcd23ea4d202f8cd55f80fad00 Mon Sep 17 00:00:00 2001 From: Flanks255 <32142731+Flanks255@users.noreply.github.com> Date: Thu, 28 Nov 2024 17:08:33 -0600 Subject: [PATCH] Fixed worldgenned plants popping off when blockupdated. --- .../103d9f3f36b01595f1aa5172191e60eff02e6924 | 8 +++---- .../20d9b6419a057e67e5bca6ce3a3de93ccc3382bf | 3 ++- .../configured_feature/canola_patch.json | 3 ++- .../configured_feature/coffee_patch.json | 3 ++- .../configured_feature/flax_patch.json | 3 ++- .../mod/blocks/base/AACrops.java | 24 ++++++++++++++++++- .../mod/gen/ActuallyConfiguredFeatures.java | 2 +- .../mod/items/ItemWingsOfTheBats.java | 2 +- 8 files changed, 37 insertions(+), 11 deletions(-) diff --git a/src/generated/resources/.cache/103d9f3f36b01595f1aa5172191e60eff02e6924 b/src/generated/resources/.cache/103d9f3f36b01595f1aa5172191e60eff02e6924 index d08d55f66..d1134e05d 100644 --- a/src/generated/resources/.cache/103d9f3f36b01595f1aa5172191e60eff02e6924 +++ b/src/generated/resources/.cache/103d9f3f36b01595f1aa5172191e60eff02e6924 @@ -1,4 +1,4 @@ -// 1.21.1 2024-10-22T22:13:28.2925645 Registries +// 1.21.1 2024-11-28T16:44:16.4483104 Registries 74628b34b75e1a2fa2ac1f6282b7d9d4e155c254 data/actuallyadditions/banner_pattern/book.json 899dfa1e0d0b15ffc090605543ec144bbfcacc4c data/actuallyadditions/banner_pattern/drill.json 7d9a33a9a151ad83de36e9af8822d08c86137adc data/actuallyadditions/banner_pattern/leaf_blo.json @@ -8,9 +8,9 @@ 360756e7cd20afc4c6b2ad58b2fd4f37358f2ee6 data/actuallyadditions/neoforge/biome_modifier/add_canola.json 0f06d7aad676a45a4ca187552ac8c4bbd6f1b1b7 data/actuallyadditions/neoforge/biome_modifier/add_coffee.json 1401a66bbf2e1daaa459381103ffba9d02be352d data/actuallyadditions/neoforge/biome_modifier/add_flax.json -dceca4be717b43a4dfc945f62f5c09622604d7f4 data/actuallyadditions/worldgen/configured_feature/canola_patch.json -d56ed72dde226d9ac5eb07fa701f7a3902f1dcf2 data/actuallyadditions/worldgen/configured_feature/coffee_patch.json -9a42d5943e40d102c5e9efee988527da3622d88d data/actuallyadditions/worldgen/configured_feature/flax_patch.json +a9f260aa69d01d64a6332df904d1164e14990663 data/actuallyadditions/worldgen/configured_feature/canola_patch.json +5dbbd50693c6463bf8b45997e3163fb5beb99b0a data/actuallyadditions/worldgen/configured_feature/coffee_patch.json +7e6f0a47b395a141247d1fdfce0de2d9ef6abf36 data/actuallyadditions/worldgen/configured_feature/flax_patch.json 80765c24aa747df53139d14a9ac3293b4b3eab16 data/actuallyadditions/worldgen/configured_feature/ore_black_quartz.json 0401f9a4edd53ed76536a2c050364a6a442185bd data/actuallyadditions/worldgen/placed_feature/canola_patch.json d7358c6519319ed3950dcdc34102504c53ccaf22 data/actuallyadditions/worldgen/placed_feature/coffee_patch.json diff --git a/src/generated/resources/.cache/20d9b6419a057e67e5bca6ce3a3de93ccc3382bf b/src/generated/resources/.cache/20d9b6419a057e67e5bca6ce3a3de93ccc3382bf index 850451f67..02fadae59 100644 --- a/src/generated/resources/.cache/20d9b6419a057e67e5bca6ce3a3de93ccc3382bf +++ b/src/generated/resources/.cache/20d9b6419a057e67e5bca6ce3a3de93ccc3382bf @@ -1 +1,2 @@ -// 1.21.1 2024-10-22T20:41:07.9123026 Update structure files in /structure/ +// 1.21.1 2024-11-28T16:44:16.4503165 Update structure files in /structure/ +be1261b16ca6da9123934a123abb191d64ed46b8 data/actuallyadditions/structure/andrew_period_house.nbt diff --git a/src/generated/resources/data/actuallyadditions/worldgen/configured_feature/canola_patch.json b/src/generated/resources/data/actuallyadditions/worldgen/configured_feature/canola_patch.json index 296139aff..c565a2c90 100644 --- a/src/generated/resources/data/actuallyadditions/worldgen/configured_feature/canola_patch.json +++ b/src/generated/resources/data/actuallyadditions/worldgen/configured_feature/canola_patch.json @@ -10,7 +10,8 @@ "state": { "Name": "actuallyadditions:canola", "Properties": { - "age": "7" + "age": "7", + "persistent": "true" } } } diff --git a/src/generated/resources/data/actuallyadditions/worldgen/configured_feature/coffee_patch.json b/src/generated/resources/data/actuallyadditions/worldgen/configured_feature/coffee_patch.json index 77b85fc67..d944c3abe 100644 --- a/src/generated/resources/data/actuallyadditions/worldgen/configured_feature/coffee_patch.json +++ b/src/generated/resources/data/actuallyadditions/worldgen/configured_feature/coffee_patch.json @@ -10,7 +10,8 @@ "state": { "Name": "actuallyadditions:coffee", "Properties": { - "age": "7" + "age": "7", + "persistent": "true" } } } diff --git a/src/generated/resources/data/actuallyadditions/worldgen/configured_feature/flax_patch.json b/src/generated/resources/data/actuallyadditions/worldgen/configured_feature/flax_patch.json index ee29d4485..12bba103e 100644 --- a/src/generated/resources/data/actuallyadditions/worldgen/configured_feature/flax_patch.json +++ b/src/generated/resources/data/actuallyadditions/worldgen/configured_feature/flax_patch.json @@ -10,7 +10,8 @@ "state": { "Name": "actuallyadditions:flax", "Properties": { - "age": "7" + "age": "7", + "persistent": "true" } } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/base/AACrops.java b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/base/AACrops.java index 8bd81923d..b826e63cd 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/base/AACrops.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/base/AACrops.java @@ -6,28 +6,50 @@ import net.minecraft.tags.BlockTags; import net.minecraft.world.item.Item; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.ItemLike; +import net.minecraft.world.level.LevelReader; +import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.CropBlock; import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.StateDefinition; +import net.minecraft.world.level.block.state.properties.BooleanProperty; +import javax.annotation.Nonnull; import java.util.function.Supplier; public class AACrops extends CropBlock { Supplier itemSupplier; + + public static final BooleanProperty PERSISTENT = BooleanProperty.create("persistent"); public AACrops(Properties properties, Supplier seedSupplier) { super(properties); this.itemSupplier = seedSupplier; + + this.registerDefaultState(this.stateDefinition.any().setValue(AGE, 0).setValue(PERSISTENT, false)); } + @Nonnull @Override protected ItemLike getBaseSeedId() { return this.itemSupplier.get(); } @Override - protected boolean mayPlaceOn(BlockState state, BlockGetter level, BlockPos pos) { + protected boolean mayPlaceOn(@Nonnull BlockState state, @Nonnull BlockGetter level, @Nonnull BlockPos pos) { if (level instanceof WorldGenRegion) { return state.is(BlockTags.DIRT); } return super.mayPlaceOn(state, level, pos); } + + @Override + protected boolean canSurvive(@Nonnull BlockState state, @Nonnull LevelReader level, @Nonnull BlockPos pos) { + if (!(level instanceof WorldGenRegion) && state.getValue(PERSISTENT) && !level.getBlockState(pos.below()).isAir()) + return true; + return super.canSurvive(state, level, pos); + } + + @Override + protected void createBlockStateDefinition(StateDefinition.Builder builder) { + builder.add(AGE, PERSISTENT); + } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/gen/ActuallyConfiguredFeatures.java b/src/main/java/de/ellpeck/actuallyadditions/mod/gen/ActuallyConfiguredFeatures.java index 026cd31ef..407714e1b 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/gen/ActuallyConfiguredFeatures.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/gen/ActuallyConfiguredFeatures.java @@ -41,7 +41,7 @@ public class ActuallyConfiguredFeatures { } private static RandomPatchConfiguration plantPatch(Block crop, int tries) { - BlockStateProvider stateProvider = BlockStateProvider.simple(crop.defaultBlockState().setValue(AACrops.AGE, AACrops.MAX_AGE)); + BlockStateProvider stateProvider = BlockStateProvider.simple(crop.defaultBlockState().setValue(AACrops.AGE, AACrops.MAX_AGE).setValue(AACrops.PERSISTENT, true)); return FeatureUtils.simpleRandomPatchConfiguration( tries, PlacementUtils.onlyWhenEmpty(Feature.SIMPLE_BLOCK, new SimpleBlockConfiguration(stateProvider)) ); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemWingsOfTheBats.java b/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemWingsOfTheBats.java index 07940accc..992c64c8d 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemWingsOfTheBats.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemWingsOfTheBats.java @@ -115,7 +115,7 @@ public class ItemWingsOfTheBats extends ItemBase { public void livingUpdateEvent(PlayerTickEvent.Post event) { if (event.getEntity() instanceof Player player) { - if (false &&!player.isCreative() && !player.isSpectator()) { //TODO disabled for now. + if (false &&!player.isCreative() && !player.isSpectator()) { //TODO disabled for now. PlayerData.PlayerSave data = PlayerData.getDataFromPlayer(player); if (!player.level().isClientSide) {