From cad14c2a4366d0d0ae9a912e4607a4f9701d9471 Mon Sep 17 00:00:00 2001 From: Lord Cambion Date: Wed, 18 Mar 2026 12:01:53 +0100 Subject: [PATCH] Door Crafting changes + Beam Color --- Minecraft.Client/BeaconRenderer.cpp | 275 +++++++++++++++++----------- Minecraft.World/Recipes.cpp | 14 +- Minecraft.World/Tile.h | 1 + 3 files changed, 179 insertions(+), 111 deletions(-) diff --git a/Minecraft.Client/BeaconRenderer.cpp b/Minecraft.Client/BeaconRenderer.cpp index 959df6a8..ed6e5db4 100644 --- a/Minecraft.Client/BeaconRenderer.cpp +++ b/Minecraft.Client/BeaconRenderer.cpp @@ -3,136 +3,203 @@ #include "..\Minecraft.World\net.minecraft.world.level.h" #include "BeaconRenderer.h" #include "Tesselator.h" +#include +#include"..\StainedGlassBlock.h" +#include"..\StainedGlassPaneBlock.h" + ResourceLocation BeaconRenderer::BEAM_LOCATION = ResourceLocation(TN_MISC_BEACON_BEAM); + +static float BEACON_COLORS[16][3] = { + {0.074f, 0.074f, 0.074f}, // 0: Black + {0.600f, 0.164f, 0.164f}, // 1: Red + {0.337f, 0.423f, 0.184f}, // 2: Green + {0.411f, 0.270f, 0.156f}, // 3: Brown + {0.203f, 0.286f, 0.611f}, // 4: Blue + {0.478f, 0.203f, 0.658f}, // 5: Purple + {0.298f, 0.501f, 0.600f}, // 6: Cyan + {0.623f, 0.623f, 0.623f}, // 7: Silver (Light Gray) + {0.298f, 0.298f, 0.298f}, // 8: Gray + {0.941f, 0.482f, 0.639f}, // 9: Pink + {0.501f, 0.752f, 0.125f}, // 10: Lime + {0.870f, 0.870f, 0.164f}, // 11: Yellow + {0.400f, 0.623f, 0.811f}, // 12: Light Blue + {0.701f, 0.325f, 0.823f}, // 13: Magenta + {0.850f, 0.478f, 0.235f}, // 14: Orange + {1.000f, 1.000f, 1.000f} // 15: White +}; + + + + void BeaconRenderer::render(shared_ptr _beacon, double x, double y, double z, float a, bool setColor, float alpha, bool useCompiled) { - shared_ptr beacon = dynamic_pointer_cast(_beacon); + shared_ptr beacon = dynamic_pointer_cast(_beacon); + if (!beacon) return; - float scale = beacon->getAndUpdateClientSideScale(); + float scale = beacon->getAndUpdateClientSideScale(); + if (scale <= 0) return; - if (scale > 0) - { - Tesselator *t = Tesselator::getInstance(); + Tesselator *t = Tesselator::getInstance(); + Level* level = beacon->getLevel(); + + + bindTexture(&BEAM_LOCATION); - bindTexture(&BEAM_LOCATION); + glDisable(GL_LIGHTING); + glDisable(GL_CULL_FACE); + glEnable(GL_TEXTURE_2D); - // TODO: 4J: Put this back in - //assert(0); - //glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); - //glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + float tt = (float)level->getGameTime() + a; + float texVOff = -tt * .20f - floor(-tt * .10f); - glDisable(GL_LIGHTING); - glDisable(GL_CULL_FACE); - glDisable(GL_BLEND); - glDepthMask(true); - glBlendFunc(GL_SRC_ALPHA, GL_ONE); + + struct BeamSegment { + float r, g, b; + int height; + }; + std::vector segments; - float tt = beacon->getLevel()->getGameTime() + a; - float texVOff = -tt * .20f - floor(-tt * .10f); + float curR = 1.0f, curG = 1.0f, curB = 1.0f; + int bx = beacon->x; + int by = beacon->y; + int bz = beacon->z; + bool firstGlass = true; - { - int r = 1; + for (int i = by + 1; i < 256; i++) { + int tileID = level->getTile(bx, i, bz); + + if (tileID == Tile::stained_glass_Id || tileID == Tile::stained_glass_pane_Id) { + int meta = level->getData(bx, i, bz); + int colorIdx = (tileID == Tile::stained_glass_Id) ? + StainedGlassBlock::getItemAuxValueForBlockData(meta) : + StainedGlassPaneBlock::getItemAuxValueForBlockData(meta); + + + if (firstGlass) { + curR = BEACON_COLORS[colorIdx][0]; + curG = BEACON_COLORS[colorIdx][1]; + curB = BEACON_COLORS[colorIdx][2]; + firstGlass = false; + } else { + curR = (curR + BEACON_COLORS[colorIdx][0]) * 0.5f; + curG = (curG + BEACON_COLORS[colorIdx][1]) * 0.5f; + curB = (curB + BEACON_COLORS[colorIdx][2]) * 0.5f; + } + + segments.push_back({curR, curG, curB, 1}); + } + else if (tileID == 0 || tileID == Tile::glass_Id || tileID == Tile::thinGlass_Id) { + if (segments.empty()) { + segments.push_back({1.0f, 1.0f, 1.0f, 1}); + } else { + segments.back().height++; + } + } + else { + if (Tile::tiles[tileID] && Tile::tiles[tileID]->blocksLight()) { + break; + } + else if (!segments.empty()) { + segments.back().height++; + } + } + } - double rot = tt * .025 * (1 - (r & 1) * 2.5); + if (segments.empty()) return; - t->begin(); - t->color(255, 255, 255, 32); + + glEnable(GL_BLEND); + + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glDepthMask(true); - double rr1 = r * 0.2; + double currentYBase = 0; + for (const auto& seg : segments) { + int r = (int)(seg.r * 255); + int g = (int)(seg.g * 255); + int b = (int)(seg.b * 255); - double wnx = .5 + cos(rot + PI * .75) * rr1; - double wnz = .5 + sin(rot + PI * .75) * rr1; - double enx = .5 + cos(rot + PI * .25) * rr1; - double enz = .5 + sin(rot + PI * .25) * rr1; + double rot = tt * .025 * (1 - (1 & 1) * 2.5); + double rr1 = 0.2; - double wsx = .5 + cos(rot + PI * 1.25) * rr1; - double wsz = .5 + sin(rot + PI * 1.25) * rr1; - double esx = .5 + cos(rot + PI * 1.75) * rr1; - double esz = .5 + sin(rot + PI * 1.75) * rr1; + double wnx = .5 + cos(rot + PI * .75) * rr1; + double wnz = .5 + sin(rot + PI * .75) * rr1; + double enx = .5 + cos(rot + PI * .25) * rr1; + double enz = .5 + sin(rot + PI * .25) * rr1; + double wsx = .5 + cos(rot + PI * 1.25) * rr1; + double wsz = .5 + sin(rot + PI * 1.25) * rr1; + double esx = .5 + cos(rot + PI * 1.75) * rr1; + double esz = .5 + sin(rot + PI * 1.75) * rr1; - double top = 256 * scale; + double yMin = currentYBase * scale; + double yMax = (currentYBase + seg.height) * scale; + double vv2 = currentYBase * scale * (0.5 / rr1) + texVOff; + double vv1 = (currentYBase + seg.height) * scale * (0.5 / rr1) + texVOff; - double uu1 = 0; - double uu2 = 1; - double vv2 = -1 + texVOff; - double vv1 = 256 * scale * (.5 / rr1) + vv2; + t->begin(); + t->color(r, g, b, 255); - t->vertexUV(x + wnx, y + top, z + wnz, uu2, vv1); - t->vertexUV(x + wnx, y, z + wnz, uu2, vv2); - t->vertexUV(x + enx, y, z + enz, uu1, vv2); - t->vertexUV(x + enx, y + top, z + enz, uu1, vv1); + t->vertexUV(x + wnx, y + yMax, z + wnz, 1.0, vv1); + t->vertexUV(x + wnx, y + yMin, z + wnz, 1.0, vv2); + t->vertexUV(x + enx, y + yMin, z + enz, 0.0, vv2); + t->vertexUV(x + enx, y + yMax, z + enz, 0.0, vv1); + t->vertexUV(x + esx, y + yMax, z + esz, 1.0, vv1); + t->vertexUV(x + esx, y + yMin, z + esz, 1.0, vv2); + t->vertexUV(x + wsx, y + yMin, z + wsz, 0.0, vv2); + t->vertexUV(x + wsx, y + yMax, z + wsz, 0.0, vv1); + t->vertexUV(x + enx, y + yMax, z + enz, 1.0, vv1); + t->vertexUV(x + enx, y + yMin, z + enz, 1.0, vv2); + t->vertexUV(x + esx, y + yMin, z + esz, 0.0, vv2); + t->vertexUV(x + esx, y + yMax, z + esz, 0.0, vv1); + t->vertexUV(x + wsx, y + yMax, z + wsz, 1.0, vv1); + t->vertexUV(x + wsx, y + yMin, z + wsz, 1.0, vv2); + t->vertexUV(x + wnx, y + yMin, z + wnz, 0.0, vv2); + t->vertexUV(x + wnx, y + yMax, z + wnz, 0.0, vv1); + t->end(); - t->vertexUV(x + esx, y + top, z + esz, uu2, vv1); - t->vertexUV(x + esx, y, z + esz, uu2, vv2); - t->vertexUV(x + wsx, y, z + wsz, uu1, vv2); - t->vertexUV(x + wsx, y + top, z + wsz, uu1, vv1); + currentYBase += seg.height; + } - t->vertexUV(x + enx, y + top, z + enz, uu2, vv1); - t->vertexUV(x + enx, y, z + enz, uu2, vv2); - t->vertexUV(x + esx, y, z + esz, uu1, vv2); - t->vertexUV(x + esx, y + top, z + esz, uu1, vv1); - - t->vertexUV(x + wsx, y + top, z + wsz, uu2, vv1); - t->vertexUV(x + wsx, y, z + wsz, uu2, vv2); - t->vertexUV(x + wnx, y, z + wnz, uu1, vv2); - t->vertexUV(x + wnx, y + top, z + wnz, uu1, vv1); - - t->end(); - } + + glDepthMask(false); - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glDepthMask(false); + currentYBase = 0; + for (const auto& seg : segments) { + int r = (int)(seg.r * 255); + int g = (int)(seg.g * 255); + int b = (int)(seg.b * 255); - { - t->begin(); - t->color(255, 255, 255, 32); + double yMin = currentYBase * scale; + double yMax = (currentYBase + seg.height) * scale; + double vv2 = currentYBase * scale + texVOff; + double vv1 = (currentYBase + seg.height) * scale + texVOff; - double wnx = .2; - double wnz = .2; - double enx = .8; - double enz = .2; + t->begin(); + t->color(r, g, b, 32); - double wsx = .2; - double wsz = .8; - double esx = .8; - double esz = .8; + t->vertexUV(x + 0.2, y + yMax, z + 0.2, 1.0, vv1); + t->vertexUV(x + 0.2, y + yMin, z + 0.2, 1.0, vv2); + t->vertexUV(x + 0.8, y + yMin, z + 0.2, 0.0, vv2); + t->vertexUV(x + 0.8, y + yMax, z + 0.2, 0.0, vv1); + t->vertexUV(x + 0.8, y + yMax, z + 0.8, 1.0, vv1); + t->vertexUV(x + 0.8, y + yMin, z + 0.8, 1.0, vv2); + t->vertexUV(x + 0.2, y + yMin, z + 0.8, 0.0, vv2); + t->vertexUV(x + 0.2, y + yMax, z + 0.8, 0.0, vv1); + t->vertexUV(x + 0.8, y + yMax, z + 0.2, 1.0, vv1); + t->vertexUV(x + 0.8, y + yMin, z + 0.2, 1.0, vv2); + t->vertexUV(x + 0.8, y + yMin, z + 0.8, 0.0, vv2); + t->vertexUV(x + 0.8, y + yMax, z + 0.8, 0.0, vv1); + t->vertexUV(x + 0.2, y + yMax, z + 0.8, 1.0, vv1); + t->vertexUV(x + 0.2, y + yMin, z + 0.8, 1.0, vv2); + t->vertexUV(x + 0.2, y + yMin, z + 0.2, 0.0, vv2); + t->vertexUV(x + 0.2, y + yMax, z + 0.2, 0.0, vv1); + t->end(); - double top = 256 * scale; + currentYBase += seg.height; + } - double uu1 = 0; - double uu2 = 1; - double vv2 = -1 + texVOff; - double vv1 = 256 * scale + vv2; - - t->vertexUV(x + wnx, y + top, z + wnz, uu2, vv1); - t->vertexUV(x + wnx, y, z + wnz, uu2, vv2); - t->vertexUV(x + enx, y, z + enz, uu1, vv2); - t->vertexUV(x + enx, y + top, z + enz, uu1, vv1); - - t->vertexUV(x + esx, y + top, z + esz, uu2, vv1); - t->vertexUV(x + esx, y, z + esz, uu2, vv2); - t->vertexUV(x + wsx, y, z + wsz, uu1, vv2); - t->vertexUV(x + wsx, y + top, z + wsz, uu1, vv1); - - t->vertexUV(x + enx, y + top, z + enz, uu2, vv1); - t->vertexUV(x + enx, y, z + enz, uu2, vv2); - t->vertexUV(x + esx, y, z + esz, uu1, vv2); - t->vertexUV(x + esx, y + top, z + esz, uu1, vv1); - - t->vertexUV(x + wsx, y + top, z + wsz, uu2, vv1); - t->vertexUV(x + wsx, y, z + wsz, uu2, vv2); - t->vertexUV(x + wnx, y, z + wnz, uu1, vv2); - t->vertexUV(x + wnx, y + top, z + wnz, uu1, vv1); - - t->end(); - } - - glEnable(GL_LIGHTING); - glEnable(GL_TEXTURE_2D); - - glDepthMask(true); - } + glDepthMask(true); + glDisable(GL_BLEND); } \ No newline at end of file diff --git a/Minecraft.World/Recipes.cpp b/Minecraft.World/Recipes.cpp index 54ebb91e..73b9846c 100644 --- a/Minecraft.World/Recipes.cpp +++ b/Minecraft.World/Recipes.cpp @@ -272,7 +272,7 @@ Recipes::Recipes() L'#', Item::stick, "W", new ItemInstance(Tile::wood, 1, TreeTile::DARK_TRUNK), L'S'); - addShapedRecipy(new ItemInstance(Item::door_wood, 1), // + addShapedRecipy(new ItemInstance(Item::door_wood, 3), // L"sssczg", L"##", // L"##", // @@ -281,7 +281,7 @@ Recipes::Recipes() L'#', new ItemInstance(Tile::wood, 1, 0), L'S'); - addShapedRecipy(new ItemInstance(Item::door_birch, 1), // + addShapedRecipy(new ItemInstance(Item::door_birch, 3), // L"sssczg", L"##", // L"##", // @@ -290,7 +290,7 @@ Recipes::Recipes() L'#', new ItemInstance(Tile::wood, 1, TreeTile::BIRCH_TRUNK), L'S'); - addShapedRecipy(new ItemInstance(Item::door_spruce, 1), // + addShapedRecipy(new ItemInstance(Item::door_spruce, 3), // L"sssczg", L"##", // L"##", // @@ -299,7 +299,7 @@ Recipes::Recipes() L'#', new ItemInstance(Tile::wood, 1, TreeTile::SPRUCE_TRUNK), L'S'); - addShapedRecipy(new ItemInstance(Item::door_jungle, 1), // + addShapedRecipy(new ItemInstance(Item::door_jungle, 3), // L"sssczg", L"##", // L"##", // @@ -308,7 +308,7 @@ Recipes::Recipes() L'#', new ItemInstance(Tile::wood, 1, TreeTile::JUNGLE_TRUNK), L'S'); - addShapedRecipy(new ItemInstance(Item::door_acacia, 1), // + addShapedRecipy(new ItemInstance(Item::door_acacia, 3), // L"sssczg", L"##", // L"##", // @@ -317,7 +317,7 @@ Recipes::Recipes() L'#', new ItemInstance(Tile::wood, 1, TreeTile::ACACIA_TRUNK), L'S'); - addShapedRecipy(new ItemInstance(Item::door_dark, 1), // + addShapedRecipy(new ItemInstance(Item::door_dark, 3), // L"sssczg", L"##", // L"##", // @@ -326,7 +326,7 @@ Recipes::Recipes() L'#', new ItemInstance(Tile::wood, 1, TreeTile::DARK_TRUNK), L'S'); - addShapedRecipy(new ItemInstance(Item::door_iron, 1), // + addShapedRecipy(new ItemInstance(Item::door_iron, 3), // L"ssscig", L"##", // L"##", // diff --git a/Minecraft.World/Tile.h b/Minecraft.World/Tile.h index 75857b65..4d4cfcf5 100644 --- a/Minecraft.World/Tile.h +++ b/Minecraft.World/Tile.h @@ -774,6 +774,7 @@ public: static bool isMatching(int tileIdA, int tileIdB); virtual bool hasAnalogOutputSignal(); virtual int getAnalogOutputSignal(Level *level, int x, int y, int z, int dir); + virtual bool blocksLight() { return Tile::lightBlock[id] > 0; } protected: virtual Tile *setIconName(const wstring &iconName);