Skip to content

Commit f2431f7

Browse files
SiverDXTheBv
authored andcommitted
feat: adjust dragon cave worldgen
- fix chests / gold piles not spawning - make (generic) placed ore configurable through tags
1 parent 8ccdb01 commit f2431f7

File tree

6 files changed

+128
-29
lines changed

6 files changed

+128
-29
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"values": [
3+
"minecraft:coal_ore",
4+
"minecraft:copper_ore",
5+
"minecraft:iron_ore"
6+
]
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"values": [
3+
"minecraft:diamond_ore",
4+
"minecraft:emerald_ore"
5+
]
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"values": [
3+
"minecraft:lapis_ore",
4+
"minecraft:redstone_ore",
5+
"minecraft:gold_ore",
6+
"iceandfire:silver_ore"
7+
]
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"values": [
3+
"iceandfire:chared_cobblestone",
4+
"iceandfire:chared_dirt",
5+
"iceandfire:chared_dirt_path",
6+
"iceandfire:chared_grass",
7+
"iceandfire:chared_gravel",
8+
"iceandfire:chared_stone",
9+
"iceandfire:frozen_cobblestone",
10+
"iceandfire:frozen_dirt",
11+
"iceandfire:frozen_dirt_path",
12+
"iceandfire:frozen_grass",
13+
"iceandfire:frozen_gravel",
14+
"iceandfire:frozen_stone",
15+
"iceandfire:crackled_cobblestone",
16+
"iceandfire:crackled_dirt",
17+
"iceandfire:crackled_dirt_path",
18+
"iceandfire:crackled_grass",
19+
"iceandfire:crackled_grass",
20+
"iceandfire:crackled_stone"
21+
]
22+
}

src/main/java/com/github/alexthe666/iceandfire/datagen/tags/IafBlockTags.java

+49
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,70 @@
11
package com.github.alexthe666.iceandfire.datagen.tags;
22

33
import com.github.alexthe666.iceandfire.IceAndFire;
4+
import com.github.alexthe666.iceandfire.block.IafBlockRegistry;
45
import net.minecraft.core.HolderLookup;
6+
import net.minecraft.core.registries.Registries;
57
import net.minecraft.data.PackOutput;
8+
import net.minecraft.resources.ResourceLocation;
9+
import net.minecraft.tags.TagKey;
10+
import net.minecraft.world.level.block.Block;
11+
import net.minecraft.world.level.block.Blocks;
612
import net.minecraftforge.common.data.BlockTagsProvider;
713
import net.minecraftforge.common.data.ExistingFileHelper;
814

915
import java.util.concurrent.CompletableFuture;
1016

1117
public class IafBlockTags extends BlockTagsProvider {
18+
public static TagKey<Block> DRAGON_ENVIRONMENT_BLOCKS = createKey("dragon_environment_blocks");
19+
20+
public static TagKey<Block> DRAGON_CAVE_RARE_ORES = createKey("dragon_cave_rare_ores");
21+
public static TagKey<Block> DRAGON_CAVE_UNCOMMON_ORES = createKey("dragon_cave_uncommon_ores");
22+
public static TagKey<Block> DRAGON_CAVE_COMMON_ORES = createKey("dragon_cave_common_ores");
1223

1324
public IafBlockTags(PackOutput output, CompletableFuture<HolderLookup.Provider> future, ExistingFileHelper helper) {
1425
super(output, future, IceAndFire.MODID, helper);
1526
}
1627

1728
@Override
1829
protected void addTags(HolderLookup.Provider pProvider) {
30+
tag(DRAGON_ENVIRONMENT_BLOCKS)
31+
.add(IafBlockRegistry.CHARRED_COBBLESTONE.get())
32+
.add(IafBlockRegistry.CHARRED_DIRT.get())
33+
.add(IafBlockRegistry.CHARRED_DIRT_PATH.get())
34+
.add(IafBlockRegistry.CHARRED_GRASS.get())
35+
.add(IafBlockRegistry.CHARRED_GRAVEL.get())
36+
.add(IafBlockRegistry.CHARRED_STONE.get())
37+
.add(IafBlockRegistry.FROZEN_COBBLESTONE.get())
38+
.add(IafBlockRegistry.FROZEN_DIRT.get())
39+
.add(IafBlockRegistry.FROZEN_DIRT_PATH.get())
40+
.add(IafBlockRegistry.FROZEN_GRASS.get())
41+
.add(IafBlockRegistry.FROZEN_GRAVEL.get())
42+
.add(IafBlockRegistry.FROZEN_STONE.get())
43+
.add(IafBlockRegistry.CRACKLED_COBBLESTONE.get())
44+
.add(IafBlockRegistry.CRACKLED_DIRT.get())
45+
.add(IafBlockRegistry.CRACKLED_DIRT_PATH.get())
46+
.add(IafBlockRegistry.CRACKLED_GRASS.get())
47+
.add(IafBlockRegistry.CRACKLED_GRASS.get())
48+
.add(IafBlockRegistry.CRACKLED_STONE.get());
49+
50+
tag(DRAGON_CAVE_RARE_ORES)
51+
.add(Blocks.DIAMOND_ORE)
52+
.add(Blocks.EMERALD_ORE);
53+
54+
tag(DRAGON_CAVE_UNCOMMON_ORES)
55+
.add(Blocks.LAPIS_ORE)
56+
.add(Blocks.REDSTONE_ORE)
57+
.add(Blocks.GOLD_ORE)
58+
.add(IafBlockRegistry.SILVER_ORE.get());
59+
60+
tag(DRAGON_CAVE_COMMON_ORES)
61+
.add(Blocks.COAL_ORE)
62+
.add(Blocks.COPPER_ORE)
63+
.add(Blocks.IRON_ORE);
64+
}
65+
66+
private static TagKey<Block> createKey(final String name) {
67+
return TagKey.create(Registries.BLOCK, new ResourceLocation(IceAndFire.MODID, name));
1968
}
2069

2170
@Override

src/main/java/com/github/alexthe666/iceandfire/world/gen/WorldGenDragonCave.java

+36-29
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import com.github.alexthe666.iceandfire.IafConfig;
44
import com.github.alexthe666.iceandfire.block.BlockGoldPile;
5-
import com.github.alexthe666.iceandfire.block.IafBlockRegistry;
5+
import com.github.alexthe666.iceandfire.datagen.tags.IafBlockTags;
66
import com.github.alexthe666.iceandfire.entity.EntityDragonBase;
77
import com.github.alexthe666.iceandfire.util.ShapeBuilder;
88
import com.github.alexthe666.iceandfire.world.IafWorldRegistry;
@@ -16,6 +16,7 @@
1616
import net.minecraft.world.level.LevelAccessor;
1717
import net.minecraft.world.level.WorldGenLevel;
1818
import net.minecraft.world.level.block.BaseEntityBlock;
19+
import net.minecraft.world.level.block.Block;
1920
import net.minecraft.world.level.block.Blocks;
2021
import net.minecraft.world.level.block.ChestBlock;
2122
import net.minecraft.world.level.block.entity.BlockEntity;
@@ -25,6 +26,7 @@
2526
import net.minecraft.world.level.levelgen.feature.Feature;
2627
import net.minecraft.world.level.levelgen.feature.FeaturePlaceContext;
2728
import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration;
29+
import net.minecraftforge.registries.ForgeRegistries;
2830

2931
import java.util.ArrayList;
3032
import java.util.List;
@@ -117,32 +119,32 @@ public void generateCave(LevelAccessor worldIn, int radius, int amount, BlockPos
117119
}
118120

119121
public void createShell(LevelAccessor worldIn, RandomSource rand, Set<BlockPos> positions) {
122+
List<Block> rareOres = ForgeRegistries.BLOCKS.tags().getTag(IafBlockTags.DRAGON_CAVE_RARE_ORES).stream().toList();
123+
List<Block> uncommonOres = ForgeRegistries.BLOCKS.tags().getTag(IafBlockTags.DRAGON_CAVE_UNCOMMON_ORES).stream().toList();
124+
List<Block> commonOres = ForgeRegistries.BLOCKS.tags().getTag(IafBlockTags.DRAGON_CAVE_COMMON_ORES).stream().toList();
125+
120126
positions.forEach(blockPos -> {
121127
if (!(worldIn.getBlockState(blockPos).getBlock() instanceof BaseEntityBlock) && worldIn.getBlockState(blockPos).getDestroySpeed(worldIn, blockPos) >= 0) {
122128
boolean doOres = rand.nextInt(IafConfig.oreToStoneRatioForDragonCaves + 1) == 0;
129+
123130
if (doOres) {
124131
int chance = rand.nextInt(199) + 1;
125-
if (chance < 30) {
126-
worldIn.setBlock(blockPos, Blocks.IRON_ORE.defaultBlockState(), 2);
127-
} else if (chance > 30 && chance < 40) {
128-
worldIn.setBlock(blockPos, Blocks.GOLD_ORE.defaultBlockState(), 2);
129-
} else if (chance > 40 && chance < 45) {
130-
worldIn.setBlock(blockPos, Blocks.COPPER_ORE.defaultBlockState(), 2);
131-
} else if (chance > 45 && chance < 50) {
132-
worldIn.setBlock(blockPos, IafBlockRegistry.SILVER_ORE.get().defaultBlockState(), 2);
133-
} else if (chance > 50 && chance < 60) {
134-
worldIn.setBlock(blockPos, Blocks.COAL_ORE.defaultBlockState(), 2);
135-
} else if (chance > 60 && chance < 70) {
136-
worldIn.setBlock(blockPos, Blocks.REDSTONE_ORE.defaultBlockState(), 2);
137-
} else if (chance > 70 && chance < 80) {
138-
worldIn.setBlock(blockPos, Blocks.LAPIS_ORE.defaultBlockState(), 2);
139-
} else if (chance > 80 && chance < 90) {
140-
worldIn.setBlock(blockPos, Blocks.DIAMOND_ORE.defaultBlockState(), 2);
141-
} else if (chance > 90) {
142-
worldIn.setBlock(blockPos, generateGemOre ? PALETTE_ORE1 : PALETTE_ORE2, 2);
132+
BlockState toPlace;
133+
134+
if (chance < 15) {
135+
toPlace = rareOres.get(rand.nextInt(rareOres.size())).defaultBlockState();
136+
} else if (chance < 45) {
137+
toPlace = uncommonOres.get(rand.nextInt(rareOres.size())).defaultBlockState();
138+
} else if (chance < 90) {
139+
toPlace = commonOres.get(rand.nextInt(rareOres.size())).defaultBlockState();
140+
} else {
141+
toPlace = generateGemOre ? PALETTE_ORE1 : PALETTE_ORE2;
143142
}
143+
144+
worldIn.setBlock(blockPos, toPlace, Block.UPDATE_CLIENTS);
144145
} else {
145-
worldIn.setBlock(blockPos, rand.nextBoolean() ? PALETTE_BLOCK1 : PALETTE_BLOCK2, 2);
146+
// TODO :: Also replace with tags?
147+
worldIn.setBlock(blockPos, rand.nextBoolean() ? PALETTE_BLOCK1 : PALETTE_BLOCK2, Block.UPDATE_CLIENTS);
146148
}
147149
}
148150
});
@@ -151,7 +153,7 @@ public void createShell(LevelAccessor worldIn, RandomSource rand, Set<BlockPos>
151153
public void hollowOut(LevelAccessor worldIn, Set<BlockPos> positions) {
152154
positions.forEach(blockPos -> {
153155
if (!(worldIn.getBlockState(blockPos).getBlock() instanceof BaseEntityBlock)) {
154-
worldIn.setBlock(blockPos, Blocks.AIR.defaultBlockState(), 3);
156+
worldIn.setBlock(blockPos, Blocks.AIR.defaultBlockState(), Block.UPDATE_ALL);
155157
}
156158
});
157159
}
@@ -160,16 +162,19 @@ public void decorateCave(LevelAccessor worldIn, RandomSource rand, Set<BlockPos>
160162
for (SphereInfo sphere : spheres) {
161163
BlockPos pos = sphere.pos;
162164
int radius = sphere.radius;
165+
163166
for (int i = 0; i < 15 + rand.nextInt(10); i++) {
164167
CEILING_DECO.generate(worldIn, rand, pos.above(radius / 2 - 1).offset(rand.nextInt(radius) - radius / 2, 0, rand.nextInt(radius) - radius / 2));
165168
}
166-
167169
}
168-
int y = center.getY();
170+
169171
positions.forEach(blockPos -> {
170-
if (blockPos.getY() < y) {
171-
if (worldIn.getBlockState(blockPos.below()).is(BlockTags.BASE_STONE_OVERWORLD) && worldIn.getBlockState(blockPos).isAir())
172+
if (blockPos.getY() < center.getY()) {
173+
BlockState stateBelow = worldIn.getBlockState(blockPos.below());
174+
175+
if ((stateBelow.is(BlockTags.BASE_STONE_OVERWORLD) || stateBelow.is(IafBlockTags.DRAGON_ENVIRONMENT_BLOCKS)) && worldIn.getBlockState(blockPos).isAir()) {
172176
setGoldPile(worldIn, blockPos, rand);
177+
}
173178
}
174179
});
175180
}
@@ -182,11 +187,13 @@ public void setGoldPile(LevelAccessor world, BlockPos pos, RandomSource rand) {
182187
boolean generateGold = rand.nextInt(goldRand) == 0;
183188
world.setBlock(pos, generateGold ? TREASURE_PILE.setValue(BlockGoldPile.LAYERS, 1 + rand.nextInt(7)) : Blocks.AIR.defaultBlockState(), 3);
184189
} else if (chance == 61) {
185-
world.setBlock(pos, Blocks.CHEST.defaultBlockState().setValue(ChestBlock.FACING, HORIZONTALS[rand.nextInt(3)]), 2);
190+
world.setBlock(pos, Blocks.CHEST.defaultBlockState().setValue(ChestBlock.FACING, HORIZONTALS[rand.nextInt(3)]), Block.UPDATE_CLIENTS);
191+
186192
if (world.getBlockState(pos).getBlock() instanceof ChestBlock) {
187-
BlockEntity tileentity1 = world.getBlockEntity(pos);
188-
if (tileentity1 instanceof ChestBlockEntity) {
189-
((ChestBlockEntity) tileentity1).setLootTable(isMale ? DRAGON_MALE_CHEST : DRAGON_CHEST, rand.nextLong());
193+
BlockEntity blockEntity = world.getBlockEntity(pos);
194+
195+
if (blockEntity instanceof ChestBlockEntity chestBlockEntity) {
196+
chestBlockEntity.setLootTable(isMale ? DRAGON_MALE_CHEST : DRAGON_CHEST, rand.nextLong());
190197
}
191198
}
192199
}

0 commit comments

Comments
 (0)