Skip to content

Commit 27524e6

Browse files
authored
Add double_plant handling to match modern (#1815)
1 parent 5d5e910 commit 27524e6

3 files changed

Lines changed: 35 additions & 27 deletions

File tree

src/main/java/com/gtnewhorizons/angelica/rendering/celeritas/AngelicaChunkBuilderMeshingTask.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import net.coderbot.iris.block_rendering.NbtConditionalIdMap;
1616
import net.coderbot.iris.vertices.ExtendedDataHelper;
1717
import net.minecraft.block.Block;
18+
import net.minecraft.block.BlockDoublePlant;
1819
import net.minecraft.nbt.NBTTagCompound;
1920
import net.minecraft.client.Minecraft;
2021
import net.minecraft.client.renderer.RenderBlocks;
@@ -275,6 +276,8 @@ protected void renderBlock(Block block, int metadata, int x, int y, int z, int p
275276
&& BlockRenderingSettings.INSTANCE.getSnowyBlocks().contains(block)
276277
&& RenderBlocksUtils.isSnowCovered(renderBlocks.blockAccess, x, y, z)) {
277278
effectiveMeta |= BlockMaterialMapping.SNOWY_META_BIT;
279+
} else if (block instanceof BlockDoublePlant doublePlant && BlockDoublePlant.func_149887_c(metadata)) {
280+
effectiveMeta = 0x8 | (doublePlant.func_149885_e(renderBlocks.blockAccess, x, y, z) & 7);
278281
}
279282
contextEncoder.prepareToRenderBlock(blockRenderContext, block, effectiveMeta,
280283
ExtendedDataHelper.BLOCK_RENDER_TYPE, lightValue);

src/main/java/net/coderbot/iris/block_rendering/BlockMaterialMapping.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import net.coderbot.iris.shaderpack.materialmap.FlatteningMap;
1515
import net.coderbot.iris.shaderpack.materialmap.NamespacedId;
1616
import net.minecraft.block.Block;
17+
import net.minecraft.block.BlockDoublePlant;
1718
import net.minecraft.init.Blocks;
1819
import net.minecraft.util.ResourceLocation;
1920

@@ -25,9 +26,11 @@ public class BlockMaterialMapping {
2526

2627
public record BlockIdMaps(Reference2ObjectMap<Block, Int2IntMap> blockMetaMap, NbtConditionalIdMap<Block> tileEntityMap) {}
2728

28-
/** Meta-key bit OR'd in at runtime when a snowy-tagged block has snow above it. */
29+
// Meta-key bits OR'd in at runtime
2930
public static final int SNOWY_META_BIT = 0x10;
3031

32+
public static final int DOUBLE_PLANT_TOP_BIT = 0x8;
33+
3134
/**
3235
* Creates the standard block meta ID map, the TileEntity NBT-conditional map, and registers
3336
* snowy blocks on {@link BlockRenderingSettings}.
@@ -129,6 +132,7 @@ private static void addBlockMetas(BlockEntry entry, Reference2ObjectMap<Block, I
129132
final Map<String, String> stateProps = entry.stateProperties();
130133
final String snowy = stateProps.get("snowy");
131134
final int snowyBit = "true".equals(snowy) ? SNOWY_META_BIT : 0;
135+
final boolean wantsDoublePlantTop = "upper".equals(stateProps.get("half"));
132136

133137
// Vanilla modern names go through FlatteningMap; legacy-section packs and modded blocks
134138
// resolve directly from the registry.
@@ -145,12 +149,16 @@ private static void addBlockMetas(BlockEntry entry, Reference2ObjectMap<Block, I
145149
}
146150
final Block block = resolveBlockOrNull(target.id());
147151
if (block == null) continue;
148-
applyMetas(block, target.metas(), idMap, intId, snowyBit);
152+
int extraBits = snowyBit;
153+
if (wantsDoublePlantTop && block instanceof BlockDoublePlant) {
154+
extraBits |= DOUBLE_PLANT_TOP_BIT;
155+
}
156+
applyMetas(block, target.metas(), idMap, intId, extraBits);
149157
if (snowy != null) snowyBlocks.add(block);
150158
}
151159
}
152160

153-
private static void applyMetas(Block block, Set<Integer> metas, Reference2ObjectMap<Block, Int2IntMap> idMap, int intId, int snowyBit) {
161+
private static void applyMetas(Block block, Set<Integer> metas, Reference2ObjectMap<Block, Int2IntMap> idMap, int intId, int extraBits) {
154162
Int2IntMap metaMap = idMap.get(block);
155163
if (metaMap == null) {
156164
metaMap = new Int2IntOpenHashMap();
@@ -159,9 +167,9 @@ private static void applyMetas(Block block, Set<Integer> metas, Reference2Object
159167
}
160168

161169
if (metas.isEmpty()) {
162-
for (int meta = 0; meta < 16; meta++) metaMap.putIfAbsent(meta | snowyBit, intId);
170+
for (int meta = 0; meta < 16; meta++) metaMap.putIfAbsent(meta | extraBits, intId);
163171
} else {
164-
for (int meta : metas) metaMap.putIfAbsent(meta | snowyBit, intId);
172+
for (int meta : metas) metaMap.putIfAbsent(meta | extraBits, intId);
165173
}
166174
}
167175

src/main/java/net/coderbot/iris/shaderpack/materialmap/FlatteningMap.java

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -373,13 +373,14 @@ public class FlatteningMap {
373373
colorVariants("carpet", "carpet");
374374

375375
// === Double plant (ID 175) ===
376-
// Bottom half has type in meta 0-5; top half is always meta 8 (shared by all types).
377-
meta("sunflower", "double_plant", 0);
378-
meta("lilac", "double_plant", 1);
379-
meta("tall_grass", "double_plant", 2);
380-
meta("large_fern", "double_plant", 3);
381-
meta("rose_bush", "double_plant", 4);
382-
meta("peony", "double_plant", 5);
376+
// Bottom half carries the variant in meta 0-5; the top half's real meta is 8-11.
377+
// We use a synthetic key to tie the variant the bottom is with the top half.
378+
doublePlant("sunflower", 0);
379+
doublePlant("lilac", 1);
380+
doublePlant("tall_grass", 2);
381+
doublePlant("large_fern", 3);
382+
doublePlant("rose_bush", 4);
383+
doublePlant("peony", 5);
383384

384385
// === Water / Lava (IDs 8-11) ===
385386
// In 1.13+, water/lava are single blocks. In 1.7.10, flowing variants are separate.
@@ -861,21 +862,6 @@ public class FlatteningMap {
861862
state(WOOD_TYPES[i] + "_sapling", "stage", "0", entryMetas("sapling", i));
862863
state(WOOD_TYPES[i] + "_sapling", "stage", "1", entryMetas("sapling", i + 8));
863864
}
864-
865-
// === Double plant half (ID 175) ===
866-
// 1.7.10: bottom half has type in meta 0-5; top half is always meta 8
867-
state("sunflower", "half", "lower", entryMetas("double_plant", 0));
868-
state("sunflower", "half", "upper", entryMetas("double_plant", 8));
869-
state("lilac", "half", "lower", entryMetas("double_plant", 1));
870-
state("lilac", "half", "upper", entryMetas("double_plant", 8));
871-
state("tall_grass", "half", "lower", entryMetas("double_plant", 2));
872-
state("tall_grass", "half", "upper", entryMetas("double_plant", 8));
873-
state("large_fern", "half", "lower", entryMetas("double_plant", 3));
874-
state("large_fern", "half", "upper", entryMetas("double_plant", 8));
875-
state("rose_bush", "half", "lower", entryMetas("double_plant", 4));
876-
state("rose_bush", "half", "upper", entryMetas("double_plant", 8));
877-
state("peony", "half", "lower", entryMetas("double_plant", 5));
878-
state("peony", "half", "upper", entryMetas("double_plant", 8));
879865
}
880866

881867
/**
@@ -1053,6 +1039,17 @@ private static void colorVariants(String modernSuffix, String legacyName) {
10531039
}
10541040
}
10551041

1042+
/**
1043+
* Double plant: the bottom half stores the variant in meta 0-5; the top half stores facing
1044+
* direction, so Angelica's chunk mesher rebuilds a synthetic key 0x8|variant for top halves.
1045+
*/
1046+
private static void doublePlant(String modern, int variant) {
1047+
final int upper = 0x8 | variant;
1048+
metas(modern, "double_plant", variant, upper);
1049+
state(modern, "half", "lower", entryMetas("double_plant", variant));
1050+
state(modern, "half", "upper", entryMetas("double_plant", upper));
1051+
}
1052+
10561053
// ==========================================
10571054
// Blockstate property mapping helpers
10581055
// ==========================================

0 commit comments

Comments
 (0)