Fix cell rendering (blessed Grondag for helping immensely)
|
@ -33,6 +33,7 @@ import net.minecraft.client.render.model.ModelLoader;
|
||||||
import net.minecraft.client.render.model.UnbakedModel;
|
import net.minecraft.client.render.model.UnbakedModel;
|
||||||
import net.minecraft.client.texture.Sprite;
|
import net.minecraft.client.texture.Sprite;
|
||||||
import net.minecraft.client.texture.SpriteAtlasTexture;
|
import net.minecraft.client.texture.SpriteAtlasTexture;
|
||||||
|
import net.minecraft.client.util.ModelIdentifier;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
import techreborn.client.render.DynamicCellBakedModel;
|
import techreborn.client.render.DynamicCellBakedModel;
|
||||||
|
|
||||||
|
@ -47,13 +48,20 @@ public class TechRebornClient implements ClientModInitializer {
|
||||||
@Override
|
@Override
|
||||||
public void onInitializeClient() {
|
public void onInitializeClient() {
|
||||||
ClientSpriteRegistryCallback.event(SpriteAtlasTexture.BLOCK_ATLAS_TEX)
|
ClientSpriteRegistryCallback.event(SpriteAtlasTexture.BLOCK_ATLAS_TEX)
|
||||||
.register((spriteAtlasTexture, registry) -> registry.register(new Identifier("techreborn:item/cell_base")));
|
.register((spriteAtlasTexture, registry) -> registry.register(new Identifier("techreborn:item/cell_base")));
|
||||||
|
|
||||||
|
ModelLoadingRegistry.INSTANCE.registerAppender((manager, out) -> {
|
||||||
|
out.accept(new ModelIdentifier(new Identifier(TechReborn.MOD_ID, "cell_base"), "inventory"));
|
||||||
|
out.accept(new ModelIdentifier(new Identifier(TechReborn.MOD_ID, "cell_fluid"), "inventory"));
|
||||||
|
out.accept(new ModelIdentifier(new Identifier(TechReborn.MOD_ID, "cell_background"), "inventory"));
|
||||||
|
out.accept(new ModelIdentifier(new Identifier(TechReborn.MOD_ID, "cell_glass"), "inventory"));
|
||||||
|
});
|
||||||
|
|
||||||
ModelLoadingRegistry.INSTANCE.registerVariantProvider(resourceManager -> (modelIdentifier, modelProviderContext) -> {
|
ModelLoadingRegistry.INSTANCE.registerVariantProvider(resourceManager -> (modelIdentifier, modelProviderContext) -> {
|
||||||
if(!modelIdentifier.getNamespace().equals("techreborn")){
|
if (!modelIdentifier.getNamespace().equals("techreborn")) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if(!modelIdentifier.getPath().equals("cell")){
|
if (!modelIdentifier.getPath().equals("cell")) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return new UnbakedModel() {
|
return new UnbakedModel() {
|
||||||
|
@ -77,5 +85,4 @@ public class TechRebornClient implements ClientModInitializer {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,13 +35,16 @@ import net.fabricmc.fabric.api.renderer.v1.mesh.MutableQuadView;
|
||||||
import net.fabricmc.fabric.api.renderer.v1.mesh.QuadEmitter;
|
import net.fabricmc.fabric.api.renderer.v1.mesh.QuadEmitter;
|
||||||
import net.fabricmc.fabric.api.renderer.v1.model.FabricBakedModel;
|
import net.fabricmc.fabric.api.renderer.v1.model.FabricBakedModel;
|
||||||
import net.fabricmc.fabric.api.renderer.v1.render.RenderContext;
|
import net.fabricmc.fabric.api.renderer.v1.render.RenderContext;
|
||||||
|
import net.fabricmc.indigo.renderer.helper.GeometryHelper;
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.MinecraftClient;
|
||||||
import net.minecraft.client.render.model.BakedModel;
|
import net.minecraft.client.render.model.BakedModel;
|
||||||
|
import net.minecraft.client.render.model.BakedModelManager;
|
||||||
import net.minecraft.client.render.model.BakedQuad;
|
import net.minecraft.client.render.model.BakedQuad;
|
||||||
import net.minecraft.client.render.model.json.ModelItemPropertyOverrideList;
|
import net.minecraft.client.render.model.json.ModelItemPropertyOverrideList;
|
||||||
import net.minecraft.client.render.model.json.ModelTransformation;
|
import net.minecraft.client.render.model.json.ModelTransformation;
|
||||||
import net.minecraft.client.texture.Sprite;
|
import net.minecraft.client.texture.Sprite;
|
||||||
|
import net.minecraft.client.util.ModelIdentifier;
|
||||||
import net.minecraft.entity.LivingEntity;
|
import net.minecraft.entity.LivingEntity;
|
||||||
import net.minecraft.fluid.Fluid;
|
import net.minecraft.fluid.Fluid;
|
||||||
import net.minecraft.fluid.Fluids;
|
import net.minecraft.fluid.Fluids;
|
||||||
|
@ -52,6 +55,7 @@ import net.minecraft.util.math.Direction;
|
||||||
import net.minecraft.world.ExtendedBlockView;
|
import net.minecraft.world.ExtendedBlockView;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import reborncore.common.fluid.container.ItemFluidInfo;
|
import reborncore.common.fluid.container.ItemFluidInfo;
|
||||||
|
import techreborn.TechReborn;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
@ -62,7 +66,12 @@ import java.util.function.Supplier;
|
||||||
|
|
||||||
public class DynamicCellBakedModel implements BakedModel, FabricBakedModel {
|
public class DynamicCellBakedModel implements BakedModel, FabricBakedModel {
|
||||||
|
|
||||||
Sprite base;
|
private final Sprite base;
|
||||||
|
|
||||||
|
private static final ModelIdentifier CELL_BASE = new ModelIdentifier(new Identifier(TechReborn.MOD_ID, "cell_base"), "inventory");
|
||||||
|
private static final ModelIdentifier CELL_BACKGROUND = new ModelIdentifier(new Identifier(TechReborn.MOD_ID, "cell_background"), "inventory");
|
||||||
|
private static final ModelIdentifier CELL_FLUID = new ModelIdentifier(new Identifier(TechReborn.MOD_ID, "cell_fluid"), "inventory");
|
||||||
|
private static final ModelIdentifier CELL_GLASS = new ModelIdentifier(new Identifier(TechReborn.MOD_ID, "cell_glass"), "inventory");
|
||||||
|
|
||||||
public DynamicCellBakedModel() {
|
public DynamicCellBakedModel() {
|
||||||
base = MinecraftClient.getInstance().getSpriteAtlas().getSprite(new Identifier("techreborn:item/cell_base"));
|
base = MinecraftClient.getInstance().getSpriteAtlas().getSprite(new Identifier("techreborn:item/cell_base"));
|
||||||
|
@ -76,12 +85,36 @@ public class DynamicCellBakedModel implements BakedModel, FabricBakedModel {
|
||||||
@Override
|
@Override
|
||||||
public void emitItemQuads(ItemStack stack, Supplier<Random> randomSupplier, RenderContext context) {
|
public void emitItemQuads(ItemStack stack, Supplier<Random> randomSupplier, RenderContext context) {
|
||||||
Fluid fluid = Fluids.EMPTY;
|
Fluid fluid = Fluids.EMPTY;
|
||||||
if(stack.getItem() instanceof ItemFluidInfo){
|
if (stack.getItem() instanceof ItemFluidInfo) {
|
||||||
ItemFluidInfo fluidInfo = (ItemFluidInfo) stack.getItem();
|
ItemFluidInfo fluidInfo = (ItemFluidInfo) stack.getItem();
|
||||||
fluid = fluidInfo.getFluid(stack);
|
fluid = fluidInfo.getFluid(stack);
|
||||||
|
|
||||||
}
|
}
|
||||||
context.meshConsumer().accept(getMesh(fluid));
|
BakedModelManager bakedModelManager = MinecraftClient.getInstance().getBakedModelManager();
|
||||||
|
context.fallbackConsumer().accept(bakedModelManager.getModel(CELL_BASE));
|
||||||
|
context.fallbackConsumer().accept(bakedModelManager.getModel(CELL_BACKGROUND));
|
||||||
|
|
||||||
|
if (fluid != Fluids.EMPTY) {
|
||||||
|
FluidRenderHandler fluidRenderHandler = FluidRenderHandlerRegistry.INSTANCE.get(fluid);
|
||||||
|
BakedModel fluidModel = bakedModelManager.getModel(CELL_FLUID);
|
||||||
|
int fluidColor = fluidRenderHandler.getFluidColor(MinecraftClient.getInstance().world, MinecraftClient.getInstance().player.getBlockPos(), fluid.getDefaultState());
|
||||||
|
Sprite fluidSprite = fluidRenderHandler.getFluidSprites(MinecraftClient.getInstance().world, BlockPos.ORIGIN, fluid.getDefaultState())[0];
|
||||||
|
int color = new Color((float) (fluidColor >> 16 & 255) / 255.0F, (float) (fluidColor >> 8 & 255) / 255.0F, (float) (fluidColor & 255) / 255.0F).getRGB();
|
||||||
|
context.pushTransform(quad -> {
|
||||||
|
quad.nominalFace(GeometryHelper.lightFace(quad));
|
||||||
|
quad.spriteColor(0, color, color, color, color);
|
||||||
|
quad.spriteBake(0, fluidSprite, MutableQuadView.BAKE_LOCK_UV);
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
final QuadEmitter emitter = context.getEmitter();
|
||||||
|
fluidModel.getQuads(null, null, randomSupplier.get()).forEach(q -> {
|
||||||
|
emitter.fromVanilla(q.getVertexData(), 0, false);
|
||||||
|
emitter.emit();
|
||||||
|
});
|
||||||
|
context.popTransform();
|
||||||
|
}
|
||||||
|
|
||||||
|
context.fallbackConsumer().accept(bakedModelManager.getModel(CELL_GLASS));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -90,7 +123,7 @@ public class DynamicCellBakedModel implements BakedModel, FabricBakedModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
//I have no idea what im doing, this works good enough for me, if you want to make it nicer a PR or tips would be appreciated, thanks.
|
//I have no idea what im doing, this works good enough for me, if you want to make it nicer a PR or tips would be appreciated, thanks.
|
||||||
private Mesh getMesh(Fluid fluid){
|
private Mesh getMesh(Fluid fluid) {
|
||||||
Renderer renderer = RendererAccess.INSTANCE.getRenderer();
|
Renderer renderer = RendererAccess.INSTANCE.getRenderer();
|
||||||
MeshBuilder builder = renderer.meshBuilder();
|
MeshBuilder builder = renderer.meshBuilder();
|
||||||
QuadEmitter emitter = builder.getEmitter();
|
QuadEmitter emitter = builder.getEmitter();
|
||||||
|
@ -99,22 +132,22 @@ public class DynamicCellBakedModel implements BakedModel, FabricBakedModel {
|
||||||
|
|
||||||
//TODO make the base texture 3d somehow
|
//TODO make the base texture 3d somehow
|
||||||
emitter.square(Direction.SOUTH, 0, 0, 1, 1, 0)
|
emitter.square(Direction.SOUTH, 0, 0, 1, 1, 0)
|
||||||
.material(mat)
|
.material(mat)
|
||||||
.spriteColor(0, -1, -1, -1, -1)
|
.spriteColor(0, -1, -1, -1, -1)
|
||||||
.spriteBake(0, base, MutableQuadView.BAKE_LOCK_UV).emit();
|
.spriteBake(0, base, MutableQuadView.BAKE_LOCK_UV).emit();
|
||||||
|
|
||||||
if(fluid != Fluids.EMPTY){
|
if (fluid != Fluids.EMPTY) {
|
||||||
FluidRenderHandler fluidRenderHandler = FluidRenderHandlerRegistry.INSTANCE.get(fluid);
|
FluidRenderHandler fluidRenderHandler = FluidRenderHandlerRegistry.INSTANCE.get(fluid);
|
||||||
if(fluidRenderHandler != null){
|
if (fluidRenderHandler != null) {
|
||||||
int color = fluidRenderHandler.getFluidColor(MinecraftClient.getInstance().world, MinecraftClient.getInstance().player.getBlockPos(), fluid.getDefaultState());
|
int color = fluidRenderHandler.getFluidColor(MinecraftClient.getInstance().world, MinecraftClient.getInstance().player.getBlockPos(), fluid.getDefaultState());
|
||||||
//Does maths that works
|
//Does maths that works
|
||||||
color = new Color((float)(color >> 16 & 255) / 255.0F, (float)(color >> 8 & 255) / 255.0F,(float)(color & 255) / 255.0F).getRGB();
|
color = new Color((float) (color >> 16 & 255) / 255.0F, (float) (color >> 8 & 255) / 255.0F, (float) (color & 255) / 255.0F).getRGB();
|
||||||
|
|
||||||
Sprite fluidSprite = fluidRenderHandler.getFluidSprites(MinecraftClient.getInstance().world, BlockPos.ORIGIN, fluid.getDefaultState())[0];
|
Sprite fluidSprite = fluidRenderHandler.getFluidSprites(MinecraftClient.getInstance().world, BlockPos.ORIGIN, fluid.getDefaultState())[0];
|
||||||
emitter.square(Direction.SOUTH, 0.4F, 0.25F, 0.6F, 0.75F, -0.0001F)
|
emitter.square(Direction.SOUTH, 0.4F, 0.25F, 0.6F, 0.75F, -0.0001F)
|
||||||
.material(mat)
|
.material(mat)
|
||||||
.spriteColor(0, color, color, color, color)
|
.spriteColor(0, color, color, color, color)
|
||||||
.spriteBake(0, fluidSprite, MutableQuadView.BAKE_LOCK_UV).emit();
|
.spriteBake(0, fluidSprite, MutableQuadView.BAKE_LOCK_UV).emit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,7 +167,7 @@ public class DynamicCellBakedModel implements BakedModel, FabricBakedModel {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasDepthInGui() {
|
public boolean hasDepthInGui() {
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -149,7 +182,7 @@ public class DynamicCellBakedModel implements BakedModel, FabricBakedModel {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ModelTransformation getTransformation() {
|
public ModelTransformation getTransformation() {
|
||||||
return ModelHelper.HANDHELD_ITEM_TRANSFORMS;
|
return ModelHelper.DEFAULT_ITEM_TRANSFORMS;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected class ItemProxy extends ModelItemPropertyOverrideList {
|
protected class ItemProxy extends ModelItemPropertyOverrideList {
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"parent": "techreborn:item/cell_fluid_template",
|
||||||
|
"textures": {
|
||||||
|
"texture": "techreborn:item/cell_background"
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"parent": "minecraft:item/generated",
|
"parent": "minecraft:item/generated",
|
||||||
"textures": {
|
"textures": {
|
||||||
"layer0": "techreborn:item/cell_empty"
|
"layer0": "techreborn:item/cell_base"
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"parent": "techreborn:item/cell_fluid_template",
|
||||||
|
"textures": {
|
||||||
|
"texture": "techreborn:item/cell_background"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,38 @@
|
||||||
|
{
|
||||||
|
"elements": [
|
||||||
|
{
|
||||||
|
"from": [7, 4, 7.5],
|
||||||
|
"to": [10, 12, 8.5],
|
||||||
|
"faces": {
|
||||||
|
"north": {"uv": [7, 4, 10, 12], "texture": "#texture"},
|
||||||
|
"south": {"uv": [7, 4, 10, 12], "texture": "#texture"}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"display": {
|
||||||
|
"ground": {
|
||||||
|
"rotation": [ 0, 0, 0 ],
|
||||||
|
"translation": [ 0, 2, 0],
|
||||||
|
"scale":[ 0.5, 0.5, 0.5 ]
|
||||||
|
},
|
||||||
|
"head": {
|
||||||
|
"rotation": [ 0, 180, 0 ],
|
||||||
|
"translation": [ 0, 13, 7],
|
||||||
|
"scale":[ 1, 1, 1]
|
||||||
|
},
|
||||||
|
"thirdperson_righthand": {
|
||||||
|
"rotation": [ 0, 0, 0 ],
|
||||||
|
"translation": [ 0, 3, 1 ],
|
||||||
|
"scale": [ 0.55, 0.55, 0.55 ]
|
||||||
|
},
|
||||||
|
"firstperson_righthand": {
|
||||||
|
"rotation": [ 0, -90, 25 ],
|
||||||
|
"translation": [ 1.13, 3.2, 1.13],
|
||||||
|
"scale": [ 0.68, 0.68, 0.68 ]
|
||||||
|
},
|
||||||
|
"fixed": {
|
||||||
|
"rotation": [ 0, 180, 0 ],
|
||||||
|
"scale": [ 1, 1, 1 ]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"parent": "techreborn:item/cell_fluid_template",
|
||||||
|
"textures": {
|
||||||
|
"texture": "techreborn:item/cell_glass"
|
||||||
|
}
|
||||||
|
}
|
After Width: | Height: | Size: 1.6 KiB |
Before Width: | Height: | Size: 505 B After Width: | Height: | Size: 1.7 KiB |
Before Width: | Height: | Size: 446 B |
Before Width: | Height: | Size: 506 B |
Before Width: | Height: | Size: 321 B |
After Width: | Height: | Size: 1.8 KiB |
Before Width: | Height: | Size: 643 B After Width: | Height: | Size: 2 KiB |
Before Width: | Height: | Size: 832 B After Width: | Height: | Size: 2.1 KiB |
Before Width: | Height: | Size: 664 B After Width: | Height: | Size: 1.9 KiB |
Before Width: | Height: | Size: 634 B After Width: | Height: | Size: 2 KiB |
Before Width: | Height: | Size: 826 B After Width: | Height: | Size: 1.8 KiB |
Before Width: | Height: | Size: 664 B After Width: | Height: | Size: 1.9 KiB |
Before Width: | Height: | Size: 659 B After Width: | Height: | Size: 1.9 KiB |
Before Width: | Height: | Size: 627 B After Width: | Height: | Size: 2 KiB |
Before Width: | Height: | Size: 823 B After Width: | Height: | Size: 1.8 KiB |