-
-
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.
Some 3D Rendering attempts. Currently, no really implemented api for …
…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
Showing
23 changed files
with
514 additions
and
40 deletions.
There are no files selected for viewing
255 changes: 255 additions & 0 deletions
255
src/main/java/de/srendi/advancedperipherals/client/RenderUtil.java
Large diffs are not rendered by default.
Oops, something went wrong.
75 changes: 75 additions & 0 deletions
75
...in/java/de/srendi/advancedperipherals/client/smartglasses/OverlayModuleLevelRenderer.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,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(); | ||
|
||
} | ||
} | ||
|
||
} |
2 changes: 1 addition & 1 deletion
2
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
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
15 changes: 15 additions & 0 deletions
15
src/main/java/de/srendi/advancedperipherals/client/smartglasses/objects/BlockRenderer.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,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) { | ||
|
||
} | ||
} |
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
2 changes: 1 addition & 1 deletion
2
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
4 changes: 2 additions & 2 deletions
4
src/main/java/de/srendi/advancedperipherals/client/smartglasses/objects/ItemRenderer.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
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
4 changes: 2 additions & 2 deletions
4
src/main/java/de/srendi/advancedperipherals/client/smartglasses/objects/TextRenderer.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
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
2 changes: 1 addition & 1 deletion
2
.../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
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
86 changes: 86 additions & 0 deletions
86
...dvancedperipherals/common/smartglasses/modules/overlay/objects/three_dim/BlockObject.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,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; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...pherals/common/smartglasses/modules/overlay/objects/three_dim/ThreeDimensionalObject.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,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); | ||
} | ||
} |
Oops, something went wrong.