-
Notifications
You must be signed in to change notification settings - Fork 5
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
1 parent
75d22df
commit 3fa68aa
Showing
65 changed files
with
801 additions
and
82 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
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
57 changes: 57 additions & 0 deletions
57
src/main/java/org/ladysnake/blabber/api/DialogueIllustration.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,57 @@ | ||
/* | ||
* Blabber | ||
* Copyright (C) 2022-2024 Ladysnake | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program; If not, see <https://www.gnu.org/licenses>. | ||
*/ | ||
package org.ladysnake.blabber.api; | ||
|
||
import net.minecraft.client.font.TextRenderer; | ||
import net.minecraft.client.gui.DrawContext; | ||
import net.minecraft.entity.Entity; | ||
import net.minecraft.server.command.ServerCommandSource; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
/** | ||
* A renderable illustration in dialogues, such as entities or items. | ||
*/ | ||
public interface DialogueIllustration { | ||
/** | ||
* Draw this illustration to the screen. | ||
* | ||
* @param context a context to draw in | ||
* @param textRenderer a text renderer | ||
* @param x the x position it should be drawn relative to | ||
* @param y the y position it should be drawn relative to | ||
* @param mouseX the current x mouse position | ||
* @param mouseY the current y mouse position | ||
* @param tickDelta how much time has passed since last frame | ||
*/ | ||
void render(DrawContext context, TextRenderer textRenderer, int x, int y, int mouseX, int mouseY, float tickDelta); | ||
|
||
/** | ||
* @return the DialogueIllustrationType that corresponds to this illustration | ||
*/ | ||
DialogueIllustrationType<? extends DialogueIllustration> getType(); | ||
|
||
/** | ||
* If this illustration contains some text, this will be parsed *server-side*. | ||
* @param source the context in which this is parsed | ||
* @param sender the player that is going to dialogue | ||
* @return a DialogueIllustration with the required text parsed (often, simply this) | ||
*/ | ||
default DialogueIllustration parseText(@Nullable ServerCommandSource source, @Nullable Entity sender) { | ||
return this; | ||
} | ||
} |
89 changes: 89 additions & 0 deletions
89
src/main/java/org/ladysnake/blabber/api/DialogueIllustrationType.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,89 @@ | ||
/* | ||
* Blabber | ||
* Copyright (C) 2022-2024 Ladysnake | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program; If not, see <https://www.gnu.org/licenses>. | ||
*/ | ||
package org.ladysnake.blabber.api; | ||
|
||
import com.mojang.serialization.Codec; | ||
import net.minecraft.network.PacketByteBuf; | ||
import net.minecraft.util.dynamic.Codecs; | ||
import org.jetbrains.annotations.ApiStatus; | ||
import org.ladysnake.blabber.impl.common.BlabberRegistrar; | ||
import org.ladysnake.blabber.impl.common.illustrations.DialogueIllustrationCollection; | ||
|
||
import java.util.function.BiConsumer; | ||
import java.util.function.Function; | ||
|
||
/** | ||
* A type of {@link DialogueIllustration}, used for registration and abstraction. | ||
* @param <T> the DialogueIllustration type this type creates | ||
*/ | ||
public final class DialogueIllustrationType<T extends DialogueIllustration> { | ||
public static final Codec<DialogueIllustration> CODEC = Codecs.createRecursive("illustration_type", self -> | ||
Codecs.alternatively( | ||
BlabberRegistrar.ILLUSTRATION_REGISTRY.getCodec() | ||
.dispatch("type", DialogueIllustration::getType, DialogueIllustrationType::getCodec), | ||
Codec.list(self).xmap(DialogueIllustrationCollection::new, DialogueIllustrationCollection::elements) | ||
) | ||
); | ||
|
||
private final Codec<T> codec; | ||
private final Function<PacketByteBuf, T> read; | ||
private final BiConsumer<PacketByteBuf, T> write; | ||
|
||
public DialogueIllustrationType(Codec<T> codec, Function<PacketByteBuf, T> read, BiConsumer<PacketByteBuf, T> write) { | ||
this.codec = codec; | ||
this.read = read; | ||
this.write = write; | ||
} | ||
|
||
/** | ||
* @return A codec to serialize and deserialize this DialogueIllustration | ||
*/ | ||
public Codec<T> getCodec() { | ||
return codec; | ||
} | ||
|
||
/** | ||
* Parses this type of DialogueIllustration from a packet. The data within should be everything the client needs to render this | ||
* @param buf the packet's data | ||
* @return a newly parsed DialogueIllustration corresponding to this type | ||
*/ | ||
@ApiStatus.Experimental | ||
public T readFromPacket(PacketByteBuf buf) { | ||
return this.read.apply(buf); | ||
} | ||
|
||
/** | ||
* Write the data this illustration needs to be drawn client-side to a packet | ||
* @param buf the packet to write to | ||
* @param toWrite the illustration to write | ||
*/ | ||
@ApiStatus.Experimental | ||
public void writeToPacket(PacketByteBuf buf, T toWrite) { | ||
this.write.accept(buf, toWrite); | ||
} | ||
|
||
/** | ||
* Same as writeToPacket, but does an unchecked cast, for when the type information is lost somewhere. | ||
* Make sure it's safe. | ||
*/ | ||
@ApiStatus.Internal | ||
public void writeToPacketUnsafe(PacketByteBuf buf, DialogueIllustration illustration) { | ||
//noinspection unchecked | ||
this.writeToPacket(buf, (T) illustration); | ||
} | ||
} |
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/org/ladysnake/blabber/api/client/BlabberScreenRegistry.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
2 changes: 1 addition & 1 deletion
2
src/main/java/org/ladysnake/blabber/impl/client/BlabberClient.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
2 changes: 1 addition & 1 deletion
2
src/main/java/org/ladysnake/blabber/impl/client/BlabberRpgDialogueScreen.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
2 changes: 1 addition & 1 deletion
2
src/main/java/org/ladysnake/blabber/impl/client/package-info.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
2 changes: 1 addition & 1 deletion
2
src/main/java/org/ladysnake/blabber/impl/common/BlabberCommand.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
2 changes: 1 addition & 1 deletion
2
src/main/java/org/ladysnake/blabber/impl/common/BlabberEntitySelectorExt.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
2 changes: 1 addition & 1 deletion
2
src/main/java/org/ladysnake/blabber/impl/common/CommandDialogueAction.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
2 changes: 1 addition & 1 deletion
2
src/main/java/org/ladysnake/blabber/impl/common/DialogueInitializationException.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
2 changes: 1 addition & 1 deletion
2
src/main/java/org/ladysnake/blabber/impl/common/DialogueLoader.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
2 changes: 1 addition & 1 deletion
2
src/main/java/org/ladysnake/blabber/impl/common/DialogueRegistry.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
Oops, something went wrong.