-
-
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] Basic syncing and rendering of our Panel render object for the…
… smart glasses. This is still a prototype and would not support other types of objects (like texts, circles or whatever we plan for the future)
- Loading branch information
Showing
16 changed files
with
345 additions
and
42 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
44 changes: 44 additions & 0 deletions
44
src/main/java/de/srendi/advancedperipherals/client/smartglasses/OverlayModuleOverlay.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,44 @@ | ||
package de.srendi.advancedperipherals.client.smartglasses; | ||
|
||
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.RenderableObject; | ||
import net.minecraft.client.renderer.GameRenderer; | ||
import net.minecraftforge.client.gui.overlay.ForgeGui; | ||
import net.minecraftforge.client.gui.overlay.IGuiOverlay; | ||
|
||
public class OverlayModuleOverlay implements IGuiOverlay { | ||
public static final String ID = "overlay_module_overlay"; | ||
|
||
@Override | ||
public void render(ForgeGui gui, PoseStack poseStack, float partialTick, int screenWidth, int screenHeight) { | ||
poseStack.pushPose(); | ||
|
||
// Just a simple quads renderer to test the syncing to the client, will evolve while we implement more renderable objects | ||
for (RenderableObject object : OverlayObjectHolder.getObjects()) { | ||
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()); | ||
} | ||
poseStack.popPose(); | ||
|
||
} | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/de/srendi/advancedperipherals/client/smartglasses/OverlayObjectHolder.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; | ||
|
||
import de.srendi.advancedperipherals.AdvancedPeripherals; | ||
import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.RenderableObject; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* Static holder for client side renderable objects - will change | ||
*/ | ||
public class OverlayObjectHolder { | ||
|
||
public static List<RenderableObject> objects = new ArrayList<>(); | ||
|
||
public static void addOrUpdateObject(RenderableObject object) { | ||
removeObject(object.getId()); | ||
objects.add(object); | ||
AdvancedPeripherals.debug("Added object to client renderer " + object); | ||
AdvancedPeripherals.debug("Having objects " + objects); | ||
} | ||
|
||
public static List<RenderableObject> getObjects() { | ||
return objects; | ||
} | ||
|
||
public static void removeObject(String id) { | ||
objects.removeIf(object -> object.getId().equals(id)); | ||
} | ||
|
||
public static void clear() { | ||
objects.clear(); | ||
} | ||
} |
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
27 changes: 27 additions & 0 deletions
27
...va/de/srendi/advancedperipherals/common/network/toclient/RenderableObjectClearPacket.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,27 @@ | ||
package de.srendi.advancedperipherals.common.network.toclient; | ||
|
||
import de.srendi.advancedperipherals.client.smartglasses.OverlayObjectHolder; | ||
import de.srendi.advancedperipherals.common.network.base.IPacket; | ||
import net.minecraft.network.FriendlyByteBuf; | ||
import net.minecraftforge.network.NetworkEvent; | ||
|
||
public class RenderableObjectClearPacket implements IPacket { | ||
|
||
public RenderableObjectClearPacket() { | ||
|
||
} | ||
|
||
@Override | ||
public void handle(NetworkEvent.Context context) { | ||
OverlayObjectHolder.clear(); | ||
} | ||
|
||
@Override | ||
public void encode(FriendlyByteBuf buffer) { | ||
|
||
} | ||
|
||
public static RenderableObjectClearPacket decode(FriendlyByteBuf buffer) { | ||
return new RenderableObjectClearPacket(); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...a/de/srendi/advancedperipherals/common/network/toclient/RenderableObjectDeletePacket.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,29 @@ | ||
package de.srendi.advancedperipherals.common.network.toclient; | ||
|
||
import de.srendi.advancedperipherals.client.smartglasses.OverlayObjectHolder; | ||
import de.srendi.advancedperipherals.common.network.base.IPacket; | ||
import net.minecraft.network.FriendlyByteBuf; | ||
import net.minecraftforge.network.NetworkEvent; | ||
|
||
public class RenderableObjectDeletePacket implements IPacket { | ||
|
||
private final String object; | ||
|
||
public RenderableObjectDeletePacket(String object) { | ||
this.object = object; | ||
} | ||
|
||
@Override | ||
public void handle(NetworkEvent.Context context) { | ||
OverlayObjectHolder.removeObject(object); | ||
} | ||
|
||
@Override | ||
public void encode(FriendlyByteBuf buffer) { | ||
buffer.writeUtf(object); | ||
} | ||
|
||
public static RenderableObjectDeletePacket decode(FriendlyByteBuf buffer) { | ||
return new RenderableObjectDeletePacket(buffer.readUtf()); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...ava/de/srendi/advancedperipherals/common/network/toclient/RenderableObjectSyncPacket.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 de.srendi.advancedperipherals.common.network.toclient; | ||
|
||
import de.srendi.advancedperipherals.client.smartglasses.OverlayObjectHolder; | ||
import de.srendi.advancedperipherals.common.network.base.IPacket; | ||
import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.RenderableObject; | ||
import net.minecraft.network.FriendlyByteBuf; | ||
import net.minecraftforge.network.NetworkEvent; | ||
|
||
public class RenderableObjectSyncPacket implements IPacket { | ||
|
||
private final RenderableObject object; | ||
|
||
public RenderableObjectSyncPacket(RenderableObject object) { | ||
this.object = object; | ||
} | ||
|
||
@Override | ||
public void handle(NetworkEvent.Context context) { | ||
OverlayObjectHolder.addOrUpdateObject(object); | ||
} | ||
|
||
@Override | ||
public void encode(FriendlyByteBuf buffer) { | ||
object.encode(buffer); | ||
} | ||
|
||
public static RenderableObjectSyncPacket decode(FriendlyByteBuf buffer) { | ||
return new RenderableObjectSyncPacket(RenderableObject.decode(buffer)); | ||
} | ||
} |
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
Oops, something went wrong.