2
2
3
3
import com .github .alexthe666 .iceandfire .IafConfig ;
4
4
import com .github .alexthe666 .iceandfire .block .BlockGoldPile ;
5
- import com .github .alexthe666 .iceandfire .block . IafBlockRegistry ;
5
+ import com .github .alexthe666 .iceandfire .datagen . tags . IafBlockTags ;
6
6
import com .github .alexthe666 .iceandfire .entity .EntityDragonBase ;
7
7
import com .github .alexthe666 .iceandfire .util .ShapeBuilder ;
8
8
import com .github .alexthe666 .iceandfire .world .IafWorldRegistry ;
16
16
import net .minecraft .world .level .LevelAccessor ;
17
17
import net .minecraft .world .level .WorldGenLevel ;
18
18
import net .minecraft .world .level .block .BaseEntityBlock ;
19
+ import net .minecraft .world .level .block .Block ;
19
20
import net .minecraft .world .level .block .Blocks ;
20
21
import net .minecraft .world .level .block .ChestBlock ;
21
22
import net .minecraft .world .level .block .entity .BlockEntity ;
25
26
import net .minecraft .world .level .levelgen .feature .Feature ;
26
27
import net .minecraft .world .level .levelgen .feature .FeaturePlaceContext ;
27
28
import net .minecraft .world .level .levelgen .feature .configurations .NoneFeatureConfiguration ;
29
+ import net .minecraftforge .registries .ForgeRegistries ;
28
30
29
31
import java .util .ArrayList ;
30
32
import java .util .List ;
@@ -117,32 +119,32 @@ public void generateCave(LevelAccessor worldIn, int radius, int amount, BlockPos
117
119
}
118
120
119
121
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
+
120
126
positions .forEach (blockPos -> {
121
127
if (!(worldIn .getBlockState (blockPos ).getBlock () instanceof BaseEntityBlock ) && worldIn .getBlockState (blockPos ).getDestroySpeed (worldIn , blockPos ) >= 0 ) {
122
128
boolean doOres = rand .nextInt (IafConfig .oreToStoneRatioForDragonCaves + 1 ) == 0 ;
129
+
123
130
if (doOres ) {
124
131
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 ;
143
142
}
143
+
144
+ worldIn .setBlock (blockPos , toPlace , Block .UPDATE_CLIENTS );
144
145
} 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 );
146
148
}
147
149
}
148
150
});
@@ -151,7 +153,7 @@ public void createShell(LevelAccessor worldIn, RandomSource rand, Set<BlockPos>
151
153
public void hollowOut (LevelAccessor worldIn , Set <BlockPos > positions ) {
152
154
positions .forEach (blockPos -> {
153
155
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 );
155
157
}
156
158
});
157
159
}
@@ -160,16 +162,19 @@ public void decorateCave(LevelAccessor worldIn, RandomSource rand, Set<BlockPos>
160
162
for (SphereInfo sphere : spheres ) {
161
163
BlockPos pos = sphere .pos ;
162
164
int radius = sphere .radius ;
165
+
163
166
for (int i = 0 ; i < 15 + rand .nextInt (10 ); i ++) {
164
167
CEILING_DECO .generate (worldIn , rand , pos .above (radius / 2 - 1 ).offset (rand .nextInt (radius ) - radius / 2 , 0 , rand .nextInt (radius ) - radius / 2 ));
165
168
}
166
-
167
169
}
168
- int y = center . getY ();
170
+
169
171
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 ()) {
172
176
setGoldPile (worldIn , blockPos , rand );
177
+ }
173
178
}
174
179
});
175
180
}
@@ -182,11 +187,13 @@ public void setGoldPile(LevelAccessor world, BlockPos pos, RandomSource rand) {
182
187
boolean generateGold = rand .nextInt (goldRand ) == 0 ;
183
188
world .setBlock (pos , generateGold ? TREASURE_PILE .setValue (BlockGoldPile .LAYERS , 1 + rand .nextInt (7 )) : Blocks .AIR .defaultBlockState (), 3 );
184
189
} 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
+
186
192
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 ());
190
197
}
191
198
}
192
199
}
0 commit comments