Skip to content

Commit

Permalink
Merge pull request #11 from TimLee9024/1.16.5-Fabric-2.0
Browse files Browse the repository at this point in the history
Update to 2.0.1.0
  • Loading branch information
Protoxy22 authored Nov 20, 2022
2 parents 57a05f9 + 10a8e52 commit ab1a465
Show file tree
Hide file tree
Showing 9 changed files with 525 additions and 55 deletions.
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ In order to adapt into BSL Shaders' SEUS/Old PBR format, some change were made:
- `Occlusion(R)Roughness(G)Metallic(B)` textures and `Emissive color(RGB)` textures had been edited and combined into `Glossiness(R)Metallic(G)Emissive strength(B)` textures for specular map.
## Additonal Note About Setup This Project
1. Before build MCglTF for developmental environment. There is two ways you can choose to avoid gradle compilation error for OptiFine code reference.
- Simply replace [this line](https://github.com/TimLee9024/MCglTF/blob/5d9f897778d27886b52c9ab3c1c41b57f300385c/src/main/java/com/timlee9024/mcgltf/MCglTF.java#L274) with `return false;` in `isShaderModActive()`.
- Download OptiFine and delete everything except files and folders inside `net/optifine/` of OptiFine JAR. Then put modified OptiFine JAR into a newly created folder named `libs` in the same dir level as `src` of MCglTF project.
2. Build MCglTF with "gradlew build" to create a `-dev` version of MCglTF which is inside `build/devlibs`.
3. Create a folder named `libs` in the same dir level as `src` of MCglTF-Example project.
4. Put `-dev` version of MCglTF into the `libs` folder.
5. In Eclipse IDE, add MCglTF jar as `Referenced Libraries` via `Project > Properties > Java Build Path > Libraries > Add JARs`.
- Simply remove any OptiFine code reference in MCglTF.java.
- Or download OptiFine and delete everything except files and folders inside `notch/net/optifine/` of OptiFine JAR. Move all files and folders from `notch/net/optifine/` to `net/optifine/`, which means the `net` folder is now in the root of OptiFine JAR. Then put modified OptiFine JAR into a newly created folder named `libs` in the same dir level as `src` of MCglTF project.
2. Build Iris Shaders for development environment and put into `libs` folder in the same dir level as `src` of MCglTF project.
3. Build MCglTF with "gradlew build" to create a `-dev` version of MCglTF which is inside `build/devlibs`.
4. Create a folder named `libs` in the same dir level as `src` of MCglTF-Example project.
5. Put `-dev` version of MCglTF into the `libs` folder.
6. In Eclipse IDE, add MCglTF jar as `Referenced Libraries` via `Project > Properties > Java Build Path > Libraries > Add JARs`.
### Alternative Way
Using [Curse Maven](https://www.cursemaven.com/) to add MCglTF into project via [build.gradle](https://www.cursemaven.com/fabric)
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ org.gradle.jvmargs=-Xmx4G
loader_version=0.14.10

# Mod Properties
mod_version = 1.16.5-Fabric-2.0.0.0
mod_version = 1.16.5-Fabric-2.0.1.0
maven_group = com.modularmods.mcgltf.example
archives_base_name = MCglTF-Example

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ public void onReceiveSharedModel(RenderedGltfModel renderedModel) {

/**
* Since you use custom BEWLR(DynamicItemRenderer) for BlockItem instead of BER to render item form of block,
* the last parameters p_225616_6_ which control overlay color is almost never used.
* the last parameters which control overlay color is almost never used.
*/
@Override
public void render(ExampleBlockEntity p_225616_1_, float p_225616_2_, PoseStack p_225616_3_, MultiBufferSource p_225616_4_, int p_225616_5_, int p_225616_6_) {
public void render(ExampleBlockEntity blockEntity, float tickDelta, PoseStack matrices, MultiBufferSource vertexConsumers, int light, int overlay) {
GL11.glPushMatrix();
GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);

Expand All @@ -67,10 +67,10 @@ public void render(ExampleBlockEntity p_225616_1_, float p_225616_2_, PoseStack
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

RenderSystem.multMatrix(p_225616_3_.last().pose());
Level level = p_225616_1_.getLevel();
RenderSystem.multMatrix(matrices.last().pose());
Level level = blockEntity.getLevel();
if(level != null) {
float time = (level.getGameTime() + p_225616_2_) / 20;
float time = (level.getGameTime() + tickDelta) / 20;
//Play every animation clips simultaneously
for(List<InterpolatedChannel> animation : animations) {
animation.parallelStream().forEach((channel) -> {
Expand All @@ -80,7 +80,7 @@ public void render(ExampleBlockEntity p_225616_1_, float p_225616_2_, PoseStack
}

GL11.glTranslatef(0.5F, 0.0F, 0.5F); //Make sure it is in the center of the block
switch(level.getBlockState(p_225616_1_.getBlockPos()).getOptionalValue(HorizontalDirectionalBlock.FACING).orElse(Direction.NORTH)) {
switch(level.getBlockState(blockEntity.getBlockPos()).getOptionalValue(HorizontalDirectionalBlock.FACING).orElse(Direction.NORTH)) {
case DOWN:
break;
case UP:
Expand All @@ -99,7 +99,7 @@ public void render(ExampleBlockEntity p_225616_1_, float p_225616_2_, PoseStack
}
}

GL13.glMultiTexCoord2s(GL13.GL_TEXTURE2, (short)(p_225616_5_ & '\uffff'), (short)(p_225616_5_ >> 16 & '\uffff'));
GL13.glMultiTexCoord2s(GL13.GL_TEXTURE2, (short)(light & '\uffff'), (short)(light >> 16 & '\uffff'));

if(MCglTF.getInstance().isShaderModActive()) {
renderedScene.renderForShaderMod();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
package com.modularmods.mcgltf.example;

import java.util.List;

import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;
import org.lwjgl.opengl.GL13;

import com.modularmods.mcgltf.MCglTF;
import com.modularmods.mcgltf.animation.InterpolatedChannel;
import com.modularmods.mcgltf.iris.IrisRenderingHook;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Matrix4f;

import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderDispatcher;
import net.minecraft.client.renderer.texture.TextureAtlas;
import net.minecraft.core.Direction;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.HorizontalDirectionalBlock;

public class ExampleBlockEntityRendererIris extends ExampleBlockEntityRenderer {

public ExampleBlockEntityRendererIris(BlockEntityRenderDispatcher p_i226006_1_) {
super(p_i226006_1_);
}

@Override
public void render(ExampleBlockEntity blockEntity, float tickDelta, PoseStack matrices, MultiBufferSource vertexConsumers, int light, int overlay) {
RenderType renderType = RenderType.entitySolid(TextureAtlas.LOCATION_BLOCKS);
vertexConsumers.getBuffer(renderType); //Put renderType into MultiBufferSource to ensure command submit to IrisRenderingHook will be run in Iris batched entity rendering.
Matrix4f modelViewMatrix = matrices.last().pose().copy();

if(MCglTF.getInstance().isShaderModActive()) {
IrisRenderingHook.submitCommandForIrisRenderingByPhaseName("BLOCK_ENTITIES", renderType, () -> {
GL11.glPushMatrix();
GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);

GL11.glShadeModel(GL11.GL_SMOOTH);

GL11.glEnable(GL12.GL_RESCALE_NORMAL);
GL11.glEnable(GL11.GL_BLEND); //Since the renderType is entity solid, we need to turn on blending manually.
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

RenderSystem.multMatrix(modelViewMatrix);
Level level = blockEntity.getLevel();
if(level != null) {
float time = (level.getGameTime() + tickDelta) / 20;
//Play every animation clips simultaneously
for(List<InterpolatedChannel> animation : animations) {
animation.parallelStream().forEach((channel) -> {
float[] keys = channel.getKeys();
channel.update(time % keys[keys.length - 1]);
});
}

GL11.glTranslatef(0.5F, 0.0F, 0.5F); //Make sure it is in the center of the block
switch(level.getBlockState(blockEntity.getBlockPos()).getOptionalValue(HorizontalDirectionalBlock.FACING).orElse(Direction.NORTH)) {
case DOWN:
break;
case UP:
break;
case NORTH:
break;
case SOUTH:
GL11.glRotatef(180.0F, 0.0F, 1.0F, 0.0F);
break;
case WEST:
GL11.glRotatef(90.0F, 0.0F, 1.0F, 0.0F);
break;
case EAST:
GL11.glRotatef(-90.0F, 0.0F, 1.0F, 0.0F);
break;
}
}

GL13.glMultiTexCoord2s(GL13.GL_TEXTURE1, (short)(overlay & '\uffff'), (short)(overlay >> 16 & '\uffff'));
GL13.glMultiTexCoord2s(GL13.GL_TEXTURE2, (short)(light & '\uffff'), (short)(light >> 16 & '\uffff'));

renderedScene.renderForShaderMod();

GL11.glPopAttrib();
GL11.glPopMatrix();
});
}
else {
IrisRenderingHook.submitCommandForIrisRenderingByPhaseName("NONE", renderType, () -> {
GL11.glPushMatrix();
GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);

GL11.glShadeModel(GL11.GL_SMOOTH);

GL11.glEnable(GL12.GL_RESCALE_NORMAL);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

RenderSystem.multMatrix(modelViewMatrix);
Level level = blockEntity.getLevel();
if(level != null) {
float time = (level.getGameTime() + tickDelta) / 20;
for(List<InterpolatedChannel> animation : animations) {
animation.parallelStream().forEach((channel) -> {
float[] keys = channel.getKeys();
channel.update(time % keys[keys.length - 1]);
});
}

GL11.glTranslatef(0.5F, 0.0F, 0.5F);
switch(level.getBlockState(blockEntity.getBlockPos()).getOptionalValue(HorizontalDirectionalBlock.FACING).orElse(Direction.NORTH)) {
case DOWN:
break;
case UP:
break;
case NORTH:
break;
case SOUTH:
GL11.glRotatef(180.0F, 0.0F, 1.0F, 0.0F);
break;
case WEST:
GL11.glRotatef(90.0F, 0.0F, 1.0F, 0.0F);
break;
case EAST:
GL11.glRotatef(-90.0F, 0.0F, 1.0F, 0.0F);
break;
}
}

GL13.glMultiTexCoord2s(GL13.GL_TEXTURE1, (short)(overlay & '\uffff'), (short)(overlay >> 16 & '\uffff'));
GL13.glMultiTexCoord2s(GL13.GL_TEXTURE2, (short)(light & '\uffff'), (short)(light >> 16 & '\uffff'));

renderedScene.renderForVanilla();

GL11.glPopAttrib();
GL11.glPopMatrix();
});
}
}

}
98 changes: 67 additions & 31 deletions src/main/java/com/modularmods/mcgltf/example/ExampleClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import net.fabricmc.fabric.api.client.rendereregistry.v1.EntityRendererRegistry;
import net.fabricmc.fabric.api.client.rendering.v1.BuiltinItemRendererRegistry;
import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderEvents;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.resources.ResourceLocation;

public class ExampleClient implements ClientModInitializer {
Expand All @@ -23,37 +24,72 @@ public void onInitializeClient() {
tickDelta = listener.tickDelta();
});

BlockEntityRendererRegistry.INSTANCE.register(Example.INSTANCE.exampleBlockEntityType, (dispatcher) -> {
ExampleBlockEntityRenderer ber = new ExampleBlockEntityRenderer(dispatcher);
MCglTF.getInstance().addGltfModelReceiver(ber);
return ber;
});

EntityRendererRegistry.INSTANCE.register(Example.INSTANCE.exampleEntityType, (dispatcher, context) -> {
ExampleEntityRenderer entityRenderer = new ExampleEntityRenderer(dispatcher);
MCglTF.getInstance().addGltfModelReceiver(entityRenderer);
return entityRenderer;
});

ExampleItemRenderer itemRenderer = new ExampleItemRenderer() {

@Override
public ResourceLocation getModelLocation() {
return new ResourceLocation("mcgltf", "models/item/water_bottle.gltf");
}
};
MCglTF.getInstance().addGltfModelReceiver(itemRenderer);
BuiltinItemRendererRegistry.INSTANCE.register(Example.INSTANCE.item, itemRenderer);

ExampleItemRenderer blockItemRenderer = new ExampleItemRenderer() {

@Override
public ResourceLocation getModelLocation() {
return new ResourceLocation("mcgltf", "models/block/boom_box.gltf");
}
};
MCglTF.getInstance().addGltfModelReceiver(blockItemRenderer);
BuiltinItemRendererRegistry.INSTANCE.register(Example.INSTANCE.blockItem, blockItemRenderer);
if(FabricLoader.getInstance().isModLoaded("iris")) {
BlockEntityRendererRegistry.INSTANCE.register(Example.INSTANCE.exampleBlockEntityType, (dispatcher) -> {
ExampleBlockEntityRenderer ber = new ExampleBlockEntityRendererIris(dispatcher);
MCglTF.getInstance().addGltfModelReceiver(ber);
return ber;
});

EntityRendererRegistry.INSTANCE.register(Example.INSTANCE.exampleEntityType, (dispatcher, context) -> {
ExampleEntityRenderer entityRenderer = new ExampleEntityRendererIris(dispatcher);
MCglTF.getInstance().addGltfModelReceiver(entityRenderer);
return entityRenderer;
});

ExampleItemRenderer itemRenderer = new ExampleItemRendererIris() {

@Override
public ResourceLocation getModelLocation() {
return new ResourceLocation("mcgltf", "models/item/water_bottle.gltf");
}
};
MCglTF.getInstance().addGltfModelReceiver(itemRenderer);
BuiltinItemRendererRegistry.INSTANCE.register(Example.INSTANCE.item, itemRenderer);

ExampleItemRenderer blockItemRenderer = new ExampleItemRendererIris() {

@Override
public ResourceLocation getModelLocation() {
return new ResourceLocation("mcgltf", "models/block/boom_box.gltf");
}
};
MCglTF.getInstance().addGltfModelReceiver(blockItemRenderer);
BuiltinItemRendererRegistry.INSTANCE.register(Example.INSTANCE.blockItem, blockItemRenderer);
}
else {
BlockEntityRendererRegistry.INSTANCE.register(Example.INSTANCE.exampleBlockEntityType, (dispatcher) -> {
ExampleBlockEntityRenderer ber = new ExampleBlockEntityRenderer(dispatcher);
MCglTF.getInstance().addGltfModelReceiver(ber);
return ber;
});

EntityRendererRegistry.INSTANCE.register(Example.INSTANCE.exampleEntityType, (dispatcher, context) -> {
ExampleEntityRenderer entityRenderer = new ExampleEntityRenderer(dispatcher);
MCglTF.getInstance().addGltfModelReceiver(entityRenderer);
return entityRenderer;
});

ExampleItemRenderer itemRenderer = new ExampleItemRenderer() {

@Override
public ResourceLocation getModelLocation() {
return new ResourceLocation("mcgltf", "models/item/water_bottle.gltf");
}
};
MCglTF.getInstance().addGltfModelReceiver(itemRenderer);
BuiltinItemRendererRegistry.INSTANCE.register(Example.INSTANCE.item, itemRenderer);

ExampleItemRenderer blockItemRenderer = new ExampleItemRenderer() {

@Override
public ResourceLocation getModelLocation() {
return new ResourceLocation("mcgltf", "models/block/boom_box.gltf");
}
};
MCglTF.getInstance().addGltfModelReceiver(blockItemRenderer);
BuiltinItemRendererRegistry.INSTANCE.register(Example.INSTANCE.blockItem, blockItemRenderer);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ public ResourceLocation getTextureLocation(ExampleEntity p_110775_1_) {
}

@Override
public void render(ExampleEntity p_225623_1_, float p_225623_2_, float p_225623_3_, PoseStack p_225623_4_, MultiBufferSource p_225623_5_, int p_225623_6_) {
float time = (p_225623_1_.level.getGameTime() + p_225623_3_) / 20;
public void render(ExampleEntity entity, float yRotDelta, float tickDelta, PoseStack matrices, MultiBufferSource vertexConsumers, int light) {
float time = (entity.level.getGameTime() + tickDelta) / 20;
//Play every animation clips simultaneously
for(List<InterpolatedChannel> animation : animations) {
animation.parallelStream().forEach((channel) -> {
Expand All @@ -75,10 +75,10 @@ public void render(ExampleEntity p_225623_1_, float p_225623_2_, float p_225623_
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

RenderSystem.multMatrix(p_225623_4_.last().pose());
GL11.glRotatef(Mth.rotLerp(p_225623_3_, p_225623_1_.yBodyRotO, p_225623_1_.yBodyRot), 0.0F, 1.0F, 0.0F);
RenderSystem.multMatrix(matrices.last().pose());
GL11.glRotatef(Mth.rotLerp(tickDelta, entity.yBodyRotO, entity.yBodyRot), 0.0F, 1.0F, 0.0F);

GL13.glMultiTexCoord2s(GL13.GL_TEXTURE2, (short)(p_225623_6_ & '\uffff'), (short)(p_225623_6_ >> 16 & '\uffff'));
GL13.glMultiTexCoord2s(GL13.GL_TEXTURE2, (short)(light & '\uffff'), (short)(light >> 16 & '\uffff'));

if(MCglTF.getInstance().isShaderModActive()) {
renderedScene.renderForShaderMod();
Expand All @@ -92,7 +92,11 @@ public void render(ExampleEntity p_225623_1_, float p_225623_2_, float p_225623_

GL11.glPopAttrib();
GL11.glPopMatrix();
super.render(p_225623_1_, p_225623_2_, p_225623_3_, p_225623_4_, p_225623_5_, p_225623_6_);
super.render(entity, yRotDelta, tickDelta, matrices, vertexConsumers, light);
}

protected void checkAndRenderNameTag(ExampleEntity entity, float yRotDelta, float tickDelta, PoseStack matrices, MultiBufferSource vertexConsumers, int light) {
super.render(entity, yRotDelta, tickDelta, matrices, vertexConsumers, light);
}

}
Loading

0 comments on commit ab1a465

Please sign in to comment.