-
-
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.
- Loading branch information
Showing
7 changed files
with
306 additions
and
68 deletions.
There are no files selected for viewing
205 changes: 141 additions & 64 deletions
205
src/main/java/de/srendi/advancedperipherals/client/RenderUtil.java
Large diffs are not rendered by default.
Oops, something went wrong.
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
49 changes: 49 additions & 0 deletions
49
...va/de/srendi/advancedperipherals/client/smartglasses/objects/threedim/SphereRenderer.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,49 @@ | ||
package de.srendi.advancedperipherals.client.smartglasses.objects.threedim; | ||
|
||
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.VertexFormat; | ||
import de.srendi.advancedperipherals.client.RenderUtil; | ||
import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.objects.three_dim.SphereObject; | ||
import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.objects.three_dim.ThreeDimensionalObject; | ||
import net.minecraft.client.renderer.GameRenderer; | ||
import net.minecraft.world.phys.Vec3; | ||
import net.minecraftforge.client.event.RenderLevelStageEvent; | ||
|
||
import java.util.List; | ||
|
||
public class SphereRenderer implements IThreeDObjectRenderer { | ||
|
||
@Override | ||
public void renderBatch(List<ThreeDimensionalObject> batch, RenderLevelStageEvent event, PoseStack poseStack, Vec3 view, BufferBuilder bufferBuilder) { | ||
poseStack.pushPose(); | ||
|
||
for (ThreeDimensionalObject renderableObject : batch) { | ||
poseStack.pushPose(); | ||
onPreRender(renderableObject); | ||
bufferBuilder.begin(VertexFormat.Mode.TRIANGLES, DefaultVertexFormat.POSITION_COLOR_NORMAL); | ||
|
||
SphereObject sphere = (SphereObject) renderableObject; | ||
|
||
RenderSystem.setShader(GameRenderer::getPositionColorShader); | ||
float alpha = renderableObject.opacity; | ||
float red = (float) (renderableObject.color >> 16 & 255) / 255.0F; | ||
float green = (float) (renderableObject.color >> 8 & 255) / 255.0F; | ||
float blue = (float) (renderableObject.color & 255) / 255.0F; | ||
|
||
poseStack.translate(-view.x + renderableObject.getX(), -view.y + renderableObject.getY(), -view.z + renderableObject.getZ()); | ||
RenderUtil.drawSphere(poseStack, bufferBuilder, 1f, 0f, 0f, 0f, red, green, blue, alpha, sphere.sectors, sphere.stacks); | ||
BufferUploader.drawWithShader(bufferBuilder.end()); | ||
onPostRender(renderableObject); | ||
|
||
poseStack.popPose(); | ||
} | ||
|
||
|
||
poseStack.popPose(); | ||
|
||
} | ||
} |
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
88 changes: 88 additions & 0 deletions
88
...vancedperipherals/common/smartglasses/modules/overlay/objects/three_dim/SphereObject.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,88 @@ | ||
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.AdvancedPeripherals; | ||
import de.srendi.advancedperipherals.client.smartglasses.objects.IObjectRenderer; | ||
import de.srendi.advancedperipherals.client.smartglasses.objects.threedim.SphereRenderer; | ||
import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.OverlayModule; | ||
import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.propertytypes.FixedPointNumberProperty; | ||
import net.minecraft.network.FriendlyByteBuf; | ||
|
||
import java.util.UUID; | ||
|
||
public class SphereObject extends ThreeDimensionalObject { | ||
public static final int TYPE_ID = 6; | ||
|
||
private final IObjectRenderer renderer = new SphereRenderer(); | ||
|
||
@FixedPointNumberProperty(min = 1, max = 1024) | ||
public int sectors = 16; | ||
|
||
@FixedPointNumberProperty(min = 1, max = 1024) | ||
public int stacks = 16; | ||
|
||
public SphereObject(OverlayModule module, IArguments arguments) throws LuaException { | ||
super(module, arguments); | ||
reflectivelyMapProperties(arguments); | ||
} | ||
|
||
public SphereObject(UUID player) { | ||
super(player); | ||
} | ||
|
||
@Override | ||
public void encode(FriendlyByteBuf buffer) { | ||
buffer.writeInt(TYPE_ID); | ||
super.encode(buffer); | ||
buffer.writeInt(sectors); | ||
buffer.writeInt(stacks); | ||
} | ||
|
||
public static SphereObject 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(); | ||
int maxZ = buffer.readInt(); | ||
|
||
boolean disableDepthTest = buffer.readBoolean(); | ||
boolean disableCulling = buffer.readBoolean(); | ||
|
||
int sectors = buffer.readInt(); | ||
int stacks = buffer.readInt(); | ||
|
||
SphereObject clientObject = new SphereObject(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.maxZ = maxZ; | ||
clientObject.disableDepthTest = disableDepthTest; | ||
clientObject.disableCulling = disableCulling; | ||
clientObject.sectors = sectors; | ||
clientObject.stacks = stacks; | ||
|
||
return clientObject; | ||
} | ||
|
||
@Override | ||
public IObjectRenderer getRenderObject() { | ||
return renderer; | ||
} | ||
} |