11package dev .xpple .seedmapper .seedmap ;
22
33import com .github .cubiomes .Cubiomes ;
4+ import com .github .cubiomes .Piece ;
5+ import com .github .cubiomes .StructureVariant ;
46import dev .xpple .seedmapper .SeedMapper ;
7+ import dev .xpple .seedmapper .feature .StructureChecks ;
8+ import dev .xpple .seedmapper .util .WorldIdentifier ;
59import net .minecraft .resources .ResourceLocation ;
610
11+ import java .lang .foreign .Arena ;
12+ import java .lang .foreign .MemorySegment ;
713import java .util .Arrays ;
814import java .util .Map ;
915import java .util .stream .Collectors ;
16+ import java .util .stream .IntStream ;
1017
1118public enum MapFeature {
1219 DESERT_PYRAMID ("desert_pyramid" , Cubiomes .Desert_Pyramid (), Cubiomes .DIM_OVERWORLD (), Cubiomes .MC_1_3 (), "cubiomes_viewer_icons" , 19 , 20 ),
1320 JUNGLE_PYRAMID ("jungle_pyramid" , Cubiomes .Jungle_Pyramid (), Cubiomes .DIM_OVERWORLD (), Cubiomes .MC_1_3 (), "cubiomes_viewer_icons" , 19 , 20 ),
1421 SWAMP_HUT ("swamp_hut" , Cubiomes .Swamp_Hut (), Cubiomes .DIM_OVERWORLD (), Cubiomes .MC_1_4 (), "cubiomes_viewer_icons" , 20 , 20 ),
1522 STRONGHOLD ("stronghold" , -1 , Cubiomes .DIM_OVERWORLD (), Cubiomes .MC_B1_8 (), "cubiomes_viewer_icons" , 19 , 20 ),
16- IGLOO ("igloo" , Cubiomes .Igloo (), Cubiomes .DIM_OVERWORLD (), Cubiomes .MC_1_9 (), "cubiomes_viewer_icons" , 20 , 20 ),
17- VILLAGE ("village" , Cubiomes .Village (), Cubiomes .DIM_OVERWORLD (), Cubiomes .MC_B1_8 (), "cubiomes_viewer_icons" , 19 , 20 ),
23+ IGLOO ("igloo" , Cubiomes .Igloo (), Cubiomes .DIM_OVERWORLD (), Cubiomes .MC_1_9 (), "cubiomes_viewer_icons" , 20 , 20 ) {
24+ private static final Texture IGLOO_BASEMENT_TEXTURE = new Texture ("igloo_basement" , "cubiomes_viewer_icons" , 20 , 20 );
25+ @ Override
26+ public Texture getVariantTexture (WorldIdentifier identifier , int posX , int posZ , int biome ) {
27+ try (Arena arena = Arena .ofConfined ()) {
28+ MemorySegment variant = StructureVariant .allocate (arena );
29+ Cubiomes .getVariant (variant , this .getStructureId (), identifier .version (), identifier .seed (), posX , posZ , biome );
30+ if (StructureVariant .basement (variant ) == 1 ) {
31+ return IGLOO_BASEMENT_TEXTURE ;
32+ }
33+ return super .getDefaultTexture ();
34+ }
35+ }
36+ },
37+ VILLAGE ("village" , Cubiomes .Village (), Cubiomes .DIM_OVERWORLD (), Cubiomes .MC_B1_8 (), "cubiomes_viewer_icons" , 19 , 20 ) {
38+ private static final Texture ZOMBIE_VILLAGE_TEXTURE = new Texture ("zombie" , "cubiomes_viewer_icons" , 19 , 20 );
39+ @ Override
40+ public Texture getVariantTexture (WorldIdentifier identifier , int posX , int posZ , int biome ) {
41+ try (Arena arena = Arena .ofConfined ()) {
42+ MemorySegment variant = StructureVariant .allocate (arena );
43+ Cubiomes .getVariant (variant , this .getStructureId (), identifier .version (), identifier .seed (), posX , posZ , biome );
44+ if (StructureVariant .abandoned (variant ) == 1 ) {
45+ return ZOMBIE_VILLAGE_TEXTURE ;
46+ }
47+ return super .getDefaultTexture ();
48+ }
49+ }
50+ },
1851 OCEAN_RUIN ("ocean_ruin" , Cubiomes .Ocean_Ruin (), Cubiomes .DIM_OVERWORLD (), Cubiomes .MC_1_13 (), "cubiomes_viewer_icons" , 19 , 19 ),
1952 SHIPWRECK ("shipwreck" , Cubiomes .Shipwreck (), Cubiomes .DIM_OVERWORLD (), Cubiomes .MC_1_13 (), "cubiomes_viewer_icons" , 19 , 19 ),
2053 MONUMENT ("monument" , Cubiomes .Monument (), Cubiomes .DIM_OVERWORLD (), Cubiomes .MC_1_8 (), "cubiomes_viewer_icons" , 20 , 20 ),
2154 MANSION ("mansion" , Cubiomes .Mansion (), Cubiomes .DIM_OVERWORLD (), Cubiomes .MC_1_11 (), "cubiomes_viewer_icons" , 20 , 20 ),
2255 OUTPOST ("pillager_outpost" , Cubiomes .Outpost (), Cubiomes .DIM_OVERWORLD (), Cubiomes .MC_1_14 (), "cubiomes_viewer_icons" , 19 , 20 ),
23- RUINED_PORTAL ("ruined_portal" , Cubiomes .Ruined_Portal (), Cubiomes .DIM_OVERWORLD (), Cubiomes .MC_1_16_1 (), "cubiomes_viewer_icons" , 20 , 20 ),
24- RUINED_PORTAL_N ("ruined_portal_n" , Cubiomes .Ruined_Portal_N (), Cubiomes .DIM_NETHER (), Cubiomes .MC_1_16_1 (), "cubiomes_viewer_icons" , 20 , 20 ),
56+ RUINED_PORTAL ("ruined_portal" , Cubiomes .Ruined_Portal (), Cubiomes .DIM_OVERWORLD (), Cubiomes .MC_1_16_1 (), "cubiomes_viewer_icons" , 20 , 20 ) {
57+ private static final Texture RUINED_PORTAL_GIANT_TEXTURE = new Texture ("portal_giant" , "cubiomes_viewer_icons" , 20 , 20 );
58+ @ Override
59+ public Texture getVariantTexture (WorldIdentifier identifier , int posX , int posZ , int biome ) {
60+ try (Arena arena = Arena .ofConfined ()) {
61+ MemorySegment variant = StructureVariant .allocate (arena );
62+ Cubiomes .getVariant (variant , this .getStructureId (), identifier .version (), identifier .seed (), posX , posZ , biome );
63+ if (StructureVariant .giant (variant ) == 1 ) {
64+ return RUINED_PORTAL_GIANT_TEXTURE ;
65+ }
66+ return super .getDefaultTexture ();
67+ }
68+ }
69+ },
70+ RUINED_PORTAL_N ("ruined_portal_n" , Cubiomes .Ruined_Portal_N (), Cubiomes .DIM_NETHER (), Cubiomes .MC_1_16_1 (), "cubiomes_viewer_icons" , 20 , 20 ) {
71+ @ Override
72+ public Texture getVariantTexture (WorldIdentifier identifier , int posX , int posZ , int biome ) {
73+ return RUINED_PORTAL .getVariantTexture (identifier , posX , posZ , biome );
74+ }
75+ },
2576 ANCIENT_CITY ("ancient_city" , Cubiomes .Ancient_City (), Cubiomes .DIM_OVERWORLD (), Cubiomes .MC_1_19_2 (), "cubiomes_viewer_icons" , 20 , 20 ),
2677 TREASURE ("buried_treasure" , Cubiomes .Treasure (), Cubiomes .DIM_OVERWORLD (), Cubiomes .MC_1_13 (), "cubiomes_viewer_icons" , 19 , 19 ),
2778 MINESHAFT ("mineshaft" , Cubiomes .Mineshaft (), Cubiomes .DIM_OVERWORLD (), Cubiomes .MC_B1_8 (), "cubiomes_viewer_icons" , 20 , 19 ),
@@ -32,7 +83,23 @@ public enum MapFeature {
3283 CANYON ("canyon" , -1 , Cubiomes .DIM_OVERWORLD (), Cubiomes .MC_1_13 (), "feature_icons" , 20 , 20 ),
3384 FORTRESS ("fortress" , Cubiomes .Fortress (), Cubiomes .DIM_NETHER (), Cubiomes .MC_1_0 (), "cubiomes_viewer_icons" , 20 , 20 ),
3485 BASTION ("bastion_remnant" , Cubiomes .Bastion (), Cubiomes .DIM_NETHER (), Cubiomes .MC_1_16_1 (), "cubiomes_viewer_icons" , 20 , 20 ),
35- END_CITY ("end_city" , Cubiomes .End_City (), Cubiomes .DIM_END (), Cubiomes .MC_1_9 (), "cubiomes_viewer_icons" , 20 , 20 ),
86+ END_CITY ("end_city" , Cubiomes .End_City (), Cubiomes .DIM_END (), Cubiomes .MC_1_9 (), "cubiomes_viewer_icons" , 20 , 20 ) {
87+ private static final Texture END_CITY_SHIP_TEXTURE = new Texture ("end_ship" , "cubiomes_viewer_icons" , 20 , 20 );
88+ @ Override
89+ public Texture getVariantTexture (WorldIdentifier identifier , int posX , int posZ , int biome ) {
90+ try (Arena arena = Arena .ofConfined ()) {
91+ MemorySegment pieces = Piece .allocateArray (StructureChecks .MAX_END_CITY_AND_FORTRESS_PIECES , arena );
92+ int numPieces = Cubiomes .getEndCityPieces (pieces , identifier .seed (), posX >> 4 , posZ >> 4 );
93+ boolean hasShip = IntStream .range (0 , numPieces )
94+ .mapToObj (i -> Piece .asSlice (pieces , i ))
95+ .anyMatch (piece -> Piece .type (piece ) == Cubiomes .END_SHIP ());
96+ if (hasShip ) {
97+ return END_CITY_SHIP_TEXTURE ;
98+ }
99+ return super .getDefaultTexture ();
100+ }
101+ }
102+ },
36103 END_GATEWAY ("end_gateway" , Cubiomes .End_Gateway (), Cubiomes .DIM_END (), Cubiomes .MC_1_13 (), "cubiomes_viewer_icons" , 20 , 20 ),
37104 TRAIL_RUINS ("trail_ruins" , Cubiomes .Trail_Ruins (), Cubiomes .DIM_OVERWORLD (), Cubiomes .MC_1_20 (), "cubiomes_viewer_icons" , 20 , 20 ),
38105 TRIAL_CHAMBERS ("trial_chambers" , Cubiomes .Trial_Chambers (), Cubiomes .DIM_OVERWORLD (), Cubiomes .MC_1_21_1 (), "cubiomes_viewer_icons" , 20 , 20 ),
@@ -48,14 +115,14 @@ public enum MapFeature {
48115 private final int structureId ;
49116 private final int dimension ;
50117 private final int availableSince ;
51- private final Texture texture ;
118+ private final Texture defaultTexture ;
52119
53120 MapFeature (String name , int structureId , int dimension , int availableSince , String directory , int textureWidth , int textureHeight ) {
54121 this .name = name ;
55122 this .structureId = structureId ;
56123 this .dimension = dimension ;
57124 this .availableSince = availableSince ;
58- this .texture = new Texture (name , directory , textureWidth , textureHeight );
125+ this .defaultTexture = new Texture (name , directory , textureWidth , textureHeight );
59126 }
60127
61128 public String getName () {
@@ -74,8 +141,12 @@ public int availableSince() {
74141 return this .availableSince ;
75142 }
76143
77- public Texture getTexture () {
78- return this .texture ;
144+ public Texture getDefaultTexture () {
145+ return this .defaultTexture ;
146+ }
147+
148+ public Texture getVariantTexture (WorldIdentifier identifier , int posX , int posZ , int biome ) {
149+ return this .getDefaultTexture ();
79150 }
80151
81152 public record Texture (ResourceLocation resourceLocation , int width , int height ) {
0 commit comments