generated from KessokuTeaTime/Example-Mod
-
Notifications
You must be signed in to change notification settings - Fork 0
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
11 changed files
with
161 additions
and
85 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package net.krlite.knowledges; | ||
|
||
import com.mojang.blaze3d.systems.RenderSystem; | ||
import net.krlite.equator.render.frame.FrameInfo; | ||
import net.krlite.knowledges.api.component.Knowledge; | ||
import net.krlite.knowledges.api.representable.Representable; | ||
import net.krlite.knowledges.mixin.client.InGameHudInvoker; | ||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.client.gui.DrawContext; | ||
import net.minecraft.client.render.GameRenderer; | ||
import net.minecraft.world.GameMode; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.Optional; | ||
import java.util.function.Consumer; | ||
|
||
public class KnowledgesHud { | ||
@Nullable | ||
private Representable<?> representable; | ||
|
||
public void setRepresentable(@NotNull Representable<?> representable) { | ||
this.representable = representable; | ||
} | ||
|
||
public void clearRepresentable() { | ||
this.representable = null; | ||
} | ||
|
||
public Optional<Representable<?>> getRepresentable() { | ||
return Optional.ofNullable(representable); | ||
} | ||
|
||
public void render(DrawContext context, Consumer<Representable<?>> renderConsumer) { | ||
getRepresentable().ifPresent(rep -> { | ||
|
||
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); | ||
RenderSystem.setShader(GameRenderer::getPositionTexProgram); | ||
RenderSystem.enableBlend(); | ||
|
||
context.getMatrices().push(); | ||
context.getMatrices().translate(FrameInfo.scaled().w() / 2, FrameInfo.scaled().h() / 2, 0); | ||
|
||
render: { | ||
MinecraftClient client = MinecraftClient.getInstance(); | ||
if (client.world == null || client.player == null) break render; | ||
|
||
boolean isFirstPerson = client.options.getPerspective().isFirstPerson(); | ||
boolean isSpectator = client.interactionManager != null && client.interactionManager.getCurrentGameMode() == GameMode.SPECTATOR; | ||
boolean shouldRenderSpectatorCrosshair = ((InGameHudInvoker) client.inGameHud).invokeShouldRenderSpectatorCrosshair(rep.hitResult()); | ||
boolean isInDebugHud = client.getDebugHud().shouldShowDebugHud() | ||
&& !client.options.hudHidden | ||
&& !client.player.hasReducedDebugInfo() | ||
&& !client.options.getReducedDebugInfo().getValue(); | ||
|
||
if (isFirstPerson | ||
&& (!isSpectator || shouldRenderSpectatorCrosshair) | ||
&& (KnowledgesClient.CONFIG.global.visibleInDebugHud || !isInDebugHud) | ||
) { | ||
renderConsumer.accept(rep); | ||
} | ||
} | ||
|
||
context.getMatrices().pop(); | ||
}); | ||
} | ||
} |
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
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
63 changes: 63 additions & 0 deletions
63
src/main/java/net/krlite/knowledges/impl/representable/EmptyRepresentable.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,63 @@ | ||
package net.krlite.knowledges.impl.representable; | ||
|
||
import net.krlite.knowledges.api.representable.Representable; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.nbt.NbtCompound; | ||
import net.minecraft.util.hit.HitResult; | ||
import net.minecraft.world.World; | ||
|
||
public class EmptyRepresentable extends KnowledgesRepresentable<HitResult> implements Representable<HitResult> { | ||
public EmptyRepresentable(Builder builder) { | ||
super(builder); | ||
} | ||
|
||
@Override | ||
public HitResult.Type type() { | ||
return HitResult.Type.MISS; | ||
} | ||
|
||
public static class Builder extends KnowledgesRepresentable.Builder<HitResult> implements Representable.Builder<HitResult, EmptyRepresentable, Builder> { | ||
@Override | ||
public Builder hitResult(HitResult hitResult) { | ||
this.hitResult = hitResult; | ||
return this; | ||
} | ||
|
||
@Override | ||
public Builder world(World world) { | ||
this.world = world; | ||
return this; | ||
} | ||
|
||
@Override | ||
public Builder player(PlayerEntity player) { | ||
this.player = player; | ||
return this; | ||
} | ||
|
||
@Override | ||
public Builder data(NbtCompound data) { | ||
this.data = data; | ||
return this; | ||
} | ||
|
||
@Override | ||
public Builder hasServer(boolean hasServer) { | ||
this.hasServer = hasServer; | ||
return this; | ||
} | ||
|
||
@Override | ||
public EmptyRepresentable build() { | ||
return new EmptyRepresentable(this); | ||
} | ||
|
||
public static Builder create() { | ||
return new Builder(); | ||
} | ||
|
||
public static Builder from(EmptyRepresentable representable) { | ||
return Representable.Builder.append(create(), representable); | ||
} | ||
} | ||
} |
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
54 changes: 0 additions & 54 deletions
54
src/main/java/net/krlite/knowledges/mixin/client/KnowledgesHud.java
This file was deleted.
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