-
-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#515] Implemented another rendering object, a circle
Implemented a system to register rendering object types for network sync and rendering on the client
- Loading branch information
Showing
15 changed files
with
369 additions
and
106 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
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
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
53 changes: 53 additions & 0 deletions
53
src/main/java/de/srendi/advancedperipherals/client/smartglasses/objects/CircleRenderer.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,53 @@ | ||
package de.srendi.advancedperipherals.client.smartglasses.objects; | ||
|
||
import com.mojang.blaze3d.systems.RenderSystem; | ||
import com.mojang.blaze3d.vertex.BufferBuilder; | ||
import com.mojang.blaze3d.vertex.BufferUploader; | ||
import com.mojang.blaze3d.vertex.DefaultVertexFormat; | ||
import com.mojang.blaze3d.vertex.PoseStack; | ||
import com.mojang.blaze3d.vertex.Tesselator; | ||
import com.mojang.blaze3d.vertex.VertexFormat; | ||
import com.mojang.math.Matrix4f; | ||
import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.objects.Circle; | ||
import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.objects.RenderableObject; | ||
import net.minecraft.client.renderer.GameRenderer; | ||
import net.minecraftforge.client.gui.overlay.ForgeGui; | ||
|
||
public class CircleRenderer implements IObjectRenderer { | ||
|
||
@Override | ||
public void render(RenderableObject object, ForgeGui gui, PoseStack poseStack, float partialTick, int screenWidth, int screenHeight) { | ||
Circle circle = (Circle) object; | ||
|
||
float alpha = object.opacity; | ||
float red = (float) (object.color >> 16 & 255) / 255.0F; | ||
float green = (float) (object.color >> 8 & 255) / 255.0F; | ||
float blue = (float) (object.color & 255) / 255.0F; | ||
|
||
drawCircle(poseStack, circle.x, circle.y, circle.radius, 120, red, green, blue, alpha); | ||
} | ||
|
||
public void drawCircle(PoseStack poseStack, float cx, float cy, float r, int numSegments, float red, float green, float blue, float alpha) { | ||
RenderSystem.setShader(GameRenderer::getPositionColorShader); | ||
BufferBuilder bufferbuilder = Tesselator.getInstance().getBuilder(); | ||
|
||
Matrix4f matrix = poseStack.last().pose(); | ||
bufferbuilder.begin(VertexFormat.Mode.TRIANGLE_FAN, DefaultVertexFormat.POSITION_COLOR); | ||
|
||
bufferbuilder.vertex(matrix, cx, cy, 1f).color(red, green, blue, alpha).endVertex(); | ||
|
||
double angle = Math.PI * 2 / numSegments; | ||
|
||
for (int i = 0; i <= numSegments; i++) { | ||
double x = cx + r * Math.cos(i * angle); | ||
double y = cy + r * Math.sin(i * angle); | ||
|
||
bufferbuilder.vertex(matrix, (float) y, (float) x, 0f).color(red, green, blue, alpha).endVertex(); | ||
} | ||
|
||
BufferUploader.drawWithShader(bufferbuilder.end()); | ||
} | ||
|
||
|
||
|
||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/de/srendi/advancedperipherals/client/smartglasses/objects/IObjectRenderer.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,11 @@ | ||
package de.srendi.advancedperipherals.client.smartglasses.objects; | ||
|
||
import com.mojang.blaze3d.vertex.PoseStack; | ||
import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.objects.RenderableObject; | ||
import net.minecraftforge.client.gui.overlay.ForgeGui; | ||
|
||
public interface IObjectRenderer { | ||
|
||
void render(RenderableObject object, ForgeGui gui, PoseStack poseStack, float partialTick, int screenWidth, int screenHeight); | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/de/srendi/advancedperipherals/client/smartglasses/objects/PanelRenderer.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,34 @@ | ||
package de.srendi.advancedperipherals.client.smartglasses.objects; | ||
|
||
import com.mojang.blaze3d.systems.RenderSystem; | ||
import com.mojang.blaze3d.vertex.BufferBuilder; | ||
import com.mojang.blaze3d.vertex.BufferUploader; | ||
import com.mojang.blaze3d.vertex.DefaultVertexFormat; | ||
import com.mojang.blaze3d.vertex.PoseStack; | ||
import com.mojang.blaze3d.vertex.Tesselator; | ||
import com.mojang.blaze3d.vertex.VertexFormat; | ||
import com.mojang.math.Matrix4f; | ||
import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.objects.RenderableObject; | ||
import net.minecraft.client.renderer.GameRenderer; | ||
import net.minecraftforge.client.gui.overlay.ForgeGui; | ||
|
||
public class PanelRenderer implements IObjectRenderer { | ||
|
||
@Override | ||
public void render(RenderableObject object, ForgeGui gui, PoseStack poseStack, float partialTick, int screenWidth, int screenHeight) { | ||
float alpha = object.opacity; | ||
float red = (float) (object.color >> 16 & 255) / 255.0F; | ||
float green = (float) (object.color >> 8 & 255) / 255.0F; | ||
float blue = (float) (object.color & 255) / 255.0F; | ||
|
||
RenderSystem.setShader(GameRenderer::getPositionColorShader); | ||
BufferBuilder bufferbuilder = Tesselator.getInstance().getBuilder(); | ||
Matrix4f matrix = poseStack.last().pose(); | ||
bufferbuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR); | ||
bufferbuilder.vertex(matrix, (float) object.x, (float) object.maxY, 0f).color(red, green, blue, alpha).endVertex(); | ||
bufferbuilder.vertex(matrix, (float) object.maxX, (float) object.maxY, 0f).color(red, green, blue, alpha).endVertex(); | ||
bufferbuilder.vertex(matrix, (float) object.maxX, (float) object.y, 0f).color(red, green, blue, alpha).endVertex(); | ||
bufferbuilder.vertex(matrix, (float) object.x, (float) object.y, 0f).color(red, green, blue, alpha).endVertex(); | ||
BufferUploader.drawWithShader(bufferbuilder.end()); | ||
} | ||
} |
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
25 changes: 25 additions & 0 deletions
25
.../srendi/advancedperipherals/common/smartglasses/modules/overlay/ObjectDecodeRegistry.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,25 @@ | ||
package de.srendi.advancedperipherals.common.smartglasses.modules.overlay; | ||
|
||
import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.objects.RenderableObject; | ||
import net.minecraft.network.FriendlyByteBuf; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.function.Function; | ||
|
||
public class ObjectDecodeRegistry { | ||
|
||
private static final Map<Integer, Function<FriendlyByteBuf, RenderableObject>> objectRegistry = new HashMap<>(); | ||
|
||
public static RenderableObject getObject(int id, FriendlyByteBuf buf) { | ||
if (objectRegistry.containsKey(id)) { | ||
return objectRegistry.get(id).apply(buf); | ||
} | ||
return null; | ||
} | ||
|
||
public static void register(int id, Function<FriendlyByteBuf, RenderableObject> function) { | ||
objectRegistry.put(id, function); | ||
} | ||
|
||
} |
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
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
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
38 changes: 0 additions & 38 deletions
38
src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/Panel.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.