Remove some duplicate code
This commit is contained in:
parent
2f9b154e22
commit
7873670a4f
4 changed files with 135 additions and 186 deletions
|
@ -102,7 +102,7 @@ public class TechRebornClient implements ClientModInitializer {
|
|||
|
||||
@Override
|
||||
public BakedModel bake(ModelLoader modelLoader, Function<Identifier, Sprite> function, ModelBakeSettings modelBakeSettings) {
|
||||
return new DynamicBucketBakedModel(fluid);
|
||||
return new DynamicBucketBakedModel();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -0,0 +1,113 @@
|
|||
package techreborn.client.render;
|
||||
|
||||
import net.fabricmc.fabric.api.client.render.fluid.v1.FluidRenderHandler;
|
||||
import net.fabricmc.fabric.api.client.render.fluid.v1.FluidRenderHandlerRegistry;
|
||||
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.model.FabricBakedModel;
|
||||
import net.fabricmc.fabric.api.renderer.v1.render.RenderContext;
|
||||
import net.fabricmc.indigo.renderer.helper.GeometryHelper;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
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.json.ModelItemPropertyOverrideList;
|
||||
import net.minecraft.client.render.model.json.ModelTransformation;
|
||||
import net.minecraft.client.texture.Sprite;
|
||||
import net.minecraft.client.util.ModelIdentifier;
|
||||
import net.minecraft.fluid.Fluid;
|
||||
import net.minecraft.fluid.Fluids;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.world.ExtendedBlockView;
|
||||
import reborncore.common.fluid.container.ItemFluidInfo;
|
||||
import reborncore.common.util.Color;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public abstract class BaseDynamicFluidBakedModel implements BakedModel, FabricBakedModel {
|
||||
|
||||
public abstract ModelIdentifier getBaseModel();
|
||||
public abstract ModelIdentifier getBackgroundModel();
|
||||
public abstract ModelIdentifier getFluidModel();
|
||||
|
||||
@Override
|
||||
public void emitItemQuads(ItemStack stack, Supplier<Random> randomSupplier, RenderContext context) {
|
||||
Fluid fluid = Fluids.EMPTY;
|
||||
if (stack.getItem() instanceof ItemFluidInfo) {
|
||||
ItemFluidInfo fluidInfo = (ItemFluidInfo) stack.getItem();
|
||||
fluid = fluidInfo.getFluid(stack);
|
||||
|
||||
}
|
||||
BakedModelManager bakedModelManager = MinecraftClient.getInstance().getBakedModelManager();
|
||||
context.fallbackConsumer().accept(bakedModelManager.getModel(getBaseModel()));
|
||||
context.fallbackConsumer().accept(bakedModelManager.getModel(getBackgroundModel()));
|
||||
|
||||
if (fluid != Fluids.EMPTY) {
|
||||
FluidRenderHandler fluidRenderHandler = FluidRenderHandlerRegistry.INSTANCE.get(fluid);
|
||||
BakedModel fluidModel = bakedModelManager.getModel(getFluidModel());
|
||||
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).getColor();
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void emitBlockQuads(ExtendedBlockView blockView, BlockState state, BlockPos pos, Supplier<Random> randomSupplier, RenderContext context) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BakedQuad> getQuads(@Nullable BlockState blockState, @Nullable Direction direction, Random random) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVanillaAdapter() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean useAmbientOcclusion() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasDepthInGui() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBuiltin() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModelTransformation getTransformation() {
|
||||
return ModelHelper.DEFAULT_ITEM_TRANSFORMS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModelItemPropertyOverrideList getItemPropertyOverrides() {
|
||||
return ModelItemPropertyOverrideList.EMPTY;
|
||||
}
|
||||
|
||||
}
|
|
@ -24,126 +24,35 @@
|
|||
|
||||
package techreborn.client.render;
|
||||
|
||||
import net.fabricmc.fabric.api.client.render.fluid.v1.FluidRenderHandler;
|
||||
import net.fabricmc.fabric.api.client.render.fluid.v1.FluidRenderHandlerRegistry;
|
||||
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.model.FabricBakedModel;
|
||||
import net.fabricmc.fabric.api.renderer.v1.render.RenderContext;
|
||||
import net.fabricmc.indigo.renderer.helper.GeometryHelper;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
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.json.ModelItemPropertyOverrideList;
|
||||
import net.minecraft.client.render.model.json.ModelTransformation;
|
||||
import net.minecraft.client.texture.Sprite;
|
||||
import net.minecraft.client.util.ModelIdentifier;
|
||||
import net.minecraft.fluid.Fluid;
|
||||
import net.minecraft.fluid.Fluids;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.world.ExtendedBlockView;
|
||||
import reborncore.common.fluid.container.ItemFluidInfo;
|
||||
import reborncore.common.util.Color;
|
||||
import techreborn.TechReborn;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class DynamicBucketBakedModel implements BakedModel, FabricBakedModel {
|
||||
|
||||
private final Fluid fluid;
|
||||
public class DynamicBucketBakedModel extends BaseDynamicFluidBakedModel {
|
||||
|
||||
private static final ModelIdentifier BUCKET_BASE = new ModelIdentifier(new Identifier(TechReborn.MOD_ID, "bucket_base"), "inventory");
|
||||
private static final ModelIdentifier BUCKET_BACKGROUND = new ModelIdentifier(new Identifier(TechReborn.MOD_ID, "bucket_background"), "inventory");
|
||||
private static final ModelIdentifier BUCKET_FLUID = new ModelIdentifier(new Identifier(TechReborn.MOD_ID, "bucket_fluid"), "inventory");
|
||||
|
||||
public DynamicBucketBakedModel(Fluid fluid) {
|
||||
this.fluid = fluid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void emitBlockQuads(ExtendedBlockView blockView, BlockState state, BlockPos pos, Supplier<Random> randomSupplier, RenderContext context) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void emitItemQuads(ItemStack stack, Supplier<Random> randomSupplier, RenderContext context) {
|
||||
Fluid fluid = Fluids.EMPTY;
|
||||
if (stack.getItem() instanceof ItemFluidInfo) {
|
||||
ItemFluidInfo fluidInfo = (ItemFluidInfo) stack.getItem();
|
||||
fluid = fluidInfo.getFluid(stack);
|
||||
|
||||
}
|
||||
BakedModelManager bakedModelManager = MinecraftClient.getInstance().getBakedModelManager();
|
||||
context.fallbackConsumer().accept(bakedModelManager.getModel(BUCKET_BASE));
|
||||
context.fallbackConsumer().accept(bakedModelManager.getModel(BUCKET_BACKGROUND));
|
||||
|
||||
if (fluid != Fluids.EMPTY) {
|
||||
FluidRenderHandler fluidRenderHandler = FluidRenderHandlerRegistry.INSTANCE.get(fluid);
|
||||
BakedModel fluidModel = bakedModelManager.getModel(BUCKET_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).getColor();
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BakedQuad> getQuads(@Nullable BlockState blockState, @Nullable Direction direction, Random random) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVanillaAdapter() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean useAmbientOcclusion() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasDepthInGui() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBuiltin() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Sprite getSprite() {
|
||||
return MinecraftClient.getInstance().getSpriteAtlas().getSprite(new Identifier("minecraft:item/bucket"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModelTransformation getTransformation() {
|
||||
return ModelHelper.DEFAULT_ITEM_TRANSFORMS;
|
||||
public ModelIdentifier getBaseModel() {
|
||||
return BUCKET_BASE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModelItemPropertyOverrideList getItemPropertyOverrides() {
|
||||
return ModelItemPropertyOverrideList.EMPTY;
|
||||
public ModelIdentifier getBackgroundModel() {
|
||||
return BUCKET_BACKGROUND;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModelIdentifier getFluidModel() {
|
||||
return BUCKET_FLUID;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,123 +24,50 @@
|
|||
|
||||
package techreborn.client.render;
|
||||
|
||||
import net.fabricmc.fabric.api.client.render.fluid.v1.FluidRenderHandler;
|
||||
import net.fabricmc.fabric.api.client.render.fluid.v1.FluidRenderHandlerRegistry;
|
||||
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.model.FabricBakedModel;
|
||||
import net.fabricmc.fabric.api.renderer.v1.render.RenderContext;
|
||||
import net.fabricmc.indigo.renderer.helper.GeometryHelper;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
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.json.ModelItemPropertyOverrideList;
|
||||
import net.minecraft.client.render.model.json.ModelTransformation;
|
||||
import net.minecraft.client.texture.Sprite;
|
||||
import net.minecraft.client.util.ModelIdentifier;
|
||||
import net.minecraft.fluid.Fluid;
|
||||
import net.minecraft.fluid.Fluids;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.world.ExtendedBlockView;
|
||||
import reborncore.common.fluid.container.ItemFluidInfo;
|
||||
import reborncore.common.util.Color;
|
||||
import techreborn.TechReborn;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class DynamicCellBakedModel implements BakedModel, FabricBakedModel {
|
||||
public class DynamicCellBakedModel extends BaseDynamicFluidBakedModel {
|
||||
|
||||
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");
|
||||
|
||||
@Override
|
||||
public void emitBlockQuads(ExtendedBlockView blockView, BlockState state, BlockPos pos, Supplier<Random> randomSupplier, RenderContext context) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void emitItemQuads(ItemStack stack, Supplier<Random> randomSupplier, RenderContext context) {
|
||||
Fluid fluid = Fluids.EMPTY;
|
||||
if (stack.getItem() instanceof ItemFluidInfo) {
|
||||
ItemFluidInfo fluidInfo = (ItemFluidInfo) stack.getItem();
|
||||
fluid = fluidInfo.getFluid(stack);
|
||||
super.emitItemQuads(stack, randomSupplier, context);
|
||||
|
||||
}
|
||||
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).getColor();
|
||||
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
|
||||
public List<BakedQuad> getQuads(@Nullable BlockState blockState, @Nullable Direction direction, Random random) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVanillaAdapter() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean useAmbientOcclusion() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasDepthInGui() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBuiltin() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Sprite getSprite() {
|
||||
return MinecraftClient.getInstance().getSpriteAtlas().getSprite(new Identifier("techreborn:item/cell_base"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModelTransformation getTransformation() {
|
||||
return ModelHelper.DEFAULT_ITEM_TRANSFORMS;
|
||||
public ModelIdentifier getBaseModel() {
|
||||
return CELL_BASE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModelItemPropertyOverrideList getItemPropertyOverrides() {
|
||||
return ModelItemPropertyOverrideList.EMPTY;
|
||||
public ModelIdentifier getBackgroundModel() {
|
||||
return CELL_BACKGROUND;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModelIdentifier getFluidModel() {
|
||||
return CELL_FLUID;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue