Skip to content

Commit

Permalink
big update
Browse files Browse the repository at this point in the history
  • Loading branch information
txnitxnichopper committed Oct 17, 2024
1 parent eafe722 commit cfe977f
Show file tree
Hide file tree
Showing 39 changed files with 940 additions and 532 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ kotlin.stdlib.default.dependency=false

#----------Mod Properties----------#
#Make sure you edit these before running renameExampleMod!
mod.version=1.0.11
mod.version=1.0.12
mod.license=Toni's MMC License
# Root Folder Path (/java/group/namespace/)
mod.group=toni
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

90 changes: 62 additions & 28 deletions src/main/java/toni/immersivemessages/ImmersiveMessagesCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import toni.immersivemessages.api.ImmersiveMessage;
import toni.immersivemessages.api.SoundEffect;
import toni.immersivemessages.api.TextAnchor;
import toni.immersivemessages.util.ImmersiveColor;

import static net.minecraft.commands.Commands.argument;
import static net.minecraft.commands.Commands.literal;
Expand All @@ -21,6 +22,48 @@ public static void register() {

CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> dispatcher.register(literal("immersivemessages")
.requires(source -> source.hasPermission(2))
.then(literal("popup")
.then(argument("player", EntityArgument.players())
.then(argument("duration", FloatArgumentType.floatArg())
.then(argument("title", StringArgumentType.string())
.then(argument("subtitle", StringArgumentType.greedyString())
.executes(context -> {
var players = EntityArgument.getPlayers(context, "player");
var duration = FloatArgumentType.getFloat(context, "duration");
var title = StringArgumentType.getString(context, "title");
var subtitle = StringArgumentType.getString(context, "subtitle");

ImmersiveMessage.popup(duration, title, subtitle)
.sendServer(players);

return 1;
})
)
)
)
)
)
.then(literal("toast")
.then(argument("player", EntityArgument.players())
.then(argument("duration", FloatArgumentType.floatArg())
.then(argument("title", StringArgumentType.string())
.then(argument("subtitle", StringArgumentType.greedyString())
.executes(context -> {
var players = EntityArgument.getPlayers(context, "player");
var duration = FloatArgumentType.getFloat(context, "duration");
var title = StringArgumentType.getString(context, "title");
var subtitle = StringArgumentType.getString(context, "subtitle");

ImmersiveMessage.toast(duration, title, subtitle)
.sendServer(players);

return 1;
})
)
)
)
)
)
.then(literal("send")
.then(argument("player", EntityArgument.players())
.then(argument("duration", FloatArgumentType.floatArg())
Expand All @@ -30,33 +73,12 @@ public static void register() {
var duration = FloatArgumentType.getFloat(context, "duration");
var string = StringArgumentType.getString(context, "string");

// ImmersiveMessage.builder(duration, string)
// .slideUp()
// .typewriter(1f, false)
// .sound(SoundEffect.LOWSHORT)
// .fadeIn()
// .fadeOut()
// .sendServer(players);

ImmersiveMessage.builder(15f, "Check out the Quest Book!")
.anchor(TextAnchor.BOTTOM_LEFT)
.wrap()
.y(-20f)
.x(10f)
.size(1f)
.fadeIn(0.5f)
.fadeOut(0.5f)
.color(ChatFormatting.GOLD)
.style(style -> style.withUnderlined(true))
.subtext(0f, "You can open your §cquest book§r with the button in the top-left corner of your inventory menu, or with a hotkey!", 11f, (subtext) -> subtext
.anchor(TextAnchor.BOTTOM_LEFT)
.wrap()
.font(ImmersiveFont.ROBOTO)
.x(10f)
.size(1f)
.fadeIn(0.5f)
.fadeOut(0.5f)
)
ImmersiveMessage.builder(duration, string)
.slideUp()
.typewriter(1f, false)
.sound(SoundEffect.LOWSHORT)
.fadeIn()
.fadeOut()
.sendServer(players);

return 1;
Expand Down Expand Up @@ -91,10 +113,17 @@ public static void register() {
if (data.contains("bold")) tooltip.bold();
if (data.contains("italic")) tooltip.italic();
if (data.contains("wrap")) tooltip.wrap(0);
if (data.contains("background")) tooltip.background = true;

if (data.contains("background")) tooltip.background();
if (data.contains("bgColor")) tooltip.backgroundColor(new ImmersiveColor(TextColor.parseColor(data.getString("bgColor")).getOrThrow().getValue()));
if (data.contains("borderTop")) tooltip.backgroundColor(new ImmersiveColor(TextColor.parseColor(data.getString("borderTop")).getOrThrow().getValue()));
if (data.contains("borderBottom")) tooltip.backgroundColor(new ImmersiveColor(TextColor.parseColor(data.getString("borderBottom")).getOrThrow().getValue()));
if (data.contains("rainbow")) tooltip.rainbow();

if (data.contains("shake")) tooltip.shake();
if (data.contains("wave")) tooltip.wave();
if (data.contains("obfuscate")) tooltip.obfuscate();
if (data.contains("align")) tooltip.align(TextAnchor.fromInt(data.getInt("align")));
if (data.contains("anchor")) tooltip.anchor(TextAnchor.fromInt(data.getInt("anchor")));
if (data.contains("color")) tooltip.color(TextColor.parseColor(data.getString("color")) #if MC == "211" .getOrThrow() #endif);
if (data.contains("size")) tooltip.size(data.getFloat("size"));
Expand All @@ -110,6 +139,11 @@ public static void register() {
tooltip.slideUp();
}

if (data.contains("slideoutup")) tooltip.slideOutUp();
else if (data.contains("slideoutdown")) tooltip.slideOutDown();
else if (data.contains("slideoutleft")) tooltip.slideOutLeft();
else if (data.contains("slideoutright")) tooltip.slideOutRight();

tooltip.sendServer(players);
return 1;
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ static void renderTooltip(GuiGraphics graphics, float deltaTicks, ImmersiveMessa
return;
}

renderer.render(tooltip, graphics);
renderer.render(tooltip, graphics, deltaTicks);

if (tooltip.subtext != null)
renderTooltip(graphics, deltaTicks, tooltip.subtext, depth + 1);
Expand Down
161 changes: 160 additions & 1 deletion src/main/java/toni/immersivemessages/api/ImmersiveMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import io.netty.buffer.ByteBuf;
import net.minecraft.ChatFormatting;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.client.resources.sounds.SimpleSoundInstance;
import net.minecraft.core.RegistryAccess;
Expand All @@ -17,7 +18,10 @@
import toni.immersivemessages.IMClient;
import toni.immersivemessages.ImmersiveMessages;
import toni.immersivemessages.ImmersiveFont;
import toni.immersivemessages.ImmersiveMessagesManager;
import toni.immersivemessages.config.AllConfigs;
import toni.immersivemessages.networking.TooltipPacket;
import toni.immersivemessages.util.ImmersiveColor;
import toni.lib.animation.AnimationTimeline;
import toni.lib.animation.Binding;
import toni.lib.animation.easing.EasingType;
Expand Down Expand Up @@ -65,8 +69,14 @@ public class ImmersiveMessage {
private int obfuscateTimes = 1;

public TextAnchor anchor = TextAnchor.CENTER_CENTER;
public TextAnchor align = TextAnchor.CENTER_CENTER;
public int wrapMaxWidth = -1;

public boolean background = false;
public ImmersiveColor colorBackground = ImmersiveColor.BLACK.copy();
public ImmersiveColor colorBorderTop = new ImmersiveColor(36,1,89,255).mixWith(ImmersiveColor.WHITE, 0.1f);
public ImmersiveColor colorBorderBot = new ImmersiveColor(25,1,53,255);
public float rainbow = -1f;

private ImmersiveMessage() { }

Expand Down Expand Up @@ -114,8 +124,15 @@ private void encode(ByteBuf buffer) {
buf.writeFloat(typewriterSpeed);

buf.writeEnum(anchor);
buf.writeEnum(align);
buf.writeInt(wrapMaxWidth);
buf.writeBoolean(background);

buf.writeInt(colorBackground.getRGB());
buf.writeInt(colorBorderTop.getRGB());
buf.writeInt(colorBorderBot.getRGB());

buf.writeFloat(rainbow);
}


Expand Down Expand Up @@ -154,8 +171,16 @@ private static ImmersiveMessage decode(ByteBuf buffer) {
ths.typewriterSpeed = buf.readFloat();

ths.anchor = buf.readEnum(TextAnchor.class);
ths.align = buf.readEnum(TextAnchor.class);
ths.wrapMaxWidth = buf.readInt();
ths.background = buf.readBoolean();

ths.colorBackground = new ImmersiveColor(buf.readInt());
ths.colorBorderTop = new ImmersiveColor(buf.readInt());
ths.colorBorderBot = new ImmersiveColor(buf.readInt());

ths.rainbow = buf.readFloat();

return ths;
}

Expand Down Expand Up @@ -190,6 +215,72 @@ public static ImmersiveMessage builder(float duration, MutableComponent text) {
return tooltip;
}



public static ImmersiveMessage popup(float duration, String title, String subtitle) {
return ImmersiveMessage.builder(duration, title)
.anchor(TextAnchor.CENTER_CENTER)
.wrap(200)
.size(1f)
.background()
.slideUp(0.3f)
.slideOutDown(0.3f)
.fadeIn(0.5f)
.fadeOut(0.5f)
.color(ChatFormatting.GOLD)
.style(style -> style.withUnderlined(true))
.subtext(0f, subtitle, 8f, (subtext) -> subtext
.anchor(TextAnchor.CENTER_CENTER)
.wrap(200)
.size(1f)
.slideUp(0.3f)
.slideOutDown(0.3f)
.fadeIn(0.5f)
.fadeOut(0.5f)
);
}

public static ImmersiveMessage toast(float duration, String title, String subtitle) {
return ImmersiveMessage.builder(duration, title)
.anchor(TextAnchor.TOP_LEFT)
.wrap()
.y(10f)
.x(10f)
.size(1f)
.slideLeft(0.3f)
.slideOutRight(0.3f)
.fadeIn(0.5f)
.fadeOut(0.5f)
.color(ChatFormatting.GOLD)
.style(style -> style.withUnderlined(true))
.subtext(0f, subtitle, 11f, (subtext) -> subtext
.anchor(TextAnchor.TOP_LEFT)
.wrap()
.x(10f)
.size(1f)
.slideLeft(0.3f)
.slideOutRight(0.3f)
.fadeIn(0.5f)
.fadeOut(0.5f)
);
}


public void render(GuiGraphics graphics, float deltaTicks) { render(graphics, deltaTicks, 0); }

private void render(GuiGraphics graphics, float deltaTicks, int depth) {
tick(deltaTicks);
animation.advancePlayhead(deltaTicks / 20);

if (depth == 0 && animation.getCurrent() >= animation.duration)
return;

ImmersiveMessagesManager.getRenderer().render(this, graphics, deltaTicks);

if (subtext != null)
subtext.render(graphics, deltaTicks, depth + 1);
}

public MutableComponent getText() {
if (typewriter) {
return typewriterCurrent.withStyle(style);
Expand All @@ -214,6 +305,42 @@ public ImmersiveMessage typewriter(float speed, boolean centerAligned) {
return this;
}

/**
* Enables a background.
*/
public ImmersiveMessage background() {
this.background = true;
return this;
}

/**
* Changes the border color to a rainbow effect, optionally with speed (default 2f).
*/
public ImmersiveMessage rainbow() { return rainbow(2f); }
public ImmersiveMessage rainbow(float speed) {
this.background = true;
this.rainbow = speed * 20f;
return this;
}

public ImmersiveMessage backgroundColor(int color) { return backgroundColor(new ImmersiveColor(color));}
public ImmersiveMessage backgroundColor(ImmersiveColor color) {
this.colorBackground = color;
return this;
}

public ImmersiveMessage borderTopColor(int color) { return borderTopColor(new ImmersiveColor(color));}
public ImmersiveMessage borderTopColor(ImmersiveColor color) {
this.colorBorderTop = color;
return this;
}

public ImmersiveMessage borderBottomColor(int color) { return borderBottomColor(new ImmersiveColor(color));}
public ImmersiveMessage borderBottomColor(ImmersiveColor color) {
this.colorBorderBot = color;
return this;
}

/**
* Sets a max width for text, beyond which will be wrapped.
*/
Expand All @@ -226,7 +353,7 @@ public ImmersiveMessage wrap(int maxWidth) {
* Wraps long lines of text.
*/
public ImmersiveMessage wrap() {
this.wrapMaxWidth = 500;
this.wrapMaxWidth = 0;
return this;
}

Expand All @@ -238,6 +365,14 @@ public ImmersiveMessage anchor(TextAnchor anchor) {
return this;
}

/**
* Changes the local offset of the text bounding box
*/
public ImmersiveMessage align(TextAnchor anchor) {
this.align = anchor;
return this;
}

/**
* Enables a sound effect. Use with typewriter mode!
*/
Expand Down Expand Up @@ -394,6 +529,30 @@ public ImmersiveMessage slideRight(float duration) {
return this;
}

public ImmersiveMessage slideOutUp() { return slideOutUp(1f); }
public ImmersiveMessage slideOutUp(float duration) {
animation.transition(Binding.yPos, animation.duration - duration, animation.duration, yLevel, yLevel - 50f, EasingType.EaseOutCubic);
return this;
}

public ImmersiveMessage slideOutDown() { return slideOutDown(1f); }
public ImmersiveMessage slideOutDown(float duration) {
animation.transition(Binding.yPos, animation.duration - duration, animation.duration, yLevel, yLevel + 50f, EasingType.EaseOutCubic);
return this;
}

public ImmersiveMessage slideOutLeft() { return slideOutLeft(1f); }
public ImmersiveMessage slideOutLeft(float duration) {
animation.transition(Binding.xPos, animation.duration - duration, animation.duration, xLevel, xLevel - 50f, EasingType.EaseOutCubic);
return this;
}

public ImmersiveMessage slideOutRight() { return slideOutRight(1f); }
public ImmersiveMessage slideOutRight(float duration) {
animation.transition(Binding.xPos, animation.duration - duration, animation.duration, xLevel, xLevel + 50f, EasingType.EaseOutCubic);
return this;
}

/**
* Sets a custom font. Please note that non-vanilla fonts will attempt to use Caxton rendering, which
* you will need installed to work properly!
Expand Down
Loading

0 comments on commit cfe977f

Please sign in to comment.