diff --git a/src/main/java/net/minecraftforge/client/extensions/IForgeVertexBuilder.java b/src/main/java/net/minecraftforge/client/extensions/IForgeVertexBuilder.java index 1a026f10c..3781390eb 100644 --- a/src/main/java/net/minecraftforge/client/extensions/IForgeVertexBuilder.java +++ b/src/main/java/net/minecraftforge/client/extensions/IForgeVertexBuilder.java @@ -107,8 +107,10 @@ public interface IForgeVertexBuilder default int applyBakedLighting(int lightmapCoord, ByteBuffer data) { int bl = LightTexture.func_228450_a_(lightmapCoord); int sl = LightTexture.func_228454_b_(lightmapCoord); - bl = Math.max(bl, Short.toUnsignedInt(data.getShort(26))); - sl = Math.max(sl, Short.toUnsignedInt(data.getShort(24))); + int blBaked = Short.toUnsignedInt(data.getShort(24)) >> 4; + int slBaked = Short.toUnsignedInt(data.getShort(26)) >> 4; + bl = Math.max(bl, blBaked); + sl = Math.max(sl, slBaked); return LightTexture.func_228451_a_(bl, sl); } diff --git a/src/main/java/net/minecraftforge/client/model/obj/OBJModel.java b/src/main/java/net/minecraftforge/client/model/obj/OBJModel.java index d98f4cc8b..b4777f03a 100644 --- a/src/main/java/net/minecraftforge/client/model/obj/OBJModel.java +++ b/src/main/java/net/minecraftforge/client/model/obj/OBJModel.java @@ -51,6 +51,7 @@ import java.util.stream.Collectors; public class OBJModel implements IMultipartModelGeometry { + private static Vector4f COLOR_WHITE = new Vector4f(1, 1, 1, 1); private static Vec2f[] DEFAULT_COORDS = { new Vec2f(0, 0), new Vec2f(0, 1), @@ -337,7 +338,7 @@ public class OBJModel implements IMultipartModelGeometry return Optional.ofNullable(parts.get(name)); } - private Pair makeQuad(int[][] indices, int tintIndex, Vector4f colorTint, Vector4f ambientColor, boolean isFullbright, TextureAtlasSprite texture, TransformationMatrix transform) + private Pair makeQuad(int[][] indices, int tintIndex, Vector4f colorTint, Vector4f ambientColor, TextureAtlasSprite texture, TransformationMatrix transform) { boolean needsNormalRecalculation = false; for (int[] ints : indices) @@ -364,10 +365,18 @@ public class OBJModel implements IMultipartModelGeometry BakedQuadBuilder builder = new BakedQuadBuilder(texture); builder.setQuadTint(tintIndex); - builder.setApplyDiffuseLighting(!isFullbright); - int fakeLight = (int)((ambientColor.getX() + ambientColor.getY() + ambientColor.getZ()) * 15 / 3.0f); - Vec2f uv2 = new Vec2f(((float) fakeLight * 0x20) / 0xFFFF, ((float) fakeLight * 0x20) / 0xFFFF); + boolean diffuse = true; + + Vec2f uv2 = new Vec2f(0,0); + if (ambientToFullbright) + { + int fakeLight = (int) ((ambientColor.getX() + ambientColor.getY() + ambientColor.getZ()) * 15 / 3.0f); + uv2 = new Vec2f((fakeLight << 4) / 32767.0f, (fakeLight << 4) / 32767.0f); + //uv2 = new Vec2f(0, (fakeLight << 4) / 32767.0f); + //uv2 = new Vec2f((fakeLight << 4) / 32767.0f, 0); + builder.setApplyDiffuseLighting(diffuse = (fakeLight > 0)); + } boolean hasTransform = !transform.isIdentity(); // The incoming transform is referenced on the center of the block, but our coords are referenced on the corner @@ -377,11 +386,11 @@ public class OBJModel implements IMultipartModelGeometry { int[] index = indices[Math.min(i,indices.length-1)]; Vector3f pos0 = positions.get(index[0]); - Vector4f position = new Vector4f(pos0.getX(), pos0.getY(), pos0.getZ(), 1); + Vector4f position = new Vector4f(pos0); Vec2f texCoord = index.length >= 2 && texCoords.size() > 0 ? texCoords.get(index[1]) : DEFAULT_COORDS[i]; Vector3f norm0 = !needsNormalRecalculation && index.length >= 3 && normals.size() > 0 ? normals.get(index[2]) : faceNormal; Vector3f normal = norm0; - Vector4f color = index.length >= 4 && colors.size() > 0 ? colors.get(index[3]) : new Vector4f(1, 1, 1, 1); + Vector4f color = index.length >= 4 && colors.size() > 0 ? colors.get(index[3]) : COLOR_WHITE; if (hasTransform) { normal = norm0.func_229195_e_(); @@ -393,6 +402,7 @@ public class OBJModel implements IMultipartModelGeometry color.getY() * colorTint.getY(), color.getZ() * colorTint.getZ(), color.getW() * colorTint.getW()); + if (!diffuse) normal = new Vector3f(0,0,0); putVertexData(builder, position, texCoord, normal, tintedColor, uv2, texture); pos[i] = position; norm[i] = normal; @@ -525,11 +535,10 @@ public class OBJModel implements IMultipartModelGeometry TextureAtlasSprite texture = spriteGetter.apply(ModelLoaderRegistry.resolveTexture(mat.diffuseColorMap, owner)); int tintIndex = mat.diffuseTintIndex; Vector4f colorTint = mat.diffuseColor; - boolean isFullbright = ambientToFullbright && mesh.isFullbright(); for (int[][] face : mesh.faces) { - Pair quad = makeQuad(face, tintIndex, colorTint, mat.ambientColor, isFullbright, texture, modelTransform.func_225615_b_()); + Pair quad = makeQuad(face, tintIndex, colorTint, mat.ambientColor, texture, modelTransform.func_225615_b_()); if (quad.getRight() == null) modelBuilder.addGeneralQuad(quad.getLeft()); else @@ -543,11 +552,6 @@ public class OBJModel implements IMultipartModelGeometry { return meshes.stream().map(mesh -> ModelLoaderRegistry.resolveTexture(mesh.mat.diffuseColorMap, owner)).collect(Collectors.toSet()); } - - public boolean hasAnyFullBright() - { - return meshes.stream().anyMatch(ModelMesh::isFullbright); - } } public class ModelGroup extends ModelObject @@ -582,12 +586,6 @@ public class OBJModel implements IMultipartModelGeometry combined.addAll(part.getTextures(owner, modelGetter, missingTextureErrors)); return combined; } - - @Override - public boolean hasAnyFullBright() - { - return super.hasAnyFullBright() || parts.values().stream().anyMatch(ModelObject::hasAnyFullBright); - } } private class ModelMesh @@ -603,11 +601,6 @@ public class OBJModel implements IMultipartModelGeometry this.mat = currentMat; this.smoothingGroup = currentSmoothingGroup; } - - public boolean isFullbright() - { - return mat != null && TransformationHelper.epsilonEquals(mat.ambientColor, new Vector4f(1,1,1,1), 1/256f); - } } public static class ModelSettings diff --git a/src/test/java/net/minecraftforge/debug/client/model/NewModelLoaderTest.java b/src/test/java/net/minecraftforge/debug/client/model/NewModelLoaderTest.java index fe20be8a4..352121c99 100644 --- a/src/test/java/net/minecraftforge/debug/client/model/NewModelLoaderTest.java +++ b/src/test/java/net/minecraftforge/debug/client/model/NewModelLoaderTest.java @@ -24,6 +24,8 @@ import net.minecraft.block.BlockState; import net.minecraft.block.FourWayBlock; import net.minecraft.block.material.Material; import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.RenderTypeLookup; import net.minecraft.client.renderer.model.ItemCameraTransforms; import net.minecraft.client.renderer.texture.AtlasTexture; import net.minecraft.entity.Entity; @@ -32,6 +34,10 @@ import net.minecraft.item.*; import net.minecraft.state.StateContainer; import net.minecraft.state.properties.BlockStateProperties; import net.minecraft.util.ResourceLocation; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.shapes.ISelectionContext; +import net.minecraft.util.math.shapes.VoxelShape; +import net.minecraft.world.IBlockReader; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.client.event.RenderGameOverlayEvent; import net.minecraftforge.client.model.ModelLoader; @@ -42,6 +48,7 @@ import net.minecraftforge.common.util.NonNullLazy; import net.minecraftforge.eventbus.api.IEventBus; import net.minecraftforge.fml.RegistryObject; import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; import net.minecraftforge.registries.DeferredRegister; import net.minecraftforge.registries.ForgeRegistries; @@ -71,6 +78,12 @@ public class NewModelLoaderTest BlockStateProperties.HORIZONTAL_FACING, context.getPlacementHorizontalFacing() ); } + + @Override + public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) + { + return Block.makeCuboidShape(2,2,2,14,14,14); + } } ); diff --git a/src/test/resources/assets/new_model_loader_test/models/block/obj_block.json b/src/test/resources/assets/new_model_loader_test/models/block/obj_block.json index 74cdffbb6..08465b0ba 100644 --- a/src/test/resources/assets/new_model_loader_test/models/block/obj_block.json +++ b/src/test/resources/assets/new_model_loader_test/models/block/obj_block.json @@ -1,17 +1,10 @@ { "parent": "forge:item/default", - "loader": "forge:composite", - "parts": { - "part1": { - "loader": "forge:obj", - "model": "new_model_loader_test:models/item/sugar_glider.obj", - "ambientToFullbright": true, - "textures": { - "qr": "minecraft:block/oak_planks" - } - } - }, + "loader": "forge:obj", + "model": "new_model_loader_test:models/item/sugar_glider.obj", + "ambientToFullbright": true, "textures": { + "qr": "minecraft:block/oak_planks", "particle": "block/oak_planks" } } diff --git a/src/test/resources/assets/new_model_loader_test/models/item/item_direction.mtl b/src/test/resources/assets/new_model_loader_test/models/item/item_direction.mtl index db7f1af66..545f6b216 100644 --- a/src/test/resources/assets/new_model_loader_test/models/item/item_direction.mtl +++ b/src/test/resources/assets/new_model_loader_test/models/item/item_direction.mtl @@ -1,7 +1,8 @@ newmtl None Ns 0 -Ka 1.0000 1.0000 1.0000 +Ka 0 0 0 Kd 0.8 0.8 0.8 Ks 0.8 0.8 0.8 d 1 illum 2 +map_Kd minecraft:block/coal_ore \ No newline at end of file diff --git a/src/test/resources/assets/new_model_loader_test/models/item/obj_block.json b/src/test/resources/assets/new_model_loader_test/models/item/obj_block.json index 99c49be2c..5ecd05efb 100644 --- a/src/test/resources/assets/new_model_loader_test/models/item/obj_block.json +++ b/src/test/resources/assets/new_model_loader_test/models/item/obj_block.json @@ -1,16 +1,5 @@ { - "parent": "forge:item/default", - "loader": "forge:composite", - "parts": { - "part1": { - "loader": "forge:obj", - "model": "new_model_loader_test:models/item/sugar_glider.obj", - "ambientToFullbright": true, - "textures": { - "qr": "new_model_loader_test:item/qr" - } - } - }, + "parent": "new_model_loader_test:block/obj_block", "textures": { "particle": "block/oak_planks" }, diff --git a/src/test/resources/assets/new_model_loader_test/models/item/sugar_glider.mtl b/src/test/resources/assets/new_model_loader_test/models/item/sugar_glider.mtl index 04ee34fde..383732fe1 100644 --- a/src/test/resources/assets/new_model_loader_test/models/item/sugar_glider.mtl +++ b/src/test/resources/assets/new_model_loader_test/models/item/sugar_glider.mtl @@ -1,6 +1,6 @@ # Rhino newmtl New material 001 (1) -Ka 0.0000 0.0000 0.0000 +Ka 0.5 0.5 0.5 Kd 0.4588 0.3333 0.1882 Ks 1.0000 1.0000 1.0000 Tf 0.0000 0.0000 0.0000 @@ -9,7 +9,7 @@ Ns 0 map_Kd #qr newmtl New material 001 -Ka 0.0000 0.0000 0.0000 +Ka 0.5 0.5 0.5 Kd 0.6745 0.5216 0.3412 Ks 1.0000 1.0000 1.0000 Tf 0.0000 0.0000 0.0000 @@ -18,7 +18,7 @@ Ns 0 map_Kd #qr newmtl Default -Ka 0.0000 0.0000 0.0000 +Ka 0.5 0.5 0.5 Kd 1.0000 1.0000 1.0000 Ks 1.0000 1.0000 1.0000 Tf 0.0000 0.0000 0.0000 @@ -27,7 +27,7 @@ Ns 0 map_Kd #qr newmtl New material 002 -Ka 0.0000 0.0000 0.0000 +Ka 0.5 0.5 0.5 Kd 0.4118 0.4118 0.4118 Ks 1.0000 1.0000 1.0000 Tf 0.0000 0.0000 0.0000 @@ -36,7 +36,7 @@ Ns 0 map_Kd #qr newmtl New material 003 -Ka 0.0000 0.0000 0.0000 +Ka 0.5 0.5 0.5 Kd 0.1490 0.1490 0.1490 Ks 1.0000 1.0000 1.0000 Tf 0.0000 0.0000 0.0000