Skip to content

Commit 974f284

Browse files
committed
Backported mega seeds from 1.21
1 parent b8da211 commit 974f284

File tree

22 files changed

+305
-54
lines changed

22 files changed

+305
-54
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
modName=DynamicTrees
22
modId=dynamictrees
3-
modVersion=1.4.5
3+
modVersion=1.4.6
44

55
group=com.ferreusveritas.dynamictrees
66

src/main/java/com/ferreusveritas/dynamictrees/block/leaves/LeavesProperties.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ public LootTable.Builder createBlockDrops() {
235235
if (primitiveLeaves != null && getPrimitiveLeavesBlock().isPresent()) {
236236
return DTLootTableProvider.BlockLoot.createLeavesBlockDrops(primitiveLeaves.getBlock(), seedDropChances, getFamily().getStick(1).getItem());
237237
}
238-
return DTLootTableProvider.BlockLoot.createLeavesDrops(seedDropChances, LootContextParamSets.BLOCK);
238+
return DTLootTableProvider.BlockLoot.createLeavesDrops(seedDropChances, LootContextParamSets.BLOCK, getFamily().getStick(1).getItem());
239239
}
240240

241241
private final LootTableSupplier lootTableSupplier;
@@ -253,7 +253,7 @@ public boolean shouldGenerateDrops() {
253253
}
254254

255255
public LootTable.Builder createDrops() {
256-
return DTLootTableProvider.BlockLoot.createLeavesDrops(seedDropChances, DTLootParameterSets.LEAVES);
256+
return DTLootTableProvider.BlockLoot.createLeavesDrops(seedDropChances, DTLootParameterSets.LEAVES, getFamily().getStick(1).getItem());
257257
}
258258

259259
public List<ItemStack> getDrops(Level level, BlockPos pos, ItemStack tool, Species species) {

src/main/java/com/ferreusveritas/dynamictrees/data/DTRecipes.java

Lines changed: 61 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
package com.ferreusveritas.dynamictrees.data;
22

3+
import com.ferreusveritas.dynamictrees.init.DTConfigs;
34
import com.ferreusveritas.dynamictrees.init.DTRegistries;
45
import com.ferreusveritas.dynamictrees.tree.species.Species;
56
import net.minecraft.core.NonNullList;
67
import net.minecraft.resources.ResourceLocation;
78
import net.minecraft.world.item.Item;
89
import net.minecraft.world.item.ItemStack;
910
import net.minecraft.world.item.Items;
10-
import net.minecraft.world.item.crafting.CraftingBookCategory;
11-
import net.minecraft.world.item.crafting.Ingredient;
12-
import net.minecraft.world.item.crafting.Recipe;
13-
import net.minecraft.world.item.crafting.ShapelessRecipe;
11+
import net.minecraft.world.item.crafting.*;
1412
import net.minecraftforge.registries.ForgeRegistries;
1513
import org.apache.logging.log4j.LogManager;
1614

@@ -37,41 +35,64 @@ public static void registerDirtBucketRecipes(final Map<ResourceLocation, Recipe<
3735

3836
final ResourceLocation registryName = species.getRegistryName();
3937

40-
species.getPrimitiveSaplingRecipes().forEach(saplingRecipe -> {
41-
final Item saplingItem = saplingRecipe.getSaplingItem().orElse(null);
42-
if (saplingItem == null || ForgeRegistries.ITEMS.getKey(saplingItem) == null) {
43-
LogManager.getLogger().error("Error creating seed-sapling recipe for species \"" + species.getRegistryName() + "\" as sapling item does not exist.");
44-
return;
45-
}
46-
47-
if (saplingRecipe.canCraftSaplingToSeed()) {
48-
final ResourceLocation saplingToSeed = new ResourceLocation(registryName.getNamespace(),
49-
separate(ForgeRegistries.ITEMS.getKey(saplingItem)) + "_to_" + registryName.getPath() + "_seed");
50-
51-
List<Item> ingredients = saplingRecipe.getIngredientsForSaplingToSeed();
52-
ingredients.add(DTRegistries.DIRT_BUCKET.get());
53-
ingredients.add(saplingItem);
54-
craftingRecipes.putIfAbsent(saplingToSeed, createShapeless(saplingToSeed,
55-
species.getSeedStack(1), //result
56-
ingredients(ingredients))); //ingredients
57-
}
58-
59-
if (saplingRecipe.canCraftSeedToSapling()) {
60-
final ResourceLocation seedToSapling = new ResourceLocation(registryName.getNamespace(),
61-
registryName.getPath() + "_seed_to_" + separate(ForgeRegistries.ITEMS.getKey(saplingItem)));
62-
63-
List<Item> ingredients = saplingRecipe.getIngredientsForSeedToSapling();
64-
ingredients.add(DTRegistries.DIRT_BUCKET.get());
65-
ingredients.add(species.getSeed().map(Item.class::cast).orElse(Items.AIR));
66-
craftingRecipes.putIfAbsent(seedToSapling, createShapeless(seedToSapling,
67-
new ItemStack(saplingItem), //result
68-
ingredients(ingredients))); //ingredients
69-
}
70-
71-
});
38+
if (DTConfigs.GENERATE_DIRT_BUCKET_RECIPES.get()){
39+
generateSaplingRecipes(craftingRecipes, species, registryName);
40+
}
41+
42+
if (DTConfigs.GENERATE_MEGA_SEED_RECIPE.get()){
43+
generateMegaSeedRecipes(craftingRecipes, species, registryName);
44+
}
45+
}
46+
}
47+
48+
private static void generateMegaSeedRecipes(Map<ResourceLocation, Recipe<?>> craftingRecipes, Species species, ResourceLocation registryName) {
49+
if (species.isMegaSpecies()
50+
&& species.getPreMegaSpecies().hasSeed()
51+
&& species.getPreMegaSpecies().canCraftMegaSeed()){
52+
final ResourceLocation resLoc = new ResourceLocation(registryName.getNamespace(),
53+
registryName.getPath() + "_mega_of_" + species.getPreMegaSpecies().getRegistryName().getPath());
54+
55+
Item preMegaSeed = species.getPreMegaSpecies().getSeed().orElse(null);
56+
57+
craftingRecipes.putIfAbsent(resLoc, createSquare(resLoc, species.getSeedStack(1), Ingredient.of(preMegaSeed)));
7258
}
7359
}
7460

61+
private static void generateSaplingRecipes(Map<ResourceLocation, Recipe<?>> craftingRecipes, Species species, ResourceLocation registryName) {
62+
species.getPrimitiveSaplingRecipes().forEach(saplingRecipe -> {
63+
final Item saplingItem = saplingRecipe.getSaplingItem().orElse(null);
64+
if (saplingItem == null || ForgeRegistries.ITEMS.getKey(saplingItem) == null) {
65+
LogManager.getLogger().error("Error creating seed-sapling recipe for species \"" + species.getRegistryName() + "\" as sapling item does not exist.");
66+
return;
67+
}
68+
69+
if (saplingRecipe.canCraftSaplingToSeed()) {
70+
final ResourceLocation saplingToSeed = new ResourceLocation(registryName.getNamespace(),
71+
separate(ForgeRegistries.ITEMS.getKey(saplingItem)) + "_to_" + registryName.getPath() + "_seed");
72+
73+
List<Item> ingredients = saplingRecipe.getIngredientsForSaplingToSeed();
74+
ingredients.add(DTRegistries.DIRT_BUCKET.get());
75+
ingredients.add(saplingItem);
76+
craftingRecipes.putIfAbsent(saplingToSeed, createShapeless(saplingToSeed,
77+
species.getSeedStack(1), //result
78+
ingredients(ingredients))); //ingredients
79+
}
80+
81+
if (saplingRecipe.canCraftSeedToSapling()) {
82+
final ResourceLocation seedToSapling = new ResourceLocation(registryName.getNamespace(),
83+
registryName.getPath() + "_seed_to_" + separate(ForgeRegistries.ITEMS.getKey(saplingItem)));
84+
85+
List<Item> ingredients = saplingRecipe.getIngredientsForSeedToSapling();
86+
ingredients.add(DTRegistries.DIRT_BUCKET.get());
87+
ingredients.add(species.getSeed().map(Item.class::cast).orElse(Items.AIR));
88+
craftingRecipes.putIfAbsent(seedToSapling, createShapeless(seedToSapling,
89+
new ItemStack(saplingItem), //result
90+
ingredients(ingredients))); //ingredients
91+
}
92+
93+
});
94+
}
95+
7596
private static String separate(final ResourceLocation resourceLocation) {
7697
return resourceLocation.getNamespace() + "_" + resourceLocation.getPath();
7798
}
@@ -80,6 +101,10 @@ private static ShapelessRecipe createShapeless(final ResourceLocation registryNa
80101
return new ShapelessRecipe(registryName, "CRAFTING_MISC", CraftingBookCategory.MISC, out, NonNullList.of(Ingredient.EMPTY, ingredients));
81102
}
82103

104+
private static ShapedRecipe createSquare(final ResourceLocation registryName, final ItemStack out, final Ingredient ingredient) {
105+
return new ShapedRecipe(registryName, "CRAFTING_MISC", CraftingBookCategory.MISC, 2,2, NonNullList.of(ingredient), out);
106+
}
107+
83108
private static Ingredient[] ingredients(Collection<Item> items) {
84109
return ingredients(items.toArray(new Item[]{}));
85110
}

src/main/java/com/ferreusveritas/dynamictrees/data/provider/DTLootTableProvider.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ public static LootTable.Builder createWartBlockDrops(Block primitiveWartBlock) {
203203
);
204204
}
205205

206-
public static LootTable.Builder createLeavesDrops(float[] seedChances, LootContextParamSet parameterSet) {
206+
public static LootTable.Builder createLeavesDrops(float[] seedChances, LootContextParamSet parameterSet, Item stickItem) {
207207
return LootTable.lootTable().withPool(
208208
LootPool.lootPool().setRolls(ConstantValue.exactly(1)).add(
209209
SeedItemLootPoolEntry.lootTableSeedItem()
@@ -213,7 +213,7 @@ public static LootTable.Builder createLeavesDrops(float[] seedChances, LootConte
213213
)
214214
).withPool(
215215
LootPool.lootPool().setRolls(ConstantValue.exactly(1)).add(
216-
LootItem.lootTableItem(Items.STICK)
216+
LootItem.lootTableItem(stickItem)
217217
.apply(SetItemCountFunction.setCount(
218218
UniformGenerator.between(1.0F, 2.0F)
219219
))

src/main/java/com/ferreusveritas/dynamictrees/init/DTConfigs.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ public class DTConfigs {
6767
public static final ForgeConfigSpec.BooleanValue PODZOL_GEN;
6868

6969
public static final ForgeConfigSpec.BooleanValue GENERATE_DIRT_BUCKET_RECIPES;
70+
public static final ForgeConfigSpec.BooleanValue GENERATE_MEGA_SEED_RECIPE;
7071
public static final ForgeConfigSpec.ConfigValue<String> BIOCHAR_BASE_BREWING_BASE;
7172

7273
public static final ForgeConfigSpec.BooleanValue WORLD_GEN;
@@ -186,6 +187,8 @@ public class DTConfigs {
186187
COMMON_BUILDER.comment("Miscellaneous Settings").push("misc");
187188
GENERATE_DIRT_BUCKET_RECIPES = COMMON_BUILDER.comment("If enabled, dirt bucket recipes will be automatically generated.")
188189
.define("generateDirtBucketRecipes", true);
190+
GENERATE_MEGA_SEED_RECIPE = COMMON_BUILDER.comment("If enabled, seeds for mega species can be crafted with four regular seeds.")
191+
.define("generateMegaSeedRecipe", false);
189192
BIOCHAR_BASE_BREWING_BASE = COMMON_BUILDER.comment("The base potion the Biochar Base is brewed from. Minecraft potions use 'awkward'. If you change this, don't forget to update the patchouli manual page too.")
190193
.define("biocharBrewingBase", "thick");
191194
COMMON_BUILDER.pop();

src/main/java/com/ferreusveritas/dynamictrees/resources/Resources.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,8 @@ public CompletableFuture<Void> reload(PreparationBarrier stage, ResourceManager
188188
}
189189

190190
private void registerDirtBucketRecipes() {
191-
if (!DTConfigs.GENERATE_DIRT_BUCKET_RECIPES.get()) {
191+
if (!DTConfigs.GENERATE_DIRT_BUCKET_RECIPES.get()
192+
&& !DTConfigs.GENERATE_MEGA_SEED_RECIPE.get()) {
192193
return;
193194
}
194195

src/main/java/com/ferreusveritas/dynamictrees/resources/loader/SpeciesResourceLoader.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ public void registerAppliers() {
107107
.register("world_gen_leaf_map_height", Integer.class, Species::setWorldGenLeafMapHeight)
108108
.register("environment_factors", JsonObject.class, this::applyEnvironmentFactors)
109109
.register("mega_species", ResourceLocation.class, this::setMegaSpecies)
110+
.register("can_craft_mega_seed", Boolean.class, Species::setCanCraftMegaSeed)
110111
.register("seed", Seed.class, (species, seed) -> species.setSeed(() -> seed))
111112
.register("seed_composter_chance", Float.class, this.composterChanceCache::put)
112113
.register("tint_sapling", Boolean.class, Species::setTintSapling)

src/main/java/com/ferreusveritas/dynamictrees/tree/species/Species.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2013,6 +2013,16 @@ public void setMegaSpecies(final Species megaSpecies) {
20132013
megaSpecies.preMegaSpecies = this;
20142014
}
20152015

2016+
private boolean canCraftMegaSeed = true;
2017+
2018+
public void setCanCraftMegaSeed(boolean canCraftMegaSeed) {
2019+
this.canCraftMegaSeed = canCraftMegaSeed;
2020+
}
2021+
2022+
public boolean canCraftMegaSeed() {
2023+
return canCraftMegaSeed;
2024+
}
2025+
20162026
///////////////////////////////////////////
20172027
// FALL ANIMATION HANDLING
20182028
///////////////////////////////////////////

src/main/java/com/ferreusveritas/dynamictrees/util/CommonVoxelShapes.java

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,34 +19,45 @@ public final class CommonVoxelShapes {
1919

2020
public static final VoxelShape SLAB = Shapes.create(0,0,0,1,0.5,1);
2121
public static final VoxelShape TALL_SLAB = Shapes.create(0,0,0,1,0.75,1);
22+
public static final VoxelShape HALF_SLAB = Shapes.create(0,0,0,1,0.25,1);
2223

2324
public static final VoxelShape SAPLING_TRUNK = Block.box(7D, 0D, 7D, 9D, 5D, 9D);
25+
public static final VoxelShape FAT_SAPLING_TRUNK = Block.box(6.5D, 0D, 6.5D, 9.5D, 5D, 9.5D);
2426
public static final VoxelShape SAPLING_LEAVES = Block.box(4D, 4D, 4D, 12D, 12D, 12D);
27+
public static final VoxelShape FAT_SAPLING_LEAVES = Block.box(3D, 4D, 3D, 13D, 14D, 13D);
2528
public static final VoxelShape SLIM_SAPLING_LEAVES = Block.box(5D, 5D, 5D, 11D, 14D, 11D);
26-
public static final VoxelShape MUSHROOM_STEM = Block.box(7D, 0D, 7D, 9D, 5D, 9D);
2729
public static final VoxelShape MUSHROOM_CAP_FLAT = Block.box(4D, 5D, 4D, 12D, 8D, 12D);
30+
public static final VoxelShape FAT_MUSHROOM_CAP_FLAT = Block.box(3D, 5D, 3D, 13D, 9D, 13D);
2831
public static final VoxelShape MUSHROOM_CAP_ROUND = Block.box(5D, 3D, 5D, 11D, 8D, 11D);
29-
public static final VoxelShape MUSHROOM_BRIM_E = Block.box(11D, 3D, 5D, 12D, 5D, 11D);
30-
public static final VoxelShape MUSHROOM_BRIM_W = Block.box(4D, 3D, 5D, 5D, 5D, 11D);
31-
public static final VoxelShape MUSHROOM_BRIM_S = Block.box(4D, 3D, 11D, 12D, 5D, 12D);
32-
public static final VoxelShape MUSHROOM_BRIM_N = Block.box(4D, 3D, 4D, 12D, 5D, 5D);
32+
public static final VoxelShape FAT_MUSHROOM_CAP_ROUND = Block.box(4D, 3D, 4D, 12D, 9D, 12D);
33+
public static final VoxelShape MUSHROOM_RIM = Block.box(4D, 3D, 4D, 12D, 5D, 12D);
34+
public static final VoxelShape FAT_MUSHROOM_RIM = Block.box(3D, 3D, 3D, 13D, 5D, 13D);
3335

3436
public static final VoxelShape SAPLING = Shapes.or(SAPLING_TRUNK, SAPLING_LEAVES);
3537
public static final VoxelShape SLIM_SAPLING = Shapes.or(SAPLING_TRUNK, SLIM_SAPLING_LEAVES);
36-
public static final VoxelShape FLAT_MUSHROOM = Shapes.or(MUSHROOM_STEM, MUSHROOM_CAP_FLAT);
37-
public static final VoxelShape ROUND_MUSHROOM = Shapes.or(MUSHROOM_STEM, MUSHROOM_CAP_ROUND);
38-
public static final VoxelShape ROUND_MUSHROOM_RIM = Shapes.or(MUSHROOM_STEM, MUSHROOM_CAP_ROUND, MUSHROOM_BRIM_E, MUSHROOM_BRIM_W, MUSHROOM_BRIM_S, MUSHROOM_BRIM_N);
38+
public static final VoxelShape FAT_SAPLING = Shapes.or(FAT_SAPLING_TRUNK, FAT_SAPLING_LEAVES);
39+
public static final VoxelShape FLAT_MUSHROOM = Shapes.or(SAPLING_TRUNK, MUSHROOM_CAP_FLAT);
40+
public static final VoxelShape FAT_FLAT_MUSHROOM = Shapes.or(FAT_SAPLING_TRUNK, FAT_MUSHROOM_CAP_FLAT);
41+
public static final VoxelShape ROUND_MUSHROOM = Shapes.or(SAPLING_TRUNK, MUSHROOM_CAP_ROUND);
42+
public static final VoxelShape FAT_ROUND_MUSHROOM = Shapes.or(FAT_SAPLING_TRUNK, FAT_MUSHROOM_CAP_ROUND);
43+
public static final VoxelShape ROUND_MUSHROOM_RIM = Shapes.or(SAPLING_TRUNK, MUSHROOM_CAP_ROUND, MUSHROOM_RIM);
44+
public static final VoxelShape FAT_ROUND_MUSHROOM_RIM = Shapes.or(FAT_SAPLING_TRUNK, FAT_MUSHROOM_CAP_ROUND, FAT_MUSHROOM_RIM);
3945

4046
static {
4147
SHAPES.put("empty", Shapes.empty());
4248
SHAPES.put("block", Shapes.block());
4349
SHAPES.put("slab", SLAB);
4450
SHAPES.put("tall_slab", TALL_SLAB);
51+
SHAPES.put("half_slab", HALF_SLAB);
4552
SHAPES.put("sapling", SAPLING);
4653
SHAPES.put("slim_sapling", SLIM_SAPLING);
54+
SHAPES.put("fat_sapling", FAT_SAPLING);
4755
SHAPES.put("flat_mushroom", FLAT_MUSHROOM);
56+
SHAPES.put("fat_flat_mushroom", FAT_FLAT_MUSHROOM);
4857
SHAPES.put("round_mushroom", ROUND_MUSHROOM);
58+
SHAPES.put("fat_round_mushroom", FAT_ROUND_MUSHROOM);
4959
SHAPES.put("round_mushroom_rim", ROUND_MUSHROOM_RIM);
60+
SHAPES.put("fat_round_mushroom_rim", FAT_ROUND_MUSHROOM_RIM);
5061
}
5162

5263
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"credit": "Made with Blockbench",
3+
"parent": "block/block",
4+
"texture_size": [32, 32],
5+
"textures": {
6+
"particle": "#cap"
7+
},
8+
"elements": [
9+
{
10+
"name": "Cap",
11+
"from": [3, 5, 3],
12+
"to": [13, 9, 13],
13+
"rotation": {"angle": 0, "axis": "y", "origin": [0, 0, -1]},
14+
"faces": {
15+
"north": {"uv": [0, 5, 5, 7], "texture": "#cap"},
16+
"east": {"uv": [0, 7.5, 5, 9.5], "texture": "#cap"},
17+
"south": {"uv": [0, 5, 5, 7], "texture": "#cap"},
18+
"west": {"uv": [0, 7.5, 5, 9.5], "texture": "#cap"},
19+
"up": {"uv": [0, 0, 5, 5], "texture": "#cap"},
20+
"down": {"uv": [5, 0, 10, 5], "texture": "#cap"}
21+
}
22+
},
23+
{
24+
"name": "Stem",
25+
"from": [6.5, -1, 6.5],
26+
"to": [9.5, 5, 9.5],
27+
"rotation": {"angle": 0, "axis": "y", "origin": [-0.5, 0, 0.5]},
28+
"faces": {
29+
"north": {"uv": [6.5, 6.5, 8, 9.5], "texture": "#cap"},
30+
"east": {"uv": [6.5, 6.5, 8, 9.5], "texture": "#cap"},
31+
"south": {"uv": [6.5, 6.5, 8, 9.5], "texture": "#cap"},
32+
"west": {"uv": [6.5, 6.5, 8, 9.5], "texture": "#cap"},
33+
"up": {"uv": [6.5, 6.5, 8, 8], "texture": "#cap"},
34+
"down": {"uv": [6.5, 8, 8, 9.5], "texture": "#cap", "cullface": "down"}
35+
}
36+
}
37+
]
38+
}

0 commit comments

Comments
 (0)