aboutsummaryrefslogtreecommitdiff
path: root/api/src
diff options
context:
space:
mode:
Diffstat (limited to 'api/src')
-rw-r--r--api/src/main/java/me/shedaniel/rei/api/client/util/SpriteRenderer.java271
-rw-r--r--api/src/main/java/me/shedaniel/rei/api/client/view/ViewSearchBuilder.java2
-rw-r--r--api/src/main/java/me/shedaniel/rei/api/client/view/Views.java9
-rw-r--r--api/src/main/java/me/shedaniel/rei/api/common/entry/EntryStack.java6
4 files changed, 285 insertions, 3 deletions
diff --git a/api/src/main/java/me/shedaniel/rei/api/client/util/SpriteRenderer.java b/api/src/main/java/me/shedaniel/rei/api/client/util/SpriteRenderer.java
new file mode 100644
index 000000000..10de31d6d
--- /dev/null
+++ b/api/src/main/java/me/shedaniel/rei/api/client/util/SpriteRenderer.java
@@ -0,0 +1,271 @@
+/*
+ * This file is licensed under the MIT License, part of Roughly Enough Items.
+ * Copyright (c) 2018, 2019, 2020 shedaniel
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package me.shedaniel.rei.api.client.util;
+
+import com.mojang.blaze3d.vertex.PoseStack;
+import com.mojang.blaze3d.vertex.VertexConsumer;
+import com.mojang.math.Matrix3f;
+import com.mojang.math.Matrix4f;
+import net.minecraft.client.Minecraft;
+import net.minecraft.client.renderer.MultiBufferSource;
+import net.minecraft.client.renderer.RenderType;
+import net.minecraft.client.renderer.texture.TextureAtlasSprite;
+import net.minecraft.resources.ResourceLocation;
+
+public class SpriteRenderer {
+ public static RenderPass beginPass() {
+ return new RenderPass();
+ }
+
+ public static class RenderPass {
+ float x1 = 0;
+ float x2 = 1;
+ float y1 = 0;
+ float y2 = 0;
+ float z1 = 0;
+ float uStart = 0F;
+ float uEnd = 1F;
+ float vStart = 0F;
+ float vEnd = 1F;
+ int u = 0;
+ int v = 1;
+ int r = 0xff;
+ int g = 0xff;
+ int b = 0xff;
+ int a = 0xff;
+ int l = 0;
+ float nX = 0;
+ float nY = 0;
+ float nZ = 0;
+ TextureAtlasSprite sprite;
+ VertexConsumer consumer;
+ MultiBufferSource consumers;
+ PoseStack matrices;
+ Matrix4f model;
+ Matrix3f normal;
+ RenderType layer;
+
+ private RenderPass() {}
+
+ public RenderPass setup(MultiBufferSource consumers, RenderType type) {
+ this.consumers = consumers;
+ this.setup(consumers.getBuffer(type), type);
+
+ return this;
+ }
+
+ public RenderPass setup(VertexConsumer consumer, RenderType type) {
+ this.consumer = consumer;
+ this.matrices = new PoseStack();
+ this.layer = type;
+
+ return this;
+ }
+
+ public RenderPass setup(MultiBufferSource consumers, PoseStack matrices, RenderType type) {
+ this.consumers = consumers;
+ this.consumer = consumers.getBuffer(type);
+ this.matrices = matrices;
+ this.layer = type;
+
+ return this;
+ }
+
+ public RenderPass position(Matrix4f model, float x1, float y1, float x2, float y2, float z1) {
+ this.position(x1, y1, x2, y2, z1);
+ this.model = model;
+
+ return this;
+ }
+
+ public RenderPass position(float x1, float y1, float x2, float y2, float z1) {
+ this.x1 = x1;
+ this.y1 = y1;
+ this.x2 = x2;
+ this.y2 = y2;
+ this.z1 = z1;
+
+ return this;
+ }
+
+ public RenderPass sprite(TextureAtlasSprite sprite) {
+ this.uStart = sprite.getU0();
+ this.uEnd = sprite.getU1();
+ this.vStart = sprite.getV0();
+ this.vEnd = sprite.getV1();
+
+ this.sprite = sprite;
+
+ return this;
+ }
+
+ public RenderPass sprite(float uStart, float uEnd, float vStart, float vEnd) {
+ this.uStart = uStart;
+ this.uEnd = uEnd;
+ this.vStart = vStart;
+ this.vEnd = vEnd;
+
+ return this;
+ }
+
+ public RenderPass overlay(int uv) {
+ return this.overlay(uv & '\uffff', uv >> 16 & '\uffff');
+ }
+
+ public RenderPass overlay(int u, int v) {
+ this.u = u;
+ this.v = v;
+
+ return this;
+ }
+
+ public RenderPass color(int color) {
+ this.r = ((color >> 16) & 0xFF);
+ this.g = ((color >> 8) & 0xFF);
+ this.b = (color & 0xFF);
+
+ return this;
+ }
+
+ public RenderPass color(int r, int g, int b) {
+ this.r = r;
+ this.g = g;
+ this.b = b;
+
+ return this;
+ }
+
+ public RenderPass alpha(int a) {
+ this.a = a;
+
+ return this;
+ }
+
+ public RenderPass light(int l) {
+ this.l = l;
+
+ return this;
+ }
+
+ public RenderPass normal(Matrix3f normal, float nX, float nY, float nZ) {
+ this.normal(nX, nY, nZ);
+ this.normal = normal;
+
+ return this;
+ }
+
+ public RenderPass normal(float nX, float nY, float nZ) {
+ this.nX = nX;
+ this.nY = nY;
+ this.nZ = nZ;
+
+ return this;
+ }
+
+ public void next() {
+ if (this.sprite == null) {
+ throw new RuntimeException("Invalid Sprite!");
+ }
+
+ next(sprite.getName());
+ }
+
+ public void next(ResourceLocation texture) {
+ if (this.consumer == null) {
+ throw new RuntimeException("Invalid VertexConsumer!");
+ }
+ if (this.matrices == null) {
+ throw new RuntimeException("Invalid MatrixStack!");
+ }
+ if (this.sprite == null) {
+ throw new RuntimeException("Invalid Sprite!");
+ }
+
+ if (this.model == null) {
+ this.model = this.matrices.last().pose();
+ }
+ if (this.normal == null) {
+ this.normal = this.matrices.last().normal();
+ }
+
+ float sX = sprite.getWidth();
+ float sY = sprite.getHeight();
+
+ Minecraft.getInstance().getTextureManager().bind(texture);
+
+ for (float y = y1; y < y2; y += Math.min(y2 - y, sY)) {
+ for (float x = x1; x < x2; x += Math.min(x2 - x, sX)) {
+ float nSX = Math.min(x2 - x, sX);
+ float nSY = Math.min(y2 - y, sY);
+
+ boolean isOverX = nSX < sX;
+ boolean isOverY = nSY < sY;
+
+ float dX = 0;
+ float dY = 0;
+
+ if (isOverX) {
+ dX = (uEnd - uStart) * (1 - (nSX / sX));
+ }
+
+ if (isOverY) {
+ dY = (vEnd - vStart) * (1 - (nSY / sY));
+ }
+
+ this.consumer = consumers.getBuffer(layer);
+
+ this.consumer.vertex(this.model, x, y + nSY, z1)
+ .color(this.r, this.g, this.b, this.a)
+ .uv(this.uStart, this.vEnd - dY)
+ .overlayCoords(this.u, this.v)
+ .uv2(this.l)
+ .normal(this.normal, this.nX, this.nY, this.nZ)
+ .endVertex();
+ this.consumer.vertex(this.model, x + nSX, y + nSY, z1)
+ .color(this.r, this.g, this.b, this.a)
+ .uv(this.uEnd - dX, this.vEnd - dY)
+ .overlayCoords(this.u, this.v)
+ .uv2(this.l)
+ .normal(this.normal, this.nX, this.nY, this.nZ)
+ .endVertex();
+ this.consumer.vertex(this.model, x + nSX, y, z1)
+ .color(this.r, this.g, this.b, this.a)
+ .uv(this.uEnd - dX, this.vStart)
+ .overlayCoords(this.u, this.v)
+ .uv2(this.l)
+ .normal(this.normal, this.nX, this.nY, this.nZ)
+ .endVertex();
+ this.consumer.vertex(this.model, x, y, z1)
+ .color(this.r, this.g, this.b, this.a)
+ .uv(this.uStart, this.vStart)
+ .overlayCoords(this.u, this.v)
+ .uv2(this.l)
+ .normal(this.normal, this.nX, this.nY, this.nZ)
+ .endVertex();
+ }
+ }
+
+ }
+ }
+} \ No newline at end of file
diff --git a/api/src/main/java/me/shedaniel/rei/api/client/view/ViewSearchBuilder.java b/api/src/main/java/me/shedaniel/rei/api/client/view/ViewSearchBuilder.java
index 068057dca..c1cb657a8 100644
--- a/api/src/main/java/me/shedaniel/rei/api/client/view/ViewSearchBuilder.java
+++ b/api/src/main/java/me/shedaniel/rei/api/client/view/ViewSearchBuilder.java
@@ -78,4 +78,6 @@ public interface ViewSearchBuilder {
EntryStack<?> getOutputNotice();
Map<DisplayCategory<?>, List<Display>> buildMap();
+
+
} \ No newline at end of file
diff --git a/api/src/main/java/me/shedaniel/rei/api/client/view/Views.java b/api/src/main/java/me/shedaniel/rei/api/client/view/Views.java
index 86c47e3fc..4af657d01 100644
--- a/api/src/main/java/me/shedaniel/rei/api/client/view/Views.java
+++ b/api/src/main/java/me/shedaniel/rei/api/client/view/Views.java
@@ -29,16 +29,19 @@ import me.shedaniel.rei.api.common.display.Display;
import me.shedaniel.rei.api.common.entry.EntryStack;
import me.shedaniel.rei.api.common.plugins.PluginManager;
import me.shedaniel.rei.api.common.registry.Reloadable;
+import org.jetbrains.annotations.ApiStatus;
import java.util.Collection;
import java.util.List;
import java.util.Map;
+import java.util.Set;
public interface Views extends Reloadable<REIClientPlugin> {
static Views getInstance() {
return PluginManager.getClientInstance().get(Views.class);
}
+ @ApiStatus.Internal
Map<DisplayCategory<?>, List<Display>> buildMapFor(ViewSearchBuilder builder);
/**
@@ -56,7 +59,7 @@ public interface Views extends Reloadable<REIClientPlugin> {
* @return the map of recipes
*/
default <T> Map<DisplayCategory<?>, List<Display>> getRecipesFor(EntryStack<T> stack) {
- return buildMapFor(ViewSearchBuilder.builder().addRecipesFor(stack).setInputNotice(stack));
+ return ViewSearchBuilder.builder().addRecipesFor(stack).setInputNotice(stack).buildMap();
}
/**
@@ -66,10 +69,10 @@ public interface Views extends Reloadable<REIClientPlugin> {
* @return the map of recipes
*/
default <T> Map<DisplayCategory<?>, List<Display>> getUsagesFor(EntryStack<T> stack) {
- return buildMapFor(ViewSearchBuilder.builder().addUsagesFor(stack).setInputNotice(stack));
+ return ViewSearchBuilder.builder().addUsagesFor(stack).setInputNotice(stack).buildMap();
}
default Map<DisplayCategory<?>, List<Display>> getAllRecipes() {
- return buildMapFor(ViewSearchBuilder.builder().addAllCategories());
+ return ViewSearchBuilder.builder().addAllCategories().buildMap();
}
}
diff --git a/api/src/main/java/me/shedaniel/rei/api/common/entry/EntryStack.java b/api/src/main/java/me/shedaniel/rei/api/common/entry/EntryStack.java
index 0f3279f3b..660605f32 100644
--- a/api/src/main/java/me/shedaniel/rei/api/common/entry/EntryStack.java
+++ b/api/src/main/java/me/shedaniel/rei/api/common/entry/EntryStack.java
@@ -158,6 +158,8 @@ public interface EntryStack<T> extends TextRepresentable, Renderer {
public static final Supplier<Boolean> FALSE = () -> false;
@Environment(EnvType.CLIENT)
public static final Function<EntryStack<?>, EntryRenderer<?>> DEFAULT_RENDERER = stack -> stack.getDefinition().getRenderer();
+ @Environment(EnvType.CLIENT)
+ public static final Function<EntryStack<?>, EntryRenderer<?>> EMPTY_RENDERER = stack -> EntryRenderer.empty();
public static final BiFunction<EntryStack<?>, Tooltip, Tooltip> DEFAULT_TOOLTIP_PROCESSOR = (stack, tooltip) -> tooltip;
@Environment(EnvType.CLIENT)
public static final Settings<Function<EntryStack<?>, EntryRenderer<?>>> RENDER = new Settings<>(DEFAULT_RENDERER);
@@ -165,6 +167,10 @@ public interface EntryStack<T> extends TextRepresentable, Renderer {
public static final Settings<BiFunction<EntryStack<?>, Tooltip, Tooltip>> TOOLTIP_PROCESSOR = new Settings<>(DEFAULT_TOOLTIP_PROCESSOR);
@Deprecated
public static final Settings<Function<EntryStack<?>, List<Component>>> TOOLTIP_APPEND_EXTRA = new Settings<>(stack -> Collections.emptyList());
+ @Environment(EnvType.CLIENT)
+ public static final Float DEFAULT_RENDER_RATIO = 1.0F;
+ @Environment(EnvType.CLIENT)
+ public static final Settings<Float> FLUID_RENDER_RATIO = new Settings<>(DEFAULT_RENDER_RATIO);
private R defaultValue;
private short id;