Skip to content

Commit

Permalink
Some 3D Rendering attempts. Currently, no really implemented api for …
Browse files Browse the repository at this point in the history
…3d objects, just playing around with the renderer to get a feeling how I want to design the functions for the 3d objects
  • Loading branch information
SirEndii committed Oct 5, 2024
1 parent 8b95891 commit 7021fe0
Show file tree
Hide file tree
Showing 23 changed files with 514 additions and 40 deletions.
255 changes: 255 additions & 0 deletions src/main/java/de/srendi/advancedperipherals/client/RenderUtil.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
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 de.srendi.advancedperipherals.AdvancedPeripherals;
import de.srendi.advancedperipherals.client.RenderUtil;
import de.srendi.advancedperipherals.common.util.EnumColor;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.event.RenderLevelStageEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;

@Mod.EventBusSubscriber(value = Dist.CLIENT, bus = Mod.EventBusSubscriber.Bus.FORGE, modid = AdvancedPeripherals.MOD_ID)
public class OverlayModuleLevelRenderer {

@SubscribeEvent
public static void renderLevelState(RenderLevelStageEvent event) {
PoseStack posestack = event.getPoseStack();
Vec3 view = Minecraft.getInstance().getEntityRenderDispatcher().camera.getPosition();

BufferBuilder bufferbuilder = Tesselator.getInstance().getBuilder();
if (event.getStage() == RenderLevelStageEvent.Stage.AFTER_TRANSLUCENT_BLOCKS) {
bufferbuilder.begin(RenderType.solid().mode(), DefaultVertexFormat.BLOCK);
BlockPos blockPos = new BlockPos(0, 190, 0);

posestack.pushPose();
posestack.translate(-view.x + blockPos.getX(), -view.y + blockPos.getY(), -view.z + blockPos.getZ());
float[] colors = EnumColor.GREEN.getRgb();
RenderSystem.setShaderColor(colors[0], colors[1], colors[2], 0.8f);

Minecraft.getInstance().getBlockRenderer().renderBatched(Blocks.STONE.defaultBlockState(), blockPos, event.getCamera().getEntity().level, posestack, bufferbuilder, false, event.getCamera().getEntity().level.random);
BufferUploader.drawWithShader(bufferbuilder.end());
RenderSystem.setShaderColor(1f, 1f, 1f, 1f);

posestack.popPose();

blockPos = new BlockPos(2, 190, 0);

colors = EnumColor.DARK_PURPLE.getRgb();

RenderSystem.setShader(GameRenderer::getPositionColorShader);
bufferbuilder.begin(RenderType.translucent().mode(), DefaultVertexFormat.POSITION_COLOR_NORMAL);
posestack.pushPose();

posestack.translate(-view.x + blockPos.getX(), -view.y + blockPos.getY(), -view.z + blockPos.getZ());

RenderUtil.drawPlane(posestack, bufferbuilder, colors[0], colors[1], colors[2], 0.8f, RenderUtil.Perspective.UP, 0f, 0.5f, 0f, 0.5f, 0f, 1f);

BufferUploader.drawWithShader(bufferbuilder.end());
posestack.popPose();
posestack.pushPose();
RenderSystem.setShader(GameRenderer::getPositionColorShader);
bufferbuilder.begin(RenderType.translucent().mode(), DefaultVertexFormat.POSITION_COLOR_NORMAL);

blockPos = new BlockPos(5, 190, 0);
posestack.translate(-view.x + blockPos.getX(), -view.y + blockPos.getY(), -view.z + blockPos.getZ());

RenderUtil.drawBox(posestack, bufferbuilder, colors[0], colors[1], colors[2], 0.8f, 16f, 16f, 12f);
BufferUploader.drawWithShader(bufferbuilder.end());
posestack.popPose();

}
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package de.srendi.advancedperipherals.client.smartglasses;

import com.mojang.blaze3d.vertex.PoseStack;
import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.objects.RenderableObject;
import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.objects.two_dim.RenderableObject;
import net.minecraftforge.client.gui.overlay.ForgeGui;
import net.minecraftforge.client.gui.overlay.IGuiOverlay;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package de.srendi.advancedperipherals.client.smartglasses;

import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.ObjectDecodeRegistry;
import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.objects.CircleObject;
import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.objects.ItemObject;
import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.objects.RectangleObject;
import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.objects.RenderableObject;
import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.objects.TextObject;
import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.objects.three_dim.BlockObject;
import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.objects.two_dim.CircleObject;
import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.objects.two_dim.ItemObject;
import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.objects.two_dim.RectangleObject;
import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.objects.two_dim.RenderableObject;
import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.objects.two_dim.TextObject;

import java.util.Collection;
import java.util.HashMap;
Expand Down Expand Up @@ -45,5 +46,7 @@ public static void registerDecodeObjects() {
ObjectDecodeRegistry.register(CircleObject.TYPE_ID, CircleObject::decode);
ObjectDecodeRegistry.register(TextObject.TYPE_ID, TextObject::decode);
ObjectDecodeRegistry.register(ItemObject.TYPE_ID, ItemObject::decode);

ObjectDecodeRegistry.register(BlockObject.TYPE_ID, BlockObject::decode);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package de.srendi.advancedperipherals.client.smartglasses.objects;

import com.mojang.blaze3d.vertex.PoseStack;
import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.objects.two_dim.RenderableObject;
import net.minecraftforge.client.gui.overlay.ForgeGui;

import java.util.List;

public class BlockRenderer implements IObjectRenderer {

@Override
public void renderBatch(List<RenderableObject> objects, ForgeGui gui, PoseStack poseStack, float partialTick, int screenWidth, int screenHeight) {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
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.CircleObject;
import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.objects.RenderableObject;
import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.objects.two_dim.CircleObject;
import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.objects.two_dim.RenderableObject;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraftforge.client.gui.overlay.ForgeGui;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package de.srendi.advancedperipherals.client.smartglasses.objects;

import com.mojang.blaze3d.vertex.PoseStack;
import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.objects.RenderableObject;
import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.objects.two_dim.RenderableObject;
import net.minecraftforge.client.gui.overlay.ForgeGui;

import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package de.srendi.advancedperipherals.client.smartglasses.objects;

import com.mojang.blaze3d.vertex.PoseStack;
import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.objects.ItemObject;
import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.objects.RenderableObject;
import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.objects.two_dim.ItemObject;
import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.objects.two_dim.RenderableObject;
import de.srendi.advancedperipherals.common.util.inventory.ItemUtil;
import net.minecraft.client.Minecraft;
import net.minecraft.world.item.Item;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
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 de.srendi.advancedperipherals.common.smartglasses.modules.overlay.objects.two_dim.RenderableObject;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraftforge.client.gui.overlay.ForgeGui;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package de.srendi.advancedperipherals.client.smartglasses.objects;

import com.mojang.blaze3d.vertex.PoseStack;
import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.objects.RenderableObject;
import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.objects.TextObject;
import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.objects.two_dim.RenderableObject;
import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.objects.two_dim.TextObject;
import net.minecraft.client.Minecraft;
import net.minecraftforge.client.gui.overlay.ForgeGui;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import de.srendi.advancedperipherals.client.smartglasses.OverlayObjectHolder;
import de.srendi.advancedperipherals.common.network.base.IPacket;
import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.ObjectDecodeRegistry;
import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.objects.RenderableObject;
import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.objects.two_dim.RenderableObject;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraftforge.network.NetworkEvent;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import de.srendi.advancedperipherals.client.smartglasses.OverlayObjectHolder;
import de.srendi.advancedperipherals.common.network.base.IPacket;
import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.ObjectDecodeRegistry;
import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.objects.RenderableObject;
import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.objects.two_dim.RenderableObject;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraftforge.network.NetworkEvent;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,6 @@ public void setItemHandler(@Nullable SmartGlassesItemHandler itemHandler) {
this.itemHandler = itemHandler;
}

public SmartGlassesItemHandler getItemHandler() {
return this.itemHandler;
}

public void markDirty() {
isDirty = true;
}
Expand Down Expand Up @@ -217,14 +213,6 @@ public Map<Integer, IModule> getModules() {
return modules;
}

@Override
protected void onTerminalChanged() {
super.onTerminalChanged();

/*if (entity instanceof ServerPlayer player && entity.isAlive()) {
// Broadcast the terminal to the current player.
}*/
}

@Override
protected void onRemoved() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package de.srendi.advancedperipherals.common.smartglasses.modules.overlay;

import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.objects.RenderableObject;
import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.objects.two_dim.RenderableObject;
import net.minecraft.network.FriendlyByteBuf;

import java.util.HashMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
import dan200.computercraft.api.lua.MethodResult;
import de.srendi.advancedperipherals.common.smartglasses.SmartGlassesAccess;
import de.srendi.advancedperipherals.common.smartglasses.modules.IModuleFunctions;
import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.objects.CircleObject;
import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.objects.ItemObject;
import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.objects.RectangleObject;
import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.objects.RenderableObject;
import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.objects.TextObject;
import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.objects.three_dim.BlockObject;
import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.objects.two_dim.CircleObject;
import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.objects.two_dim.ItemObject;
import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.objects.two_dim.RectangleObject;
import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.objects.two_dim.RenderableObject;
import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.objects.two_dim.TextObject;
import net.minecraft.client.Minecraft;

public class OverlayGlassesFunctions implements IModuleFunctions {
Expand Down Expand Up @@ -55,6 +56,14 @@ public final MethodResult createItem(IArguments arguments) throws LuaException {
return MethodResult.of(object, "SUCCESS");
}

@LuaFunction
public final MethodResult createBlock(IArguments arguments) throws LuaException {
BlockObject block = new BlockObject(overlayModule, arguments);
RenderableObject object = overlayModule.addObject(block);

return MethodResult.of(object, "SUCCESS");
}

@LuaFunction
public final MethodResult getObject(IArguments arguments) throws LuaException {
int id = arguments.getInt(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import de.srendi.advancedperipherals.common.smartglasses.SmartGlassesAccess;
import de.srendi.advancedperipherals.common.smartglasses.modules.IModule;
import de.srendi.advancedperipherals.common.smartglasses.modules.IModuleFunctions;
import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.objects.RenderableObject;
import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.objects.two_dim.RenderableObject;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerPlayer;
import org.jetbrains.annotations.NotNull;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package de.srendi.advancedperipherals.common.smartglasses.modules.overlay.objects.three_dim;

import dan200.computercraft.api.lua.IArguments;
import dan200.computercraft.api.lua.LuaException;
import dan200.computercraft.api.lua.LuaFunction;
import de.srendi.advancedperipherals.AdvancedPeripherals;
import de.srendi.advancedperipherals.client.smartglasses.objects.BlockRenderer;
import de.srendi.advancedperipherals.client.smartglasses.objects.IObjectRenderer;
import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.OverlayModule;
import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.propertytypes.StringProperty;
import net.minecraft.network.FriendlyByteBuf;

import java.util.UUID;

public class BlockObject extends ThreeDimensionalObject {
public static final int TYPE_ID = 4;

private final IObjectRenderer renderer = new BlockRenderer();

@StringProperty
public String block = "minecraft:air";

public BlockObject(OverlayModule module, IArguments arguments) throws LuaException {
super(module, arguments);
reflectivelyMapProperties(arguments);
}

public BlockObject(UUID player) {
super(player);
}

@LuaFunction
public void setBlock(String block) {
this.block = block;
getModule().update(this);
}

@LuaFunction
public final String getBlock() {
return block;
}

@Override
public void encode(FriendlyByteBuf buffer) {
buffer.writeInt(TYPE_ID);
super.encode(buffer);
buffer.writeUtf(block);
}

public static BlockObject decode(FriendlyByteBuf buffer) {
int objectId = buffer.readInt();
boolean hasValidUUID = buffer.readBoolean();
if (!hasValidUUID) {
AdvancedPeripherals.exception("Tried to decode a buffer for an OverlayObject but without a valid player as target.", new IllegalArgumentException());
return null;
}
UUID player = buffer.readUUID();
int color = buffer.readInt();
float opacity = buffer.readFloat();

int x = buffer.readInt();
int y = buffer.readInt();
int z = buffer.readInt();
int maxX = buffer.readInt();
int maxY = buffer.readInt();
String block = buffer.readUtf();

BlockObject clientObject = new BlockObject(player);
clientObject.setId(objectId);
clientObject.color = color;
clientObject.opacity = opacity;
clientObject.x = x;
clientObject.y = y;
clientObject.z = z;
clientObject.maxX = maxX;
clientObject.maxY = maxY;
clientObject.block = block;

return clientObject;
}

@Override
public IObjectRenderer getRenderObject() {
return renderer;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package de.srendi.advancedperipherals.common.smartglasses.modules.overlay.objects.three_dim;

import dan200.computercraft.api.lua.IArguments;
import dan200.computercraft.api.lua.LuaException;
import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.OverlayModule;
import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.objects.two_dim.RenderableObject;

import java.util.UUID;

public abstract class ThreeDimensionalObject extends RenderableObject {

public ThreeDimensionalObject(OverlayModule module, IArguments arguments) throws LuaException {
super(module, arguments);
}

public ThreeDimensionalObject(UUID player) {
super(player);
}
}
Loading

0 comments on commit 7021fe0

Please sign in to comment.