Remove emissive items hook, add small utility for bakedquad lighting
This commit is contained in:
parent
1936eb1f36
commit
380366e25f
5 changed files with 25 additions and 186 deletions
|
@ -9,18 +9,7 @@
|
||||||
|
|
||||||
for(Item item : Registry.field_212630_s) {
|
for(Item item : Registry.field_212630_s) {
|
||||||
if (!field_195411_c.contains(item)) {
|
if (!field_195411_c.contains(item)) {
|
||||||
@@ -70,6 +70,10 @@
|
@@ -91,7 +91,7 @@
|
||||||
}
|
|
||||||
|
|
||||||
private void func_229114_a_(IBakedModel p_229114_1_, ItemStack p_229114_2_, int p_229114_3_, int p_229114_4_, MatrixStack p_229114_5_, IVertexBuilder p_229114_6_) {
|
|
||||||
+ if (false && net.minecraftforge.common.ForgeConfig.CLIENT.allowEmissiveItems.get()) { //TODO: Find way to re-introduce emissive items.
|
|
||||||
+ net.minecraftforge.client.ForgeHooksClient.renderLitItem(this, p_229114_5_, p_229114_6_, p_229114_1_, p_229114_2_);
|
|
||||||
+ return;
|
|
||||||
+ }
|
|
||||||
Random random = new Random();
|
|
||||||
long i = 42L;
|
|
||||||
|
|
||||||
@@ -91,7 +95,7 @@
|
|
||||||
p_229111_8_ = this.field_175059_m.func_178083_a().func_174953_a(new ModelResourceLocation("minecraft:trident#inventory"));
|
p_229111_8_ = this.field_175059_m.func_178083_a().func_174953_a(new ModelResourceLocation("minecraft:trident#inventory"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,7 +18,7 @@
|
||||||
p_229111_4_.func_227861_a_(-0.5D, -0.5D, -0.5D);
|
p_229111_4_.func_227861_a_(-0.5D, -0.5D, -0.5D);
|
||||||
if (!p_229111_8_.func_188618_c() && (p_229111_1_.func_77973_b() != Items.field_203184_eO || flag1)) {
|
if (!p_229111_8_.func_188618_c() && (p_229111_1_.func_77973_b() != Items.field_203184_eO || flag1)) {
|
||||||
RenderType rendertype = RenderTypeLookup.func_228389_a_(p_229111_1_);
|
RenderType rendertype = RenderTypeLookup.func_228389_a_(p_229111_1_);
|
||||||
@@ -105,7 +109,7 @@
|
@@ -105,7 +105,7 @@
|
||||||
IVertexBuilder ivertexbuilder = func_229113_a_(p_229111_5_, rendertype1, true, p_229111_1_.func_77962_s());
|
IVertexBuilder ivertexbuilder = func_229113_a_(p_229111_5_, rendertype1, true, p_229111_1_.func_77962_s());
|
||||||
this.func_229114_a_(p_229111_8_, p_229111_1_, p_229111_6_, p_229111_7_, p_229111_4_, ivertexbuilder);
|
this.func_229114_a_(p_229111_8_, p_229111_1_, p_229111_6_, p_229111_7_, p_229111_4_, ivertexbuilder);
|
||||||
} else {
|
} else {
|
||||||
|
@ -38,7 +27,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
p_229111_4_.func_227865_b_();
|
p_229111_4_.func_227865_b_();
|
||||||
@@ -129,7 +133,7 @@
|
@@ -129,7 +129,7 @@
|
||||||
float f = (float)(i >> 16 & 255) / 255.0F;
|
float f = (float)(i >> 16 & 255) / 255.0F;
|
||||||
float f1 = (float)(i >> 8 & 255) / 255.0F;
|
float f1 = (float)(i >> 8 & 255) / 255.0F;
|
||||||
float f2 = (float)(i & 255) / 255.0F;
|
float f2 = (float)(i & 255) / 255.0F;
|
||||||
|
@ -47,7 +36,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -216,6 +220,7 @@
|
@@ -216,6 +216,7 @@
|
||||||
crashreportcategory.func_189529_a("Item Type", () -> {
|
crashreportcategory.func_189529_a("Item Type", () -> {
|
||||||
return String.valueOf((Object)p_184391_2_.func_77973_b());
|
return String.valueOf((Object)p_184391_2_.func_77973_b());
|
||||||
});
|
});
|
||||||
|
@ -55,7 +44,7 @@
|
||||||
crashreportcategory.func_189529_a("Item Damage", () -> {
|
crashreportcategory.func_189529_a("Item Damage", () -> {
|
||||||
return String.valueOf(p_184391_2_.func_77952_i());
|
return String.valueOf(p_184391_2_.func_77952_i());
|
||||||
});
|
});
|
||||||
@@ -247,18 +252,16 @@
|
@@ -247,18 +248,16 @@
|
||||||
irendertypebuffer$impl.func_228461_a_();
|
irendertypebuffer$impl.func_228461_a_();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,7 +67,7 @@
|
||||||
this.func_181565_a(bufferbuilder, p_180453_3_ + 2, p_180453_4_ + 13, 13, 2, 0, 0, 0, 255);
|
this.func_181565_a(bufferbuilder, p_180453_3_ + 2, p_180453_4_ + 13, 13, 2, 0, 0, 0, 255);
|
||||||
this.func_181565_a(bufferbuilder, p_180453_3_ + 2, p_180453_4_ + 13, i, 1, j >> 16 & 255, j >> 8 & 255, j & 255, 255);
|
this.func_181565_a(bufferbuilder, p_180453_3_ + 2, p_180453_4_ + 13, i, 1, j >> 16 & 255, j >> 8 & 255, j & 255, 255);
|
||||||
RenderSystem.enableBlend();
|
RenderSystem.enableBlend();
|
||||||
@@ -296,4 +299,9 @@
|
@@ -296,4 +295,9 @@
|
||||||
public void func_195410_a(IResourceManager p_195410_1_) {
|
public void func_195410_a(IResourceManager p_195410_1_) {
|
||||||
this.field_175059_m.func_178085_b();
|
this.field_175059_m.func_178085_b();
|
||||||
}
|
}
|
||||||
|
|
|
@ -557,166 +557,6 @@ public class ForgeHooksClient
|
||||||
return new Material(AtlasTexture.LOCATION_BLOCKS_TEXTURE, loc);
|
return new Material(AtlasTexture.LOCATION_BLOCKS_TEXTURE, loc);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class LightGatheringTransformer extends QuadGatheringTransformer {
|
|
||||||
|
|
||||||
private static final VertexFormat FORMAT = new VertexFormat(ImmutableList.of(DefaultVertexFormats.TEX_2F, DefaultVertexFormats.TEX_2S));
|
|
||||||
|
|
||||||
int blockLight, skyLight;
|
|
||||||
|
|
||||||
{ setVertexFormat(FORMAT); }
|
|
||||||
|
|
||||||
boolean hasLighting()
|
|
||||||
{
|
|
||||||
return dataLength[1] >= 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void processQuad()
|
|
||||||
{
|
|
||||||
// Reset light data
|
|
||||||
blockLight = 0;
|
|
||||||
skyLight = 0;
|
|
||||||
// Compute average light for all 4 vertices
|
|
||||||
for (int i = 0; i < 4; i++)
|
|
||||||
{
|
|
||||||
blockLight += (int) ((quadData[1][i][0] * 0xFFFF) / 0x20);
|
|
||||||
skyLight += (int) ((quadData[1][i][1] * 0xFFFF) / 0x20);
|
|
||||||
}
|
|
||||||
// Values must be multiplied by 16, divided by 4 for average => x4
|
|
||||||
blockLight *= 4;
|
|
||||||
skyLight *= 4;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Dummy overrides
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setQuadTint(int tint) {}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setQuadOrientation(Direction orientation) {}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setApplyDiffuseLighting(boolean diffuse) {}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setTexture(TextureAtlasSprite texture) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final LightGatheringTransformer lightGatherer = new LightGatheringTransformer();
|
|
||||||
|
|
||||||
// TODO: Fix: Vanilla now batches rendering items, so our hack of forcing the GL lighting state does not work.
|
|
||||||
public static void renderLitItem(ItemRenderer ri, MatrixStack mat, IVertexBuilder consumer, IBakedModel model, ItemStack stack)
|
|
||||||
{
|
|
||||||
List<BakedQuad> allquads = new ArrayList<>();
|
|
||||||
Random random = new Random();
|
|
||||||
long seed = 42L;
|
|
||||||
|
|
||||||
for (Direction enumfacing : Direction.values())
|
|
||||||
{
|
|
||||||
random.setSeed(seed);
|
|
||||||
allquads.addAll(model.getQuads(null, enumfacing, random, EmptyModelData.INSTANCE));
|
|
||||||
}
|
|
||||||
|
|
||||||
random.setSeed(seed);
|
|
||||||
allquads.addAll(model.getQuads(null, null, random, EmptyModelData.INSTANCE));
|
|
||||||
|
|
||||||
if (allquads.isEmpty()) return;
|
|
||||||
|
|
||||||
// Current list of consecutive quads with the same lighting
|
|
||||||
List<BakedQuad> segment = new ArrayList<>();
|
|
||||||
|
|
||||||
// Lighting of the current segment
|
|
||||||
int segmentBlockLight = 0;
|
|
||||||
int segmentSkyLight = 0;
|
|
||||||
// Diffuse lighting state
|
|
||||||
boolean segmentShading = true;
|
|
||||||
// State changed by the current segment
|
|
||||||
boolean segmentLightingDirty = false;
|
|
||||||
boolean segmentShadingDirty = false;
|
|
||||||
// If the current segment contains lighting data
|
|
||||||
boolean hasLighting = false;
|
|
||||||
|
|
||||||
for (int i = 0; i < allquads.size(); i++)
|
|
||||||
{
|
|
||||||
BakedQuad q = allquads.get(i);
|
|
||||||
|
|
||||||
// Lighting of the current quad
|
|
||||||
int bl = 0;
|
|
||||||
int sl = 0;
|
|
||||||
|
|
||||||
LightUtil.putBakedQuad(lightGatherer, q);
|
|
||||||
if (lightGatherer.hasLighting())
|
|
||||||
{
|
|
||||||
bl = lightGatherer.blockLight;
|
|
||||||
sl = lightGatherer.skyLight;
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean shade = q.shouldApplyDiffuseLighting();
|
|
||||||
|
|
||||||
boolean lightingDirty = segmentBlockLight != bl || segmentSkyLight != sl;
|
|
||||||
boolean shadeDirty = shade != segmentShading;
|
|
||||||
|
|
||||||
// If lighting or color data has changed, draw the segment and flush it
|
|
||||||
if (lightingDirty || shadeDirty)
|
|
||||||
{
|
|
||||||
if (i > 0) // Make sure this isn't the first quad being processed
|
|
||||||
drawSegment(ri, mat, consumer, stack, segment, segmentBlockLight, segmentSkyLight, segmentShading, segmentLightingDirty && (hasLighting || segment.size() < i), segmentShadingDirty);
|
|
||||||
segmentBlockLight = bl;
|
|
||||||
segmentSkyLight = sl;
|
|
||||||
segmentShading = shade;
|
|
||||||
segmentLightingDirty = lightingDirty;
|
|
||||||
segmentShadingDirty = shadeDirty;
|
|
||||||
hasLighting = segmentBlockLight > 0 || segmentSkyLight > 0 || !segmentShading;
|
|
||||||
}
|
|
||||||
|
|
||||||
segment.add(q);
|
|
||||||
}
|
|
||||||
|
|
||||||
drawSegment(ri, mat, consumer, stack, segment, segmentBlockLight, segmentSkyLight, segmentShading, segmentLightingDirty && (hasLighting || segment.size() < allquads.size()), segmentShadingDirty);
|
|
||||||
|
|
||||||
// Clean up render state if necessary
|
|
||||||
if (hasLighting)
|
|
||||||
{
|
|
||||||
RenderSystem.glMultiTexCoord2f(GL13.GL_TEXTURE1, GlStateManager.lastBrightnessX, GlStateManager.lastBrightnessY);
|
|
||||||
RenderSystem.enableLighting();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void drawSegment(ItemRenderer ir, MatrixStack mat, IVertexBuilder cons, ItemStack stack, List<BakedQuad> segment, int bl, int sl, boolean shade, boolean updateLighting, boolean updateShading)
|
|
||||||
{
|
|
||||||
float lastBl = GlStateManager.lastBrightnessX;
|
|
||||||
float lastSl = GlStateManager.lastBrightnessY;
|
|
||||||
|
|
||||||
if (updateShading)
|
|
||||||
{
|
|
||||||
if (shade)
|
|
||||||
{
|
|
||||||
// (Re-)enable lighting for normal look with shading
|
|
||||||
RenderSystem.enableLighting();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Disable lighting to simulate a lack of diffuse lighting
|
|
||||||
RenderSystem.disableLighting();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (updateLighting)
|
|
||||||
{
|
|
||||||
// Force lightmap coords to simulate synthetic lighting
|
|
||||||
RenderSystem.glMultiTexCoord2f(GL13.GL_TEXTURE1, Math.max(bl, lastBl), Math.max(sl, lastSl));
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO can we just use this light value ??
|
|
||||||
ir.func_229112_a_(mat, cons, segment, stack, (bl << 16) | sl, OverlayTexture.field_229196_a_);
|
|
||||||
|
|
||||||
// Preserve this as it represents the "world" lighting
|
|
||||||
GlStateManager.lastBrightnessX = lastBl;
|
|
||||||
GlStateManager.lastBrightnessY = lastSl;
|
|
||||||
|
|
||||||
segment.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* internal, relies on fixed format of FaceBakery
|
* internal, relies on fixed format of FaceBakery
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -30,6 +30,8 @@ import net.minecraft.client.renderer.Vector4f;
|
||||||
import net.minecraft.client.renderer.model.BakedQuad;
|
import net.minecraft.client.renderer.model.BakedQuad;
|
||||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||||
import net.minecraft.util.math.Vec3i;
|
import net.minecraft.util.math.Vec3i;
|
||||||
|
import net.minecraftforge.client.model.pipeline.LightUtil;
|
||||||
|
|
||||||
import org.lwjgl.system.MemoryStack;
|
import org.lwjgl.system.MemoryStack;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
@ -108,8 +110,9 @@ public interface IForgeVertexBuilder
|
||||||
default int applyBakedLighting(int lightmapCoord, ByteBuffer data) {
|
default int applyBakedLighting(int lightmapCoord, ByteBuffer data) {
|
||||||
int bl = LightTexture.func_228450_a_(lightmapCoord);
|
int bl = LightTexture.func_228450_a_(lightmapCoord);
|
||||||
int sl = LightTexture.func_228454_b_(lightmapCoord);
|
int sl = LightTexture.func_228454_b_(lightmapCoord);
|
||||||
int blBaked = Short.toUnsignedInt(data.getShort(24)) >> 4;
|
int offset = LightUtil.getLightOffset(0) * 4; // int offset for vertex 0 * 4 bytes per int
|
||||||
int slBaked = Short.toUnsignedInt(data.getShort(26)) >> 4;
|
int blBaked = Short.toUnsignedInt(data.getShort(offset)) >> 4;
|
||||||
|
int slBaked = Short.toUnsignedInt(data.getShort(offset + 2)) >> 4;
|
||||||
bl = Math.max(bl, blBaked);
|
bl = Math.max(bl, blBaked);
|
||||||
sl = Math.max(sl, slBaked);
|
sl = Math.max(sl, slBaked);
|
||||||
return LightTexture.func_228451_a_(bl, sl);
|
return LightTexture.func_228451_a_(bl, sl);
|
||||||
|
|
|
@ -247,6 +247,20 @@ public class LightUtil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int getLightOffset(int v)
|
||||||
|
{
|
||||||
|
return (v * 8) + 6;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setLightData(BakedQuad q, int light)
|
||||||
|
{
|
||||||
|
int[] data = q.getVertexData();
|
||||||
|
for (int i = 0; i < 4; i++)
|
||||||
|
{
|
||||||
|
data[getLightOffset(i)] = light;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static final class ItemPipeline
|
private static final class ItemPipeline
|
||||||
{
|
{
|
||||||
|
|
|
@ -133,8 +133,6 @@ public class ForgeConfig
|
||||||
|
|
||||||
public final BooleanValue showLoadWarnings;
|
public final BooleanValue showLoadWarnings;
|
||||||
|
|
||||||
public final BooleanValue allowEmissiveItems;
|
|
||||||
|
|
||||||
Client(ForgeConfigSpec.Builder builder) {
|
Client(ForgeConfigSpec.Builder builder) {
|
||||||
builder.comment("Client only settings, mostly things related to rendering")
|
builder.comment("Client only settings, mostly things related to rendering")
|
||||||
.push("client");
|
.push("client");
|
||||||
|
@ -176,11 +174,6 @@ public class ForgeConfig
|
||||||
.translation("forge.configgui.showloadwarnings")
|
.translation("forge.configgui.showloadwarnings")
|
||||||
.define("showLoadWarnings", true);
|
.define("showLoadWarnings", true);
|
||||||
|
|
||||||
allowEmissiveItems = builder
|
|
||||||
.comment("Allow item rendering to detect emissive quads and draw them properly. This allows glowing blocks to look the same in item form, but incurs a very slight performance hit.")
|
|
||||||
.translation("forge.configgui.allowEmissiveItems")
|
|
||||||
.define("allowEmissiveItems", true);
|
|
||||||
|
|
||||||
builder.pop();
|
builder.pop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue