Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
desht committed Nov 7, 2024
2 parents 4e3e715 + e777df6 commit 36b5e9e
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,22 +114,22 @@ public static void displayCompletionToast(long id) {
}
}

public static void displayItemRewardToast(ItemStack stack, int count) {
public static void displayItemRewardToast(ItemStack stack, int count, boolean disableBlur) {
ItemStack stack1 = ItemStackHooks.copyWithCount(stack, 1);
Icon icon = ItemIcon.getItemIcon(stack1);

if (!IRewardListenerScreen.add(new RewardKey(stack.getHoverName().getString(), icon, stack1), count)) {
if (!IRewardListenerScreen.add(new RewardKey(stack.getHoverName().getString(), icon, stack1, disableBlur), count)) {
MutableComponent comp = count > 1 ?
Component.literal(count + "x ").append(stack.getHoverName()) :
stack.getHoverName().copy();
Minecraft.getInstance().getToasts().addToast(new RewardToast(comp.withStyle(stack.getRarity().color()), icon));
}
}

public static void displayRewardToast(long id, Component text, Icon icon) {
public static void displayRewardToast(long id, Component text, Icon icon, boolean disableBlur) {
Icon i = icon.isEmpty() ? ClientQuestFile.INSTANCE.getBase(id).getIcon() : icon;

if (!IRewardListenerScreen.add(new RewardKey(text.getString(), i), 1)) {
if (!IRewardListenerScreen.add(new RewardKey(text.getString(), i, disableBlur), 1)) {
Minecraft.getInstance().getToasts().addToast(new RewardToast(text, i));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@ public class RewardKey {
private final String title;
private final Icon icon;
private final ItemStack stack;
private final boolean disableBlur;

public RewardKey(String title, Icon icon) {
this(title, icon, ItemStack.EMPTY);
public RewardKey(String title, Icon icon, boolean disableBlur) {
this(title, icon, ItemStack.EMPTY, disableBlur);
}

public RewardKey(String title, Icon icon, ItemStack stack) {
public RewardKey(String title, Icon icon, ItemStack stack, boolean disableBlur) {
this.title = title;
this.icon = icon;
this.stack = stack;
this.disableBlur = disableBlur;
}

public String getTitle() {
Expand All @@ -28,6 +30,10 @@ public Icon getIcon() {
return icon;
}

public boolean disableBlur() {
return disableBlur;
}

public int hashCode() {
return stack.isEmpty() ? Objects.hash(title, icon) : ItemStack.hashItemAndComponents(stack);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ public void addWidgets() {
for (RewardKey key : keys) {
add(new RewardNotification(this, key));
}

boolean renderBlur = keys.stream().anyMatch(RewardKey::disableBlur);
RewardNotificationsScreen.this.setRenderBlur(!renderBlur);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
import net.minecraft.world.item.ItemStack;

public record DisplayItemRewardToastMessage(ItemStack stack, int count) implements CustomPacketPayload {
public record DisplayItemRewardToastMessage(ItemStack stack, int count, boolean disableBlur) implements CustomPacketPayload {
public static final Type<DisplayItemRewardToastMessage> TYPE = new Type<>(FTBQuestsAPI.rl("display_item_reward_toast_message"));

public static final StreamCodec<RegistryFriendlyByteBuf, DisplayItemRewardToastMessage> STREAM_CODEC = StreamCodec.composite(
ItemStack.OPTIONAL_STREAM_CODEC, DisplayItemRewardToastMessage::stack,
ByteBufCodecs.VAR_INT, DisplayItemRewardToastMessage::count,
ByteBufCodecs.BOOL, DisplayItemRewardToastMessage::disableBlur,
DisplayItemRewardToastMessage::new
);

Expand All @@ -24,6 +25,6 @@ public Type<DisplayItemRewardToastMessage> type() {
}

public static void handle(DisplayItemRewardToastMessage message, NetworkManager.PacketContext context) {
context.queue(() -> FTBQuestsNetClient.displayItemRewardToast(message.stack, message.count));
context.queue(() -> FTBQuestsNetClient.displayItemRewardToast(message.stack, message.count, message.disableBlur));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;

public record DisplayRewardToastMessage(long id, Component text, Icon icon) implements CustomPacketPayload {
public record DisplayRewardToastMessage(long id, Component text, Icon icon, boolean disableBlur) implements CustomPacketPayload {
public static final Type<DisplayRewardToastMessage> TYPE = new Type<>(FTBQuestsAPI.rl("display_reward_toast_message"));

public static final StreamCodec<RegistryFriendlyByteBuf, DisplayRewardToastMessage> STREAM_CODEC = StreamCodec.composite(
ByteBufCodecs.VAR_LONG, DisplayRewardToastMessage::id,
ComponentSerialization.STREAM_CODEC, DisplayRewardToastMessage::text,
Icon.STREAM_CODEC, DisplayRewardToastMessage::icon,
ByteBufCodecs.BOOL, DisplayRewardToastMessage::disableBlur,
DisplayRewardToastMessage::new
);

Expand All @@ -27,6 +28,6 @@ public Type<DisplayRewardToastMessage> type() {
}

public static void handle(DisplayRewardToastMessage message, NetworkManager.PacketContext context) {
context.queue(() -> FTBQuestsNetClient.displayRewardToast(message.id, message.text, message.icon));
context.queue(() -> FTBQuestsNetClient.displayRewardToast(message.id, message.text, message.icon, message.disableBlur));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public void claim(ServerPlayer player, boolean notify) {

if (notify) {
String key = feedbackMessage.isEmpty() ? "ftbquests.reward.ftbquests.command.success" : feedbackMessage;
NetworkManager.sendToPlayer(player, new DisplayRewardToastMessage(id, Component.translatable(key), REWARD_ICON));
NetworkManager.sendToPlayer(player, new DisplayRewardToastMessage(id, Component.translatable(key), REWARD_ICON, disableRewardScreenBlur));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public void claim(ServerPlayer player, boolean notify) {
}

if (notify) {
NetworkManager.sendToPlayer(player, new DisplayItemRewardToastMessage(item, size));
NetworkManager.sendToPlayer(player, new DisplayItemRewardToastMessage(item, size, disableRewardScreenBlur));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public abstract class Reward extends QuestObjectBase {
protected RewardAutoClaim autoclaim;
private boolean excludeFromClaimAll;
private boolean ignoreRewardBlocking;
protected boolean disableRewardScreenBlur;

public Reward(long id, Quest q) {
super(id);
Expand All @@ -47,6 +48,7 @@ public Reward(long id, Quest q) {
autoclaim = RewardAutoClaim.DEFAULT;
excludeFromClaimAll = getType().getExcludeFromListRewards();
ignoreRewardBlocking = false;
disableRewardScreenBlur = false;
}

public Quest getQuest() {
Expand Down Expand Up @@ -90,6 +92,7 @@ public void writeData(CompoundTag nbt, HolderLookup.Provider provider) {

if (excludeFromClaimAll) nbt.putBoolean("exclude_from_claim_all", true);
if (ignoreRewardBlocking) nbt.putBoolean("ignore_reward_blocking", true);
if (disableRewardScreenBlur) nbt.putBoolean("disable_reward_screen_blur", true);
}

@Override
Expand All @@ -99,6 +102,7 @@ public void readData(CompoundTag nbt, HolderLookup.Provider provider) {
autoclaim = RewardAutoClaim.NAME_MAP.get(nbt.getString("auto"));
excludeFromClaimAll = nbt.getBoolean("exclude_from_claim_all");
ignoreRewardBlocking = nbt.getBoolean("ignore_reward_blocking");
disableRewardScreenBlur = nbt.getBoolean("disable_reward_screen_blur");
}

@Override
Expand All @@ -108,6 +112,7 @@ public void writeNetData(RegistryFriendlyByteBuf buffer) {
RewardAutoClaim.NAME_MAP.write(buffer, autoclaim);
buffer.writeBoolean(excludeFromClaimAll);
buffer.writeBoolean(ignoreRewardBlocking);
buffer.writeBoolean(disableRewardScreenBlur);
}

@Override
Expand All @@ -117,6 +122,7 @@ public void readNetData(RegistryFriendlyByteBuf buffer) {
autoclaim = RewardAutoClaim.NAME_MAP.read(buffer);
excludeFromClaimAll = buffer.readBoolean();
ignoreRewardBlocking = buffer.readBoolean();
disableRewardScreenBlur = buffer.readBoolean();
}

@Override
Expand All @@ -133,6 +139,8 @@ public void fillConfigGroup(ConfigGroup config) {
config.addBool("ignore_reward_blocking", ignoreRewardBlocking(), v -> ignoreRewardBlocking = v, ignoreRewardBlocking)
.setNameKey("ftbquests.quest.misc.ignore_reward_blocking")
.setCanEdit(!isIgnoreRewardBlockingHardcoded());
config.addBool("disable_reward_screen_blur", disableRewardScreenBlur, v -> disableRewardScreenBlur = v, false)
.setNameKey("ftbquests.reward.disable_reward_screen_blur");
}

public abstract void claim(ServerPlayer player, boolean notify);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void claim(ServerPlayer player, boolean notify) {
if (notify) {
Component text = Component.translatable("ftbquests.reward.ftbquests.xp_levels").append(": ")
.append(Component.literal("+" + xpLevels).withStyle(ChatFormatting.GREEN));
NetworkManager.sendToPlayer(player, new DisplayRewardToastMessage(id, text, Color4I.empty()));
NetworkManager.sendToPlayer(player, new DisplayRewardToastMessage(id, text, Color4I.empty(), disableRewardScreenBlur));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void claim(ServerPlayer player, boolean notify) {
if (notify) {
Component text = Component.translatable("ftbquests.reward.ftbquests.xp").append(": ")
.append(Component.literal("+" + xp).withStyle(ChatFormatting.GREEN));
NetworkManager.sendToPlayer(player, new DisplayRewardToastMessage(id, text, Color4I.empty()));
NetworkManager.sendToPlayer(player, new DisplayRewardToastMessage(id, text, Color4I.empty(), disableRewardScreenBlur));
}
}

Expand Down
1 change: 1 addition & 0 deletions common/src/main/resources/assets/ftbquests/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,7 @@
"ftbquests.reward.ftbquests.npc_mail.items": "Items",
"ftbquests.reward.ftbquests.npc_mail.time_past": "Time Past",
"ftbquests.reward_table": "Reward Table",
"ftbquests.reward.disable_reward_screen_blur": "Disable Reward Screen Blur",
"ftbquests.reward_table.hide_tooltip": "Hide Tooltip",
"ftbquests.reward_table.use_title": "Use Title",
"ftbquests.reward_table.edit": "Edit Reward Table",
Expand Down

0 comments on commit 36b5e9e

Please sign in to comment.