-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
321 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
src/main/java/com/buuz135/sushigocrafting/api/IFoodIngredientRenderer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/main/java/com/buuz135/sushigocrafting/api/impl/renderer/CubeFoodIngredientRenderer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...n/java/com/buuz135/sushigocrafting/api/impl/renderer/FlatSheetFoodIngredientRenderer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
Oops, something went wrong.