Skip to content

Commit

Permalink
Added Roller Rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
Buuz135 committed Jan 14, 2024
1 parent 6f48951 commit eda11b1
Show file tree
Hide file tree
Showing 11 changed files with 321 additions and 20 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
org.gradle.jvmargs=-Xmx2G
modGroup=com.buuz135
modVersion=0.4.4
modVersion=0.5.0
modBaseName=sushigocrafting
minecraftVersion=1.20.1
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,7 @@ default boolean isEmpty() {
int getSaturationValue();

DietType getDietType();

IFoodIngredientRenderer getRenderer();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package com.buuz135.sushigocrafting.api;

import com.buuz135.sushigocrafting.SushiGoCrafting;
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import com.mojang.blaze3d.vertex.VertexFormat;
import com.mojang.datafixers.util.Pair;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.RenderStateShard;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.phys.AABB;
import org.joml.Matrix4f;

public interface IFoodIngredientRenderer {

static RenderType ROLLER_RENDERER = createRenderType();

public static RenderType createRenderType() {
RenderType.CompositeState state = RenderType.CompositeState.builder()
.setTextureState(new RenderStateShard.TextureStateShard(new ResourceLocation(SushiGoCrafting.MOD_ID, "textures/block/roller_texture.png"), false, false))
.setShaderState(new RenderStateShard.ShaderStateShard(GameRenderer::getPositionColorTexShader))
.createCompositeState(true);
return RenderType.create("roller_renderer", DefaultVertexFormat.POSITION_COLOR_TEX, VertexFormat.Mode.QUADS, 256, false, true, state);
}

public static void renderCube(PoseStack stack, MultiBufferSource renderTypeBuffer, AABB pos, double x, double y, double z, float red, float green, float blue, float alpha) {

float x1 = (float) (pos.minX + x);
float x2 = (float) (pos.maxX + x);
float y1 = (float) (pos.minY + y);
float y2 = (float) (pos.maxY + y);
float z1 = (float) (pos.minZ + z);
float z2 = (float) (pos.maxZ + z);

Matrix4f matrix = stack.last().pose();
VertexConsumer buffer;

buffer = renderTypeBuffer.getBuffer(ROLLER_RENDERER);

buffer.vertex(matrix, x1, y1, z1).color(red, green, blue, alpha).uv(0, (float) pos.maxY).endVertex();
buffer.vertex(matrix, x1, y2, z1).color(red, green, blue, alpha).uv(0, 0).endVertex();
buffer.vertex(matrix, x2, y2, z1).color(red, green, blue, alpha).uv(1, 0).endVertex();
buffer.vertex(matrix, x2, y1, z1).color(red, green, blue, alpha).uv(1, (float) pos.maxY).endVertex();

buffer.vertex(matrix, x1, y1, z2).color(red, green, blue, alpha).uv(0, 1).endVertex();
buffer.vertex(matrix, x2, y1, z2).color(red, green, blue, alpha).uv(0, 0).endVertex();
buffer.vertex(matrix, x2, y2, z2).color(red, green, blue, alpha).uv((float) pos.maxY, 0).endVertex();
buffer.vertex(matrix, x1, y2, z2).color(red, green, blue, alpha).uv((float) pos.maxY, 1).endVertex();


buffer.vertex(matrix, x1, y1, z1).color(red, green, blue, alpha).uv(0, 1).endVertex();
buffer.vertex(matrix, x2, y1, z1).color(red, green, blue, alpha).uv(0, 0).endVertex();
buffer.vertex(matrix, x2, y1, z2).color(red, green, blue, alpha).uv(1, 0).endVertex();
buffer.vertex(matrix, x1, y1, z2).color(red, green, blue, alpha).uv(0, 0).endVertex();

buffer.vertex(matrix, x1, y2, z1).color(red, green, blue, alpha).uv(0, (float) pos.maxZ).endVertex();
buffer.vertex(matrix, x1, y2, z2).color(red, green, blue, alpha).uv(0, (float) pos.minZ).endVertex();
buffer.vertex(matrix, x2, y2, z2).color(red, green, blue, alpha).uv(1, (float) pos.minZ).endVertex();
buffer.vertex(matrix, x2, y2, z1).color(red, green, blue, alpha).uv(1, (float) pos.maxZ).endVertex();


buffer.vertex(matrix, x1, y1, z1).color(red, green, blue, alpha).uv(0, (float) pos.maxZ).endVertex();
buffer.vertex(matrix, x1, y1, z2).color(red, green, blue, alpha).uv(0, (float) pos.minZ).endVertex();
buffer.vertex(matrix, x1, y2, z2).color(red, green, blue, alpha).uv((float) pos.maxY, (float) pos.minZ).endVertex();
buffer.vertex(matrix, x1, y2, z1).color(red, green, blue, alpha).uv((float) pos.maxY, (float) pos.maxZ).endVertex();

buffer.vertex(matrix, x2, y1, z1).color(red, green, blue, alpha).uv((float) pos.maxY, (float) pos.maxZ).endVertex();
buffer.vertex(matrix, x2, y2, z1).color(red, green, blue, alpha).uv(0, (float) pos.maxZ).endVertex();
buffer.vertex(matrix, x2, y2, z2).color(red, green, blue, alpha).uv(0, (float) pos.minZ).endVertex();
buffer.vertex(matrix, x2, y1, z2).color(red, green, blue, alpha).uv((float) pos.maxY, (float) pos.minZ).endVertex();

}

Pair<Float, Float> render(PoseStack stack, MultiBufferSource renderTypeBuffer, int weight, int combinedLightIn, int combinedOverlayIn);
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package com.buuz135.sushigocrafting.api.impl;

import com.buuz135.sushigocrafting.api.IFoodIngredient;
import com.buuz135.sushigocrafting.api.IFoodIngredientRenderer;
import com.buuz135.sushigocrafting.api.IIngredientConsumer;
import com.buuz135.sushigocrafting.api.IIngredientEffect;
import com.buuz135.sushigocrafting.api.impl.effect.AddIngredientEffect;
import com.buuz135.sushigocrafting.api.impl.effect.ModifyIngredientEffect;
import com.buuz135.sushigocrafting.api.impl.renderer.CubeFoodIngredientRenderer;
import com.buuz135.sushigocrafting.api.impl.renderer.FlatSheetFoodIngredientRenderer;
import com.buuz135.sushigocrafting.api.impl.renderer.StackFoodIngredientRenderer;
import com.buuz135.sushigocrafting.proxy.SushiContent;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.ItemTags;
Expand All @@ -13,26 +17,42 @@
import net.minecraft.world.item.Items;
import net.minecraft.world.item.crafting.Ingredient;

import java.awt.*;
import java.util.function.Supplier;

public class FoodIngredient implements IFoodIngredient {

public static FoodIngredient EMPTY = new FoodIngredient("empty", null, 0, IIngredientConsumer.WEIGHT, null, null, 0, 0, DietType.SUGARS);
public static FoodIngredient RICE = new FoodIngredient("rice", SushiContent.Items.COOKED_RICE, 30, IIngredientConsumer.WEIGHT, null, new ModifyIngredientEffect(1.75f, 0), 0, 2, DietType.GRAINS);
public static FoodIngredient NORI = new FoodIngredient("nori", SushiContent.Items.NORI_SHEET, 1, IIngredientConsumer.STACK, null, null, 1, 1, DietType.VEGETABLES);
public static FoodIngredient TUNA_FILLET = new FoodIngredient("tuna", SushiContent.Items.RAW_TUNA_FILLET, 30, IIngredientConsumer.WEIGHT, () -> Ingredient.of(ItemTags.create(new ResourceLocation("forge", "raw_fishes/tuna"))), new AddIngredientEffect(SushiContent.Effects.ACQUIRED_TASTE, 30, 0), 3, 1, DietType.PROTEINS);
public static FoodIngredient SALMON_FILLET = new FoodIngredient("salmon", SushiContent.Items.RAW_SALMON_FILLET, 30, IIngredientConsumer.WEIGHT, () -> Ingredient.of(ItemTags.create(new ResourceLocation("forge", "raw_fishes/salmon"))), new AddIngredientEffect(SushiContent.Effects.SMALL_BITES, 30, 0), 3, 1, DietType.PROTEINS);
public static FoodIngredient AVOCADO = new FoodIngredient("avocado", SushiContent.Items.AVOCADO_SLICES, 45, IIngredientConsumer.WEIGHT, () -> Ingredient.of(ItemTags.create(new ResourceLocation("forge", "fruits/avocado"))), new ModifyIngredientEffect(1.20f, 1), 2, 2, DietType.FRUITS);
public static FoodIngredient CUCUMBER = new FoodIngredient("cucumber", SushiContent.Items.CUCUMBER_SLICES, 15, IIngredientConsumer.WEIGHT, () -> Ingredient.of(ItemTags.create(new ResourceLocation("forge", "crops/cucumber"))), new ModifyIngredientEffect(1.25f, 0), 2, 2, DietType.VEGETABLES);
public static FoodIngredient SESAME = new FoodIngredient("sesame", SushiContent.Items.SESAME_SEED, 6, IIngredientConsumer.WEIGHT, null, new ModifyIngredientEffect(2, 0), 1, 1, DietType.GRAINS);
public static FoodIngredient CRAB = new FoodIngredient("crab", SushiContent.Items.IMITATION_CRAB, 30, IIngredientConsumer.WEIGHT, () -> Ingredient.of(Items.COD), new AddIngredientEffect(() -> MobEffects.MOVEMENT_SPEED, 3, 0), 2, 1, DietType.PROTEINS);
public static FoodIngredient WAKAME = new FoodIngredient("wakame", () -> Items.SEAGRASS, 1, IIngredientConsumer.STACK, null, null, 0, 1, DietType.VEGETABLES);
public static FoodIngredient TOBIKO = new FoodIngredient("tobiko", SushiContent.Items.TOBIKO, 12, IIngredientConsumer.WEIGHT, null, new ModifyIngredientEffect(1.50f, 0), 1, 2, DietType.PROTEINS);
public static FoodIngredient CHEESE = new FoodIngredient("cheese", SushiContent.Items.CHEESE, 12, IIngredientConsumer.WEIGHT, null, new AddIngredientEffect(() -> MobEffects.SATURATION, 15, 0), 1, 2, DietType.PROTEINS);
public static FoodIngredient SHRIMP = new FoodIngredient("shrimp", SushiContent.Items.SHRIMP, 30, IIngredientConsumer.WEIGHT, null, new AddIngredientEffect(SushiContent.Effects.STEADY_HANDS, 60, 0), 2, 1, DietType.PROTEINS);
public static FoodIngredient CHICKEN = new FoodIngredient("chicken", () -> Items.COOKED_CHICKEN, 30, IIngredientConsumer.WEIGHT, null, new AddIngredientEffect(() -> MobEffects.SLOW_FALLING, 10, 0), 2, 1, DietType.PROTEINS);
public static FoodIngredient SOY_SAUCE = new FoodIngredient("soy_sauce", SushiContent.Items.SOY_SAUCE, 4, IIngredientConsumer.WEIGHT, null, new ModifyIngredientEffect(1, 1), 0, 0, DietType.GRAINS);
public static FoodIngredient WASABI = new FoodIngredient("wasabi", SushiContent.Items.WASABI_PASTE, 4, IIngredientConsumer.WEIGHT, () -> Ingredient.of(ItemTags.create(new ResourceLocation("forge", "crops/wasabi_root"))), new AddIngredientEffect(() -> MobEffects.FIRE_RESISTANCE, 10, 0), 0, 0, DietType.VEGETABLES);
public static FoodIngredient EMPTY = new FoodIngredient("empty", null, 0, IIngredientConsumer.WEIGHT, null, null, 0, 0, DietType.SUGARS, null);
public static FoodIngredient RICE = new FoodIngredient("rice", SushiContent.Items.COOKED_RICE, 30, IIngredientConsumer.WEIGHT, null,
new ModifyIngredientEffect(1.75f, 0), 0, 2, DietType.GRAINS, new FlatSheetFoodIngredientRenderer(0.01f, new Color(230, 237, 232)));
public static FoodIngredient NORI = new FoodIngredient("nori", SushiContent.Items.NORI_SHEET, 1, IIngredientConsumer.STACK, null,
null, 1, 1, DietType.VEGETABLES, new FlatSheetFoodIngredientRenderer(0.005f, new Color(19, 28, 13)));
public static FoodIngredient TUNA_FILLET = new FoodIngredient("tuna", SushiContent.Items.RAW_TUNA_FILLET, 30, IIngredientConsumer.WEIGHT, () -> Ingredient.of(ItemTags.create(new ResourceLocation("forge", "raw_fishes/tuna"))),
new AddIngredientEffect(SushiContent.Effects.ACQUIRED_TASTE, 30, 0), 3, 1, DietType.PROTEINS, new CubeFoodIngredientRenderer(0.01f, new Color(168, 39, 47)));
public static FoodIngredient SALMON_FILLET = new FoodIngredient("salmon", SushiContent.Items.RAW_SALMON_FILLET, 30, IIngredientConsumer.WEIGHT, () -> Ingredient.of(ItemTags.create(new ResourceLocation("forge", "raw_fishes/salmon"))),
new AddIngredientEffect(SushiContent.Effects.SMALL_BITES, 30, 0), 3, 1, DietType.PROTEINS, new CubeFoodIngredientRenderer(0.01f, new Color(255, 117, 59)));
public static FoodIngredient AVOCADO = new FoodIngredient("avocado", SushiContent.Items.AVOCADO_SLICES, 45, IIngredientConsumer.WEIGHT, () -> Ingredient.of(ItemTags.create(new ResourceLocation("forge", "fruits/avocado"))),
new ModifyIngredientEffect(1.20f, 1), 2, 2, DietType.FRUITS, new CubeFoodIngredientRenderer(0.01f, new Color(160, 179, 79)));
public static FoodIngredient CUCUMBER = new FoodIngredient("cucumber", SushiContent.Items.CUCUMBER_SLICES, 15, IIngredientConsumer.WEIGHT, () -> Ingredient.of(ItemTags.create(new ResourceLocation("forge", "crops/cucumber"))),
new ModifyIngredientEffect(1.25f, 0), 2, 2, DietType.VEGETABLES, new CubeFoodIngredientRenderer(0.01f, new Color(227, 241, 199)));
public static FoodIngredient SESAME = new FoodIngredient("sesame", SushiContent.Items.SESAME_SEED, 6, IIngredientConsumer.WEIGHT, null,
new ModifyIngredientEffect(2, 0), 1, 1, DietType.GRAINS, null);
public static FoodIngredient CRAB = new FoodIngredient("crab", SushiContent.Items.IMITATION_CRAB, 30, IIngredientConsumer.WEIGHT, () -> Ingredient.of(Items.COD),
new AddIngredientEffect(() -> MobEffects.MOVEMENT_SPEED, 3, 0), 2, 1, DietType.PROTEINS, new CubeFoodIngredientRenderer(0.01f, new Color(214, 34, 43)));
public static FoodIngredient WAKAME = new FoodIngredient("wakame", () -> Items.SEAGRASS, 1, IIngredientConsumer.STACK, null,
null, 0, 1, DietType.VEGETABLES, new CubeFoodIngredientRenderer(0.01f, new Color(82, 127, 29)));
public static FoodIngredient TOBIKO = new FoodIngredient("tobiko", SushiContent.Items.TOBIKO, 12, IIngredientConsumer.WEIGHT, null,
new ModifyIngredientEffect(1.50f, 0), 1, 2, DietType.PROTEINS, new CubeFoodIngredientRenderer(0.01f, new Color(179, 18, 26)));
public static FoodIngredient CHEESE = new FoodIngredient("cheese", SushiContent.Items.CHEESE, 12, IIngredientConsumer.WEIGHT, null,
new AddIngredientEffect(() -> MobEffects.SATURATION, 15, 0), 1, 2, DietType.PROTEINS, new CubeFoodIngredientRenderer(0.01f, new Color(237, 208, 125)));
public static FoodIngredient SHRIMP = new FoodIngredient("shrimp", SushiContent.Items.SHRIMP, 30, IIngredientConsumer.WEIGHT, null,
new AddIngredientEffect(SushiContent.Effects.STEADY_HANDS, 60, 0), 2, 1, DietType.PROTEINS, new CubeFoodIngredientRenderer(0.01f, new Color(200, 91, 89)));
public static FoodIngredient CHICKEN = new FoodIngredient("chicken", () -> Items.COOKED_CHICKEN, 30, IIngredientConsumer.WEIGHT, null,
new AddIngredientEffect(() -> MobEffects.SLOW_FALLING, 10, 0), 2, 1, DietType.PROTEINS, new CubeFoodIngredientRenderer(0.01f, new Color(255, 149, 1)));
public static FoodIngredient SOY_SAUCE = new FoodIngredient("soy_sauce", SushiContent.Items.SOY_SAUCE, 4, IIngredientConsumer.WEIGHT, null,
new ModifyIngredientEffect(1, 1), 0, 0, DietType.GRAINS, new StackFoodIngredientRenderer(SushiContent.Items.SOY_SAUCE, 0.92f, 0f, 0.15f, -20f, 0f));
public static FoodIngredient WASABI = new FoodIngredient("wasabi", SushiContent.Items.WASABI_PASTE, 4, IIngredientConsumer.WEIGHT, () -> Ingredient.of(ItemTags.create(new ResourceLocation("forge", "crops/wasabi_root"))),
new AddIngredientEffect(() -> MobEffects.FIRE_RESISTANCE, 10, 0), 0, 0, DietType.VEGETABLES, new StackFoodIngredientRenderer(SushiContent.Items.WASABI_PASTE, 0.035f, -0.02f, 0.2f, 20, -90));

private final Supplier<? extends Item> item;
private final String name;
Expand All @@ -44,7 +64,9 @@ public class FoodIngredient implements IFoodIngredient {
private final int saturationValue;
private final DietType dietType;

public FoodIngredient(String name, Supplier<? extends Item> item, int defaultAmount, IIngredientConsumer ingredientConsumer, Supplier<Ingredient> ingredientSupplier, IIngredientEffect effect, int foodValue, int saturationValue, DietType dietType) {
private final IFoodIngredientRenderer renderer;

public FoodIngredient(String name, Supplier<? extends Item> item, int defaultAmount, IIngredientConsumer ingredientConsumer, Supplier<Ingredient> ingredientSupplier, IIngredientEffect effect, int foodValue, int saturationValue, DietType dietType, IFoodIngredientRenderer renderer) {
this.name = name;
this.item = item;
this.defaultAmount = defaultAmount;
Expand All @@ -54,6 +76,7 @@ public FoodIngredient(String name, Supplier<? extends Item> item, int defaultAmo
this.hungerValue = foodValue;
this.saturationValue = saturationValue;
this.dietType = dietType;
this.renderer = renderer;
FoodAPI.get().addFoodIngredient(this);
}

Expand Down Expand Up @@ -105,4 +128,9 @@ public DietType getDietType() {
public IIngredientConsumer getIngredientConsumer() {
return ingredientConsumer;
}

@Override
public IFoodIngredientRenderer getRenderer() {
return renderer;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.buuz135.sushigocrafting.api.impl.renderer;

import com.buuz135.sushigocrafting.api.IFoodIngredientRenderer;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.datafixers.util.Pair;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.world.phys.AABB;

import java.awt.*;

public class CubeFoodIngredientRenderer implements IFoodIngredientRenderer {

private final float thickness;
private final Color color;

public CubeFoodIngredientRenderer(float height, Color color) {
this.thickness = height;
this.color = color;
}

@Override
public Pair<Float, Float> render(PoseStack stack, MultiBufferSource renderTypeBuffer, int weight, int combinedLightIn, int combinedOverlayIn) {
var paddingX = 0.15f;
var paddingY = 0.08f;
var customHeight = thickness + (weight / 2f) * thickness;
var box = new AABB(paddingX, 0, 0.5, 1 - paddingX, customHeight, 0.5 + customHeight * 2);
IFoodIngredientRenderer.renderCube(stack, renderTypeBuffer, box, 0, 0, 0, color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f, color.getAlpha() / 255f);
return Pair.of(customHeight * 2, 0f);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.buuz135.sushigocrafting.api.impl.renderer;

import com.buuz135.sushigocrafting.api.IFoodIngredientRenderer;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.datafixers.util.Pair;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.world.phys.AABB;

import java.awt.*;

public class FlatSheetFoodIngredientRenderer implements IFoodIngredientRenderer {

private final float height;
private final Color color;

public FlatSheetFoodIngredientRenderer(float height, Color color) {
this.height = height;
this.color = color;
}

@Override
public Pair<Float, Float> render(PoseStack stack, MultiBufferSource renderTypeBuffer, int weight, int combinedLightIn, int combinedOverlayIn) {
var paddingX = 0.15f;
var paddingY = 0.08f;
var customHeight = height + (weight / 2f) * height;
var box = new AABB(paddingX, 0, paddingY, 1 - paddingX, customHeight, 1 - paddingY);
IFoodIngredientRenderer.renderCube(stack, renderTypeBuffer, box, 0, 0, 0, color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f, color.getAlpha() / 255f);
return Pair.of(0f, customHeight);
}
}
Loading

0 comments on commit eda11b1

Please sign in to comment.