mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-20 04:09:51 +00:00
Implement rendering for item models with emissive quads (#5047)
This commit is contained in:
1 parent
3cf97f43fe
commit
90c244acb4
5 files changed
+236
-9
No files matched your search
@@ -9,7 +9,19 @@
|
||||
this.func_175041_b();
|
||||
this.field_184395_f = p_i46552_3_;
|
||||
}
|
||||
@@ -137,7 +137,7 @@
|
||||
@@ -113,6 +113,11 @@
|
||||
|
||||
private void func_191967_a(IBakedModel p_191967_1_, int p_191967_2_, ItemStack p_191967_3_)
|
||||
{
|
||||
+ if (net.minecraftforge.common.ForgeModContainer.allowEmissiveItems)
|
||||
+ {
|
||||
+ net.minecraftforge.client.ForgeHooksClient.renderLitItem(this, p_191967_1_, p_191967_2_, p_191967_3_);
|
||||
+ return;
|
||||
+ }
|
||||
Tessellator tessellator = Tessellator.func_178181_a();
|
||||
BufferBuilder bufferbuilder = tessellator.func_178180_c();
|
||||
bufferbuilder.func_181668_a(7, DefaultVertexFormats.field_176599_b);
|
||||
@@ -137,7 +142,7 @@
|
||||
{
|
||||
GlStateManager.func_179131_c(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
GlStateManager.func_179091_B();
|
||||
@@ -18,7 +30,7 @@
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -218,7 +218,7 @@
|
||||
@@ -218,7 +223,7 @@
|
||||
k = k | -16777216;
|
||||
}
|
||||
|
||||
@@ -27,7 +39,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
@@ -240,17 +240,7 @@
|
||||
@@ -240,17 +245,7 @@
|
||||
public IBakedModel func_184393_a(ItemStack p_184393_1_, @Nullable World p_184393_2_, @Nullable EntityLivingBase p_184393_3_)
|
||||
{
|
||||
IBakedModel ibakedmodel = this.field_175059_m.func_178089_a(p_184393_1_);
|
||||
@@ -46,7 +58,7 @@
|
||||
}
|
||||
|
||||
public void func_184392_a(ItemStack p_184392_1_, EntityLivingBase p_184392_2_, ItemCameraTransforms.TransformType p_184392_3_, boolean p_184392_4_)
|
||||
@@ -274,14 +264,9 @@
|
||||
@@ -274,14 +269,9 @@
|
||||
GlStateManager.func_179147_l();
|
||||
GlStateManager.func_187428_a(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
|
||||
GlStateManager.func_179094_E();
|
||||
@@ -63,7 +75,7 @@
|
||||
this.func_180454_a(p_184394_1_, p_184394_2_);
|
||||
GlStateManager.func_187407_a(GlStateManager.CullFace.BACK);
|
||||
GlStateManager.func_179121_F();
|
||||
@@ -314,7 +299,7 @@
|
||||
@@ -314,7 +304,7 @@
|
||||
GlStateManager.func_187401_a(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
|
||||
GlStateManager.func_179131_c(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
this.func_180452_a(p_191962_2_, p_191962_3_, p_191962_4_.func_177556_c());
|
||||
@@ -72,7 +84,7 @@
|
||||
this.func_180454_a(p_191962_1_, p_191962_4_);
|
||||
GlStateManager.func_179118_c();
|
||||
GlStateManager.func_179101_C();
|
||||
@@ -367,6 +352,7 @@
|
||||
@@ -367,6 +357,7 @@
|
||||
return String.valueOf((Object)p_184391_2_.func_77973_b());
|
||||
}
|
||||
});
|
||||
@@ -80,7 +92,7 @@
|
||||
crashreportcategory.func_189529_a("Item Aux", new ICrashReportDetail<String>()
|
||||
{
|
||||
public String call() throws Exception
|
||||
@@ -413,9 +399,12 @@
|
||||
@@ -413,9 +404,12 @@
|
||||
p_180453_1_.func_175063_a(s, (float)(p_180453_3_ + 19 - 2 - p_180453_1_.func_78256_a(s)), (float)(p_180453_4_ + 6 + 3), 16777215);
|
||||
GlStateManager.func_179145_e();
|
||||
GlStateManager.func_179126_j();
|
||||
@@ -94,7 +106,7 @@
|
||||
{
|
||||
GlStateManager.func_179140_f();
|
||||
GlStateManager.func_179097_i();
|
||||
@@ -424,11 +413,10 @@
|
||||
@@ -424,11 +418,10 @@
|
||||
GlStateManager.func_179084_k();
|
||||
Tessellator tessellator = Tessellator.func_178181_a();
|
||||
BufferBuilder bufferbuilder = tessellator.func_178180_c();
|
||||
@@ -110,7 +122,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, i, 1, j >> 16 & 255, j >> 8 & 255, j & 255, 255);
|
||||
GlStateManager.func_179147_l();
|
||||
@@ -1099,6 +1087,7 @@
|
||||
@@ -1099,6 +1092,7 @@
|
||||
this.func_175029_a(Blocks.field_185779_df, TileEntityStructure.Mode.LOAD.func_185110_a(), "structure_block");
|
||||
this.func_175029_a(Blocks.field_185779_df, TileEntityStructure.Mode.CORNER.func_185110_a(), "structure_block");
|
||||
this.func_175029_a(Blocks.field_185779_df, TileEntityStructure.Mode.DATA.func_185110_a(), "structure_block");
|
||||
|
||||
@@ -28,7 +28,13 @@ import java.io.File;
|
||||
import java.lang.reflect.Field;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.FloatBuffer;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Deque;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
@@ -56,6 +62,8 @@ import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.OpenGlHelper;
|
||||
import net.minecraft.client.renderer.RenderGlobal;
|
||||
import net.minecraft.client.renderer.RenderItem;
|
||||
import net.minecraft.client.renderer.RenderHelper;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.renderer.block.model.BakedQuad;
|
||||
import net.minecraft.client.renderer.block.model.BlockFaceUV;
|
||||
import net.minecraft.client.renderer.block.model.IBakedModel;
|
||||
@@ -70,8 +78,10 @@ import net.minecraft.client.renderer.color.ItemColors;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.renderer.texture.TextureManager;
|
||||
import net.minecraft.client.renderer.texture.TextureMap;
|
||||
import net.minecraft.client.renderer.texture.TextureUtil;
|
||||
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
|
||||
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
|
||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormat;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormatElement;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormatElement.EnumUsage;
|
||||
@@ -124,6 +134,7 @@ import net.minecraftforge.client.model.animation.Animation;
|
||||
import net.minecraftforge.client.resource.IResourceType;
|
||||
import net.minecraftforge.client.resource.SelectiveReloadStateHandler;
|
||||
import net.minecraftforge.client.resource.VanillaResourceType;
|
||||
import net.minecraftforge.client.model.pipeline.QuadGatheringTransformer;
|
||||
import net.minecraftforge.common.ForgeModContainer;
|
||||
import net.minecraftforge.common.ForgeVersion;
|
||||
import net.minecraftforge.common.ForgeVersion.Status;
|
||||
@@ -144,6 +155,7 @@ import org.lwjgl.opengl.GL20;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
public class ForgeHooksClient
|
||||
@@ -581,6 +593,198 @@ public class ForgeHooksClient
|
||||
{
|
||||
tileItemMap.put(Pair.of(item, metadata), TileClass);
|
||||
}
|
||||
|
||||
private static class LightGatheringTransformer extends QuadGatheringTransformer {
|
||||
|
||||
private static final VertexFormat FORMAT = new VertexFormat().addElement(DefaultVertexFormats.TEX_2F).addElement(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(EnumFacing orientation) {}
|
||||
|
||||
@Override
|
||||
public void setApplyDiffuseLighting(boolean diffuse) {}
|
||||
|
||||
@Override
|
||||
public void setTexture(TextureAtlasSprite texture) {}
|
||||
}
|
||||
|
||||
private static final LightGatheringTransformer lightGatherer = new LightGatheringTransformer();
|
||||
|
||||
public static void renderLitItem(RenderItem ri, IBakedModel model, int color, ItemStack stack)
|
||||
{
|
||||
List<BakedQuad> allquads = new ArrayList<>();
|
||||
|
||||
for (EnumFacing enumfacing : EnumFacing.VALUES)
|
||||
{
|
||||
allquads.addAll(model.getQuads(null, enumfacing, 0));
|
||||
}
|
||||
|
||||
allquads.addAll(model.getQuads(null, null, 0));
|
||||
|
||||
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 = -1;
|
||||
int segmentSkyLight = -1;
|
||||
// Coloring of the current segment
|
||||
int segmentColorMultiplier = color;
|
||||
// If the current segment contains lighting data
|
||||
boolean hasLighting = false;
|
||||
|
||||
// Tint index cache to avoid unnecessary IItemColor lookups
|
||||
int prevTintIndex = -1;
|
||||
|
||||
for (int i = 0; i < allquads.size(); i++)
|
||||
{
|
||||
BakedQuad q = allquads.get(i);
|
||||
|
||||
// Lighting of the current quad
|
||||
int bl = 0;
|
||||
int sl = 0;
|
||||
|
||||
// Fail-fast on ITEM, as it cannot have light data
|
||||
if (q.getFormat() != DefaultVertexFormats.ITEM && q.getFormat().hasUvOffset(1))
|
||||
{
|
||||
q.pipe(lightGatherer);
|
||||
if (lightGatherer.hasLighting())
|
||||
{
|
||||
bl = lightGatherer.blockLight;
|
||||
sl = lightGatherer.skyLight;
|
||||
}
|
||||
}
|
||||
|
||||
int colorMultiplier = segmentColorMultiplier;
|
||||
|
||||
// If there is no color override, and this quad is tinted, we need to apply IItemColor
|
||||
if (color == 0xFFFFFFFF && q.hasTintIndex())
|
||||
{
|
||||
int tintIndex = q.getTintIndex();
|
||||
|
||||
if (prevTintIndex != tintIndex)
|
||||
{
|
||||
colorMultiplier = getColorMultiplier(stack, tintIndex);
|
||||
}
|
||||
prevTintIndex = tintIndex;
|
||||
}
|
||||
else
|
||||
{
|
||||
colorMultiplier = color;
|
||||
prevTintIndex = -1;
|
||||
}
|
||||
|
||||
boolean lightingDirty = segmentBlockLight != bl || segmentSkyLight != sl;
|
||||
boolean colorDirty = hasLighting && segmentColorMultiplier != colorMultiplier;
|
||||
|
||||
// If lighting or color data has changed, draw the segment and flush it
|
||||
if (lightingDirty || colorDirty)
|
||||
{
|
||||
if (i > 0) // Make sure this isn't the first quad being processed
|
||||
{
|
||||
drawSegment(ri, color, stack, segment, segmentBlockLight, segmentSkyLight, segmentColorMultiplier, lightingDirty && (hasLighting || segment.size() < i), colorDirty);
|
||||
}
|
||||
segmentBlockLight = bl;
|
||||
segmentSkyLight = sl;
|
||||
segmentColorMultiplier = colorMultiplier;
|
||||
hasLighting = segmentBlockLight > 0 || segmentSkyLight > 0;
|
||||
}
|
||||
|
||||
segment.add(q);
|
||||
}
|
||||
|
||||
drawSegment(ri, color, stack, segment, segmentBlockLight, segmentSkyLight, segmentColorMultiplier, hasLighting || segment.size() < allquads.size(), false);
|
||||
|
||||
// Clean up render state if necessary
|
||||
if (hasLighting)
|
||||
{
|
||||
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, OpenGlHelper.lastBrightnessX, OpenGlHelper.lastBrightnessY);
|
||||
GL11.glMaterial(GL11.GL_FRONT_AND_BACK, GL11.GL_EMISSION, RenderHelper.setColorBuffer(0, 0, 0, 1));
|
||||
}
|
||||
}
|
||||
|
||||
private static void drawSegment(RenderItem ri, int baseColor, ItemStack stack, List<BakedQuad> segment, int bl, int sl, int tintColor, boolean updateLighting, boolean updateColor)
|
||||
{
|
||||
BufferBuilder bufferbuilder = Tessellator.getInstance().getBuffer();
|
||||
bufferbuilder.begin(GL11.GL_QUADS, DefaultVertexFormats.ITEM);
|
||||
|
||||
float lastBl = OpenGlHelper.lastBrightnessX;
|
||||
float lastSl = OpenGlHelper.lastBrightnessY;
|
||||
|
||||
if (updateLighting || updateColor)
|
||||
{
|
||||
float emissive = Math.max(bl, sl) / 240f;
|
||||
|
||||
float r = (tintColor >>> 16 & 0xff) / 255f;
|
||||
float g = (tintColor >>> 8 & 0xff) / 255f;
|
||||
float b = (tintColor & 0xff) / 255f;
|
||||
|
||||
GL11.glMaterial(GL11.GL_FRONT_AND_BACK, GL11.GL_EMISSION, RenderHelper.setColorBuffer(emissive * r, emissive * g, emissive * b, 1));
|
||||
|
||||
if (updateLighting)
|
||||
{
|
||||
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, Math.max(bl, lastBl), Math.max(sl, lastSl));
|
||||
}
|
||||
}
|
||||
|
||||
ri.renderQuads(bufferbuilder, segment, baseColor, stack);
|
||||
Tessellator.getInstance().draw();
|
||||
|
||||
// Preserve this as it represents the "world" lighting
|
||||
OpenGlHelper.lastBrightnessX = lastBl;
|
||||
OpenGlHelper.lastBrightnessY = lastSl;
|
||||
|
||||
segment.clear();
|
||||
}
|
||||
|
||||
private static int getColorMultiplier(ItemStack stack, int tintIndex)
|
||||
{
|
||||
if (tintIndex == -1 || stack.isEmpty()) return 0xFFFFFFFF;
|
||||
|
||||
int colorMultiplier = Minecraft.getMinecraft().getItemColors().colorMultiplier(stack, tintIndex);
|
||||
|
||||
if (EntityRenderer.anaglyphEnable)
|
||||
{
|
||||
colorMultiplier = TextureUtil.anaglyphColor(colorMultiplier);
|
||||
}
|
||||
|
||||
// Always full opacity
|
||||
colorMultiplier |= 0xff << 24; // -16777216
|
||||
|
||||
return colorMultiplier;
|
||||
}
|
||||
|
||||
/**
|
||||
* internal, relies on fixed format of FaceBakery
|
||||
|
||||
@@ -122,6 +122,7 @@ public class ForgeModContainer extends DummyModContainer implements WorldAccessC
|
||||
public static boolean forgeCloudsEnabled = true;
|
||||
public static boolean disableStairSlabCulling = false; // Also known as the "DontCullStairsBecauseIUseACrappyTexturePackThatBreaksBasicBlockShapesSoICantTrustBasicBlockCulling" flag
|
||||
public static boolean alwaysSetupTerrainOffThread = false; // In RenderGlobal.setupTerrain, always force the chunk render updates to be queued to the thread
|
||||
public static boolean allowEmissiveItems; // see RenderItem#renderModel(IBakedModel, int, ItemStack)
|
||||
public static int dimensionUnloadQueueDelay = 0;
|
||||
public static boolean logCascadingWorldGeneration = true; // see Chunk#logCascadingWorldGeneration()
|
||||
public static boolean fixVanillaCascading = false; // There are various places in vanilla that cause cascading worldgen. Enabling this WILL change where blocks are placed to prevent this.
|
||||
@@ -346,6 +347,12 @@ public class ForgeModContainer extends DummyModContainer implements WorldAccessC
|
||||
alwaysSetupTerrainOffThread = prop.getBoolean(false);
|
||||
prop.setLanguageKey("forge.configgui.alwaysSetupTerrainOffThread");
|
||||
propOrder.add(prop.getName());
|
||||
|
||||
prop = config.get(Configuration.CATEGORY_CLIENT, "allowEmissiveItems", true,
|
||||
"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.");
|
||||
allowEmissiveItems = prop.getBoolean(true);
|
||||
prop.setLanguageKey("forge.configgui.allowEmissiveItems");
|
||||
propOrder.add(prop.getName());
|
||||
|
||||
prop = config.get(Configuration.CATEGORY_CLIENT, "biomeSkyBlendRange", new int[] { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34 });
|
||||
prop.setComment("Control the range of sky blending for colored skies in biomes.");
|
||||
|
||||
@@ -87,6 +87,8 @@ forge.configgui.zoomInMissingModelTextInGui=Zoom in Missing model text in the GU
|
||||
forge.configgui.disableStairSlabCulling.tooltip=Enable this if you see through blocks touching stairs/slabs with your resource pack.
|
||||
forge.configgui.alwaysSetupTerrainOffThread=Force threaded chunk rendering
|
||||
forge.configgui.alwaysSetupTerrainOffThread.tooltip=Enable forge to queue all chunk updates to the Chunk Update thread. May increase FPS significantly, but may also cause weird rendering lag. Not recommended for computers without a significant number of cores available.
|
||||
forge.configgui.allowEmissiveItems=Allow Emissive Item Rendering
|
||||
forge.configgui.allowEmissiveItems.tooltip=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.
|
||||
forge.configgui.selectiveResourceReloadEnabled=Enable Selective Resource Loading
|
||||
forge.configgui.selectiveResourceReloadEnabled.tooltip=When enabled, makes specific reload tasks such as language changing quicker to run.
|
||||
|
||||
|
||||
@@ -88,6 +88,8 @@ public net.minecraft.entity.item.EntityXPOrb field_70530_e # xpValue
|
||||
public net.minecraft.world.gen.structure.StructureVillagePieces$Village
|
||||
# RenderPlayer
|
||||
#public net.minecraft.client.renderer.entity.RenderBiped field_77071_a #modelBipedMain
|
||||
# RenderItem
|
||||
public net.minecraft.client.renderer.RenderItem func_191970_a(Lnet/minecraft/client/renderer/BufferBuilder;Ljava/util/List;ILnet/minecraft/item/ItemStack;)V # renderQuads
|
||||
# ChunkProviderServer
|
||||
public net.minecraft.world.gen.ChunkProviderServer field_186029_c # chunkGenerator
|
||||
public net.minecraft.world.gen.ChunkProviderServer field_73244_f # loadedChunkHashMap
|
||||
|
||||
Reference in new issue
Block a user