-
-
Notifications
You must be signed in to change notification settings - Fork 36
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
14 changed files
with
383 additions
and
223 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 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
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 |
---|---|---|
@@ -1,9 +1,19 @@ | ||
package dev.tr7zw.exordium.access; | ||
|
||
import dev.tr7zw.exordium.access.VanillaBufferAccess.ChatOverlayAccess; | ||
import java.util.List; | ||
|
||
public interface ChatAccess extends ChatOverlayAccess { | ||
import net.minecraft.client.GuiMessage; | ||
|
||
void updateState(int tickCount); | ||
public interface ChatAccess { | ||
|
||
List<GuiMessage.Line> getTrimmedMessages(); | ||
|
||
int getChatScollbarPos(); | ||
|
||
boolean isChatFocused(); | ||
|
||
boolean isChatHidden(); | ||
|
||
int getLinesPerPage(); | ||
|
||
} |
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
9 changes: 9 additions & 0 deletions
9
src/main/java/dev/tr7zw/exordium/components/BufferComponent.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,9 @@ | ||
package dev.tr7zw.exordium.components; | ||
|
||
public interface BufferComponent<T> { | ||
|
||
public void captureState(T context); | ||
|
||
public boolean hasChanged(int tickCount, T context); | ||
|
||
} |
44 changes: 44 additions & 0 deletions
44
src/main/java/dev/tr7zw/exordium/components/BufferInstance.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,44 @@ | ||
package dev.tr7zw.exordium.components; | ||
|
||
import java.util.function.Supplier; | ||
|
||
import dev.tr7zw.exordium.util.BufferedComponent; | ||
import dev.tr7zw.exordium.versionless.config.Config; | ||
import lombok.Getter; | ||
import net.minecraft.resources.ResourceLocation; | ||
|
||
public final class BufferInstance<T> { | ||
|
||
@Getter | ||
private final ResourceLocation id; | ||
private final BufferComponent<T> component; | ||
private final BufferedComponent buffer; | ||
|
||
BufferInstance(ResourceLocation id, BufferComponent<T> component, Supplier<Config.ComponentSettings> settings) { | ||
this.id = id; | ||
this.component = component; | ||
this.buffer = new BufferedComponent(settings); | ||
} | ||
|
||
/** | ||
* Tries to render the buffer. Returns false if the buffer was not rendered and | ||
* the normal render logic should be used. | ||
* | ||
* @param context | ||
* @return | ||
*/ | ||
public boolean renderBuffer(int ticks, T context) { | ||
return buffer.render(() -> component.hasChanged(ticks, context)); | ||
} | ||
|
||
/** | ||
* This method should be called after the render logic, no matter if the buffer | ||
* or normal render logic was used. | ||
* | ||
* @param context | ||
*/ | ||
public void postRender(T context) { | ||
buffer.renderEnd(() -> component.captureState(context)); | ||
} | ||
|
||
} |
133 changes: 133 additions & 0 deletions
133
src/main/java/dev/tr7zw/exordium/components/BufferManager.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,133 @@ | ||
package dev.tr7zw.exordium.components; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.concurrent.atomic.AtomicBoolean; | ||
import java.util.function.Consumer; | ||
import java.util.function.Function; | ||
import java.util.function.Supplier; | ||
|
||
import dev.tr7zw.exordium.ExordiumModBase; | ||
import dev.tr7zw.exordium.access.ChatAccess; | ||
import dev.tr7zw.exordium.access.GuiAccess; | ||
import dev.tr7zw.exordium.access.TablistAccess; | ||
import dev.tr7zw.exordium.access.VanillaBufferAccess.CrosshairOverlayAccess; | ||
import dev.tr7zw.exordium.access.VanillaBufferAccess.DebugOverlayAccess; | ||
import dev.tr7zw.exordium.access.VanillaBufferAccess.ExperienceBarOverlayAccess; | ||
import dev.tr7zw.exordium.access.VanillaBufferAccess.HotbarOverlayAccess; | ||
import dev.tr7zw.exordium.access.VanillaBufferAccess.ScoreBoardOverlayAccess; | ||
import dev.tr7zw.exordium.access.VanillaBufferAccess.VignetteOverlayAccess; | ||
import dev.tr7zw.exordium.components.vanilla.ChatComponent; | ||
import dev.tr7zw.exordium.util.BufferedComponent; | ||
import dev.tr7zw.exordium.versionless.config.Config; | ||
import lombok.NoArgsConstructor; | ||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.client.gui.Gui; | ||
import net.minecraft.client.gui.GuiGraphics; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.world.scores.DisplaySlot; | ||
import net.minecraft.world.scores.Scoreboard; | ||
|
||
@NoArgsConstructor | ||
public class BufferManager { | ||
|
||
// private final Map<ResourceLocation, Function<Gui, BufferedComponent>> vanillaBuffers = new HashMap<>(); | ||
// private final Map<ResourceLocation, Consumer<HandlerData>> customHandlers = new HashMap<>(); | ||
// private final Map<ResourceLocation, Runnable> customEndHandlers = new HashMap<>(); | ||
private final Map<ResourceLocation, BufferInstance<?>> buffers = new HashMap<>(); | ||
|
||
public void initialize() { | ||
ExordiumModBase inst = ExordiumModBase.instance; | ||
Minecraft minecraft = Minecraft.getInstance(); | ||
// vanillaBuffers.put(new ResourceLocation("debug_text"), | ||
// gui -> ((DebugOverlayAccess) gui).getDebugOverlayBuffer()); | ||
// vanillaBuffers.put(new ResourceLocation("crosshair"), | ||
// gui -> ((CrosshairOverlayAccess) gui).exordium_getCrosshairOverlayBuffer()); | ||
// vanillaBuffers.put(new ResourceLocation("experience_bar"), | ||
// gui -> ((ExperienceBarOverlayAccess) gui).getExperienceBarOverlayBuffer()); | ||
// vanillaBuffers.put(new ResourceLocation("scoreboard"), | ||
// gui -> ((ScoreBoardOverlayAccess) gui).getScoreBoardOverlayBuffer()); | ||
// vanillaBuffers.put(new ResourceLocation("hotbar"), gui -> ((HotbarOverlayAccess) gui).getHotbarOverlayBuffer()); | ||
// registerCustomHandler(new ResourceLocation("vignette"), data -> { | ||
// VignetteOverlayAccess vignette = (VignetteOverlayAccess) minecraft.gui; | ||
// if (ExordiumModBase.instance.config.vignetteSettings.isEnabled()) { | ||
// if (!vignette.getVignetteOverlayBuffer().render()) { | ||
// vignette.renderCustomVignette(data.gui()); | ||
// } | ||
// data.cancel().set(true); | ||
// } | ||
// vignette.getVignetteOverlayBuffer().renderEnd(); | ||
// }); | ||
// registerCustomHandler(new ResourceLocation("chat_panel"), data -> { | ||
// GuiAccess guiAccess = (GuiAccess) minecraft.gui; | ||
// ChatAccess chatAccess = (ChatAccess) guiAccess.getChatComponent(); | ||
// chatAccess.updateState(guiAccess.getTickCount()); | ||
// BufferedComponent bufferedComponent = chatAccess.getChatOverlayBuffer(); | ||
// if (bufferedComponent.render()) { | ||
// data.cancel().set(true); | ||
// } | ||
// }); | ||
registerBuffer(ChatComponent.getId(), new ChatComponent(), () -> inst.config.chatSettings); | ||
|
||
// registerCustomEndHandler(new ResourceLocation("chat_panel"), () -> { | ||
// GuiAccess guiAccess = (GuiAccess) minecraft.gui; | ||
// ChatAccess chatAccess = (ChatAccess) guiAccess.getChatComponent(); | ||
// BufferedComponent bufferedComponent = chatAccess.getChatOverlayBuffer(); | ||
// bufferedComponent.renderEnd(); | ||
// }); | ||
// registerCustomHandler(new ResourceLocation("player_list"), data -> { | ||
// GuiAccess guiAccess = (GuiAccess) minecraft.gui; | ||
// TablistAccess tablistAccess = (TablistAccess) guiAccess.getPlayerTabOverlay(); | ||
// Scoreboard scoreboard = minecraft.level.getScoreboard(); | ||
// tablistAccess.updateState(scoreboard, scoreboard.getDisplayObjective(DisplaySlot.LIST)); | ||
// BufferedComponent bufferedComponent = tablistAccess.getPlayerListOverlayBuffer(); | ||
// if (bufferedComponent.render()) { | ||
// data.cancel().set(true); | ||
// } | ||
// }); | ||
// registerCustomEndHandler(new ResourceLocation("player_list"), () -> { | ||
// GuiAccess guiAccess = (GuiAccess) minecraft.gui; | ||
// TablistAccess tabAccess = (TablistAccess) guiAccess.getPlayerTabOverlay(); | ||
// BufferedComponent bufferedComponent = tabAccess.getPlayerListOverlayBuffer(); | ||
// bufferedComponent.renderEnd(); | ||
// }); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
public <T> BufferInstance<T> getBufferInstance(ResourceLocation id, Class<T> context) { | ||
return (BufferInstance<T>) buffers.get(id); | ||
} | ||
|
||
public void registerBuffer(ResourceLocation id, BufferComponent<?> component, | ||
Supplier<Config.ComponentSettings> settings) { | ||
this.buffers.put(id, new BufferInstance<>(id, component, settings)); | ||
} | ||
// | ||
// public BufferedComponent getBufferedComponent(ResourceLocation resourceLocation, Gui gui) { | ||
// Function<Gui, BufferedComponent> vanFun = vanillaBuffers.get(resourceLocation); | ||
// if (vanFun != null) { | ||
// return vanFun.apply(gui); | ||
// } | ||
// return null; | ||
// } | ||
// | ||
// public Consumer<HandlerData> getCustomHandler(ResourceLocation resourceLocation) { | ||
// return customHandlers.get(resourceLocation); | ||
// } | ||
// | ||
// public Runnable getCustomEndHandler(ResourceLocation resourceLocation) { | ||
// return customEndHandlers.get(resourceLocation); | ||
// } | ||
// | ||
// public void registerCustomHandler(ResourceLocation resourceLocation, Consumer<HandlerData> handler) { | ||
// customHandlers.put(resourceLocation, handler); | ||
// } | ||
// | ||
// public void registerCustomEndHandler(ResourceLocation resourceLocation, Runnable handler) { | ||
// customEndHandlers.put(resourceLocation, handler); | ||
// } | ||
// | ||
// public record HandlerData(GuiGraphics gui, AtomicBoolean cancel) { | ||
// } | ||
|
||
} |
Oops, something went wrong.