Skip to content

Commit

Permalink
Work on Ping icon
Browse files Browse the repository at this point in the history
  • Loading branch information
GirafiStudios committed Jan 28, 2020
1 parent 2baf7d9 commit c904199
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
25 changes: 12 additions & 13 deletions src/main/java/dmillerw/ping/client/PingHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.ForgeHooksClient;
import net.minecraftforge.client.event.EntityViewRenderEvent;
import net.minecraftforge.client.event.RenderBlockOverlayEvent;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.client.event.RenderWorldLastEvent;
import net.minecraftforge.event.TickEvent;
Expand All @@ -45,6 +46,7 @@
public class PingHandler {
public static final PingHandler INSTANCE = new PingHandler();
public static final ResourceLocation TEXTURE = new ResourceLocation(Ping.MOD_ID, "textures/ping.png");
public static final RenderType PING_TYPE = PingRenderType.getPingIcon(TEXTURE);
private static List<PingWrapper> active_pings = new ArrayList<>();

public void onPingPacket(ServerBroadcastPing packet) {
Expand Down Expand Up @@ -152,9 +154,8 @@ public static void renderPingOffscreen(RenderGameOverlayEvent.Post event) {
matrixStack.push();
MatrixStack.Entry matrixEntry = matrixStack.getLast();
Matrix4f matrix4f = matrixEntry.getPositionMatrix();
Matrix3f matrix3f = matrixEntry.getNormalMatrix();
RenderType pingOffset = null; //TODO
IRenderTypeBuffer.Impl buffer = Minecraft.getInstance().getRenderTypeBuffers().getBufferSource();
IRenderTypeBuffer.Impl buffer = mc.getRenderTypeBuffers().getBufferSource();
IVertexBuilder vertexBuilder = buffer.getBuffer(pingOffset);
Minecraft.getInstance().textureManager.bindTexture(TEXTURE);

Expand Down Expand Up @@ -206,18 +207,16 @@ public static void onClientTick(TickEvent.ClientTickEvent event) {

private static void renderPing(double px, double py, double pz, MatrixStack matrixStack, Entity renderEntity, PingWrapper ping) {
Minecraft mc = Minecraft.getInstance();
matrixStack.push(); //push
matrixStack.translate(px, py, pz); //translate
matrixStack.rotate(Vector3f.YP.rotationDegrees(-renderEntity.rotationYaw)); //rotate
matrixStack.rotate(Vector3f.XP.rotationDegrees(renderEntity.rotationPitch)); //rotate
matrixStack.rotate(Vector3f.ZP.rotationDegrees(180.0F)); //rotate
matrixStack.push();
matrixStack.translate(px, py, pz);
matrixStack.rotate(Vector3f.YP.rotationDegrees(-renderEntity.rotationYaw));
matrixStack.rotate(Vector3f.XP.rotationDegrees(renderEntity.rotationPitch));
matrixStack.rotate(Vector3f.ZP.rotationDegrees(180.0F));

MatrixStack.Entry matrixEntry = matrixStack.getLast();
Matrix4f matrix4f = matrixEntry.getPositionMatrix();
Matrix3f matrix3f = matrixEntry.getNormalMatrix();
RenderType pingIcon = PingRenderType.getPingIcon();
IRenderTypeBuffer.Impl buffer = Minecraft.getInstance().getRenderTypeBuffers().getBufferSource();
IVertexBuilder vertexBuilder = buffer.getBuffer(pingIcon);
IRenderTypeBuffer.Impl buffer = mc.getRenderTypeBuffers().getBufferSource();
IVertexBuilder vertexBuilder = buffer.getBuffer(PING_TYPE);

float min = -0.25F - (0.25F * (float) ping.animationTimer / 20F);
float max = 0.25F + (0.25F * (float) ping.animationTimer / 20F);
Expand All @@ -237,9 +236,9 @@ private static void renderPing(double px, double py, double pz, MatrixStack matr
VertexHelper.renderPosTexColorNoZ(vertexBuilder, matrix4f, max, max, ping.type.minU, ping.type.maxV, 255, 255, 255, alpha);
VertexHelper.renderPosTexColorNoZ(vertexBuilder, matrix4f, max, min, ping.type.minU, ping.type.maxV, 255, 255, 255, alpha);
VertexHelper.renderPosTexColorNoZ(vertexBuilder, matrix4f, min, min, ping.type.minU, ping.type.maxV, 255, 255, 255, alpha);
buffer.finish(pingIcon);
buffer.finish(PING_TYPE);

matrixStack.pop(); //pop
matrixStack.pop();
}

private static void renderPingOverlay(double x, double y, double z, MatrixStack matrixStack, PingWrapper ping) {
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/dmillerw/ping/client/PingRenderType.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,26 @@
import net.minecraft.client.renderer.RenderState;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.util.ResourceLocation;

public class PingRenderType extends RenderState {
protected static final RenderState.TransparencyState OVERLAY_TRANSPARENCY = new RenderState.TransparencyState("overlay_transparency", () -> {
RenderSystem.enableBlend();
RenderSystem.defaultBlendFunc();
}, RenderSystem::disableBlend);
protected static final RenderState.LayerState DEPTH = new RenderState.LayerState("depth", GlStateManager::disableDepthTest, GlStateManager::enableDepthTest);
protected static final RenderState.LayerState DISABLE_DEPTH = new RenderState.LayerState("disable_depth", GlStateManager::disableDepthTest, GlStateManager::enableDepthTest);

public PingRenderType(String string, Runnable r, Runnable r1) {
super(string, r, r1);
}

public static RenderType getPingOverlay() {
RenderType.State renderTypeState = RenderType.State.builder().transparency(OVERLAY_TRANSPARENCY).texture(BLOCK_SHEET).layer(DEPTH).build(true);
RenderType.State renderTypeState = RenderType.State.builder().transparency(OVERLAY_TRANSPARENCY).texture(BLOCK_SHEET).layer(DISABLE_DEPTH).build(true);
return RenderType.get("ping_overlay", DefaultVertexFormats.POSITION_TEX_COLOR, 7, 262144, true, true, renderTypeState);
}

public static RenderType getPingIcon() {
RenderType.State renderTypeState = RenderType.State.builder().texture(BLOCK_SHEET).layer(DEPTH).build(true);
public static RenderType getPingIcon(ResourceLocation location) {
RenderType.State renderTypeState = RenderType.State.builder().texture(new RenderState.TextureState(location, false, false)).layer(DISABLE_DEPTH).build(true);
return RenderType.get("ping_icon", DefaultVertexFormats.POSITION_TEX_COLOR, 7, 262144, true, true, renderTypeState);
}
}

0 comments on commit c904199

Please sign in to comment.