Skip to content

Commit

Permalink
fix Ancient Sapling not being connected to a tree grower
Browse files Browse the repository at this point in the history
  • Loading branch information
quat1024 committed Dec 5, 2023
1 parent 29d684d commit 7f342f2
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 50 deletions.
6 changes: 6 additions & 0 deletions src/main/java/org/violetmoon/quark/base/Quark.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.violetmoon.quark.base;

import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.fml.DistExecutor;
import net.minecraftforge.fml.common.Mod;
Expand Down Expand Up @@ -35,4 +37,8 @@ public Quark() {
public static ResourceLocation asResource(String name) {
return new ResourceLocation(MOD_ID, name);
}

public static <T>ResourceKey<T> asResourceKey(ResourceKey<? extends Registry<T>> base, String name) {
return ResourceKey.create(base, asResource(name));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,37 +26,8 @@

public class AncientSaplingBlock extends ZetaSaplingBlock {

public AncientSaplingBlock(ZetaModule module) {
super("ancient", module, new AncientTree());
}

public static class AncientTree extends AbstractTreeGrower {

public final TreeConfiguration config;

public AncientTree() {
config = (new TreeConfiguration.TreeConfigurationBuilder(
BlockStateProvider.simple(AncientWoodModule.woodSet.log),
new MultiFoliageStraightTrunkPlacer(17, 4, 6, 5, 3),
BlockStateProvider.simple(AncientWoodModule.ancient_leaves),
new FancyFoliagePlacer(UniformInt.of(2, 4), ConstantInt.of(-3) , 2),
new TwoLayersFeatureSize(0, 0, 0, OptionalInt.of(4))))
.decorators(Lists.newArrayList(new AncientTreeTopperDecorator()))
.ignoreVines()
.build();
}

ResourceKey<ConfiguredFeature<?, ?>> ANCIENT_TREE = ResourceKey.create(Registries.CONFIGURED_FEATURE, Quark.asResource("ancient_tree"));

@Override
protected ResourceKey<ConfiguredFeature<?, ?>> getConfiguredFeature(@NotNull RandomSource rand, boolean hasFlowers) {
return ANCIENT_TREE;
}

//fixme find how to call this
public void bootstrap(BootstapContext<ConfiguredFeature<?, ?>> context) {
context.register(ANCIENT_TREE, new ConfiguredFeature<>(Feature.TREE, config));
}
public AncientSaplingBlock(ZetaModule module, AbstractTreeGrower grower) {
super("ancient", module, grower);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,16 @@
import net.minecraft.world.level.levelgen.feature.treedecorators.TreeDecoratorType;
import org.violetmoon.quark.content.world.module.AncientWoodModule;

//for Ancient Trees, TODO register me
public class AncientTreeTopperDecorator extends TreeDecorator {

public static final Codec<AncientTreeTopperDecorator> CODEC = Codec.unit(AncientTreeTopperDecorator::new);

//Registered in AncientWoodModule
public static final TreeDecoratorType<AncientTreeTopperDecorator> TYPE = new TreeDecoratorType<>(CODEC);

//TODO register me
@Override
protected TreeDecoratorType<?> type() {
//return TYPE;
return null;
return TYPE;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,12 @@ public MultiFoliageStraightTrunkPlacer(int baseHeight, int heightRandA, int heig
)
).apply(overengineered, MultiFoliageStraightTrunkPlacer::new));

//TODO: register me
//Registered in AncientWoodModule
public static final TrunkPlacerType<MultiFoliageStraightTrunkPlacer> TYPE = new TrunkPlacerType<>(CODEC);

@Override
protected TrunkPlacerType<?> type() {
//return TYPE;
return null;
return TYPE;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
package org.violetmoon.quark.content.world.module;

import java.util.List;
import java.util.OptionalInt;

import com.google.common.base.Functions;
import com.google.common.collect.ImmutableSet;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceKey;
import net.minecraft.util.valueproviders.ConstantInt;
import net.minecraft.util.valueproviders.UniformInt;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.ComposterBlock;
import net.minecraft.world.level.levelgen.feature.ConfiguredFeature;
import net.minecraft.world.level.levelgen.feature.Feature;
import net.minecraft.world.level.levelgen.feature.TreeFeature;
import net.minecraft.world.level.levelgen.feature.configurations.TreeConfiguration;
import net.minecraft.world.level.levelgen.feature.featuresize.TwoLayersFeatureSize;
import net.minecraft.world.level.levelgen.feature.foliageplacers.FancyFoliagePlacer;
import net.minecraft.world.level.levelgen.feature.stateproviders.BlockStateProvider;
import net.minecraft.world.level.material.MapColor;
import net.minecraft.world.level.storage.loot.BuiltInLootTables;
import net.minecraft.world.level.storage.loot.entries.LootItem;
Expand All @@ -16,11 +29,13 @@
import org.violetmoon.quark.base.handler.GeneralConfig;
import org.violetmoon.quark.base.handler.WoodSetHandler;
import org.violetmoon.quark.base.handler.WoodSetHandler.WoodSet;
import org.violetmoon.quark.content.world.block.AncientSaplingBlock;
import org.violetmoon.quark.content.world.feature.AncientTreeTopperDecorator;
import org.violetmoon.quark.content.world.feature.MultiFoliageStraightTrunkPlacer;
import org.violetmoon.quark.content.world.item.AncientFruitItem;
import org.violetmoon.zeta.advancement.ManualTrigger;
import org.violetmoon.zeta.advancement.modifier.BalancedDietModifier;
import org.violetmoon.zeta.block.ZetaLeavesBlock;
import org.violetmoon.zeta.block.ZetaSaplingBlock;
import org.violetmoon.zeta.event.bus.LoadEvent;
import org.violetmoon.zeta.event.bus.PlayEvent;
import org.violetmoon.zeta.event.load.ZCommonSetup;
Expand All @@ -29,6 +44,7 @@
import org.violetmoon.zeta.module.ZetaLoadModule;
import org.violetmoon.zeta.module.ZetaModule;
import org.violetmoon.zeta.util.Hint;
import org.violetmoon.zeta.world.PassthruTreeGrower;

@ZetaLoadModule(category = "world")
public class AncientWoodModule extends ZetaModule {
Expand Down Expand Up @@ -61,6 +77,7 @@ public class AncientWoodModule extends ZetaModule {
public static Block ancient_leaves;
@Hint public static Block ancient_sapling;
@Hint public static Item ancient_fruit;
public static final ResourceKey<ConfiguredFeature<?, ?>> configuredFeatureKey = Quark.asResourceKey(Registries.CONFIGURED_FEATURE, "ancient_tree");

public static ManualTrigger ancientFruitTrigger;

Expand All @@ -75,17 +92,35 @@ public void setup(ZCommonSetup e) {

@LoadEvent
public void register(ZRegister event) {
// wood //

woodSet = WoodSetHandler.addWoodSet(event, this, "ancient", MapColor.TERRACOTTA_WHITE, MapColor.TERRACOTTA_WHITE, true);
ancient_leaves = new ZetaLeavesBlock(woodSet.name, this, MapColor.PLANT);
ancient_sapling = new AncientSaplingBlock(this);
ancient_fruit = new AncientFruitItem(this);
ancient_sapling = new ZetaSaplingBlock("ancient", this, new PassthruTreeGrower(configuredFeatureKey)); //actually called "ancient_sapling"

event.getVariantRegistry().addFlowerPot(ancient_sapling, Quark.ZETA.registry.getRegistryName(ancient_sapling, BuiltInRegistries.BLOCK).getPath(), Functions.identity());
event.getVariantRegistry().addFlowerPot(ancient_sapling, "ancient_sapling", Functions.identity()); //actually "potted_ancient_sapling"

// fruit //

ancient_fruit = new AncientFruitItem(this);
event.getAdvancementModifierRegistry().addModifier(new BalancedDietModifier(this, ImmutableSet.of(ancient_fruit))
.setCondition(() -> GeneralConfig.enableAdvancementModification));

ancientFruitTrigger = event.getAdvancementModifierRegistry().registerManualTrigger("ancient_fruit_overlevel");

// tree //

//i don't think these custom tree placer bits *strictly* need to be registered in json, but it doesn't hurt
event.getRegistry().registerDynamic(MultiFoliageStraightTrunkPlacer.TYPE, "multi_foliage_straight_trunk_placer", Registries.TRUNK_PLACER_TYPE);
event.getRegistry().registerDynamic(AncientTreeTopperDecorator.TYPE, "ancient_tree_topper_decorator", Registries.TREE_DECORATOR_TYPE);

TreeConfiguration treeCfg = new TreeConfiguration.TreeConfigurationBuilder(
BlockStateProvider.simple(woodSet.log),
new MultiFoliageStraightTrunkPlacer(17, 4, 6, 5, 3),
BlockStateProvider.simple(ancient_leaves),
new FancyFoliagePlacer(UniformInt.of(2, 4), ConstantInt.of(-3), 2),
new TwoLayersFeatureSize(0, 0, 0, OptionalInt.of(4))
).decorators(List.of(new AncientTreeTopperDecorator())).ignoreVines().build();
event.getRegistry().registerDynamic(new ConfiguredFeature<>((TreeFeature) Feature.TREE, treeCfg), configuredFeatureKey, Registries.CONFIGURED_FEATURE);
}

@PlayEvent
Expand Down
9 changes: 3 additions & 6 deletions src/main/java/org/violetmoon/zeta/registry/ZetaRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,7 @@ public abstract class ZetaRegistry {
private final Map<Item, String> itemsToColorProviderName = new HashMap<>();

// Hastily tacked-on dynamic registry bullshit
private record DynamicEntry<T>(ResourceKey<T> id, T obj) {
void register(WritableRegistry<T> reg) {
reg.register(id, obj, Lifecycle.stable());
}
}
private record DynamicEntry<T>(ResourceKey<T> id, T obj) { }
private final Map<ResourceKey<Registry<?>>, List<DynamicEntry<?>>> dynamicDefers = new HashMap<>();

public ZetaRegistry(Zeta z) {
Expand Down Expand Up @@ -160,6 +156,7 @@ private <T> ResourceKey<Registry<?>> erase(ResourceKey<? extends Registry<T>> we
return (ResourceKey<Registry<?>>) (Object) weeeejava;
}

//Returns the ResourceKey purely because they are kind of annoying to create
public <T> void registerDynamic(T obj, ResourceKey<T> id, ResourceKey<? extends Registry<T>> registry) {
RegisterDynamicUtil.signup(z);
dynamicDefers.computeIfAbsent(erase(registry), __ -> new ArrayList<>()).add(new DynamicEntry<>(id, obj));
Expand All @@ -182,6 +179,6 @@ public <T> void performDynamicRegistration(ResourceKey<? extends Registry<?>> re
return;

List<DynamicEntry<T>> pun = ((List<DynamicEntry<T>>) (Object) entries);
pun.forEach(entry -> entry.register(writable));
pun.forEach(entry -> writable.register(entry.id, entry.obj, Lifecycle.stable()));
}
}

0 comments on commit 7f342f2

Please sign in to comment.