Skip to content

Commit

Permalink
salepoint tooltip
Browse files Browse the repository at this point in the history
  • Loading branch information
techno-sam committed Aug 8, 2024
1 parent 439974f commit 9985089
Show file tree
Hide file tree
Showing 21 changed files with 369 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// 1.20.1 2024-08-07T23:05:34.25307421 Create: Numismatics/Numismatics' Advancements
// 1.20.1 2024-08-08T14:22:14.213110993 Create: Numismatics/Numismatics' Advancements
4ab84595dc44460d6d89ff3608940dd8694b93d6 data/numismatics/advancements/is_this_legal.json
645c92e6e449889ed4cf617432fd6fa87ffe355b data/numismatics/advancements/questionable_investment.json
8f32fb49ef81058e2e660fac983dbef2f554db38 data/numismatics/advancements/root.json
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// 1.20.1 2024-08-07T23:05:34.251904854 Create: Numismatics/Numismatics Standard Recipes
// 1.20.1 2024-08-08T14:22:14.210008775 Create: Numismatics/Numismatics Standard Recipes
0e1680b878cfa51c04809504b3542cb6312027a1 data/numismatics/recipes/crafting/gray_id_card.json
61954216f844eecdbee266da7e517a983993d2f8 data/numismatics/advancements/recipes/misc/crafting/brown_card.json
2c732f9c3bc02a29a4d86a0552f4dbbae986a34a data/numismatics/recipes/crafting/blue_authorized_card.json
Expand Down Expand Up @@ -62,8 +62,8 @@ b33377448ad6812c10b1405051359e58172299e9 data/numismatics/advancements/recipes/m
ea20b56eaa5e6c8af48b7b8c3c33cd15c0107bc1 data/numismatics/advancements/recipes/misc/crafting/gray_authorized_card.json
d7a7609aa109440f0f47b8ba7c598d9f7a667734 data/numismatics/advancements/recipes/misc/crafting/blue_id_card.json
4ef1874d44a47c50706505c00f866b9ecb6d860d data/numismatics/recipes/crafting/purple_authorized_card.json
cee2975b897e1c1216e301ad69dea85258902546 data/numismatics/advancements/recipes/misc/crafting/black_id_card.json
dccd117562bb9bf28890aa0aa53273b4587504ee data/numismatics/recipes/crafting/white_card.json
cee2975b897e1c1216e301ad69dea85258902546 data/numismatics/advancements/recipes/misc/crafting/black_id_card.json
6ed249679ea9168906e4e00a7c6f85f432f9cd16 data/numismatics/advancements/recipes/misc/crafting/orange_authorized_card.json
20434910bb6e5fa2e8350f52b30c728b091a85d3 data/numismatics/recipes/crafting/brown_card.json
24bb0a27737622bbc1dfce601b0030372f0b6bcf data/numismatics/recipes/crafting/black_authorized_card.json
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// 1.20.1 2024-08-07T23:05:34.248846149 Create: Numismatics/Numismatics EMI excluded tags
// 1.20.1 2024-08-08T14:22:14.204849223 Create: Numismatics/Numismatics EMI excluded tags
b57edab6f7e7a6e1b1211daa4c3b217ffd09ce62 assets/emi/tag/exclusions/numismatics.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
// 1.20.1 2024-08-07T23:05:34.252881766 Create: Numismatics/Numismatics' Sequenced Assembly Recipes
// 1.20.1 2024-08-08T14:22:14.212185451 Create: Numismatics/Numismatics' Sequenced Assembly Recipes
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// 1.20.1 2024-08-07T23:05:34.250006007 Create: Numismatics/Registrate Provider for numismatics [Recipes, Advancements, Loot Tables, Tags (blocks), Tags (items), Tags (fluids), Tags (entity_types), Blockstates, Item models, Lang (en_us/en_ud)]
// 1.20.1 2024-08-08T14:22:14.206619846 Create: Numismatics/Registrate Provider for numismatics [Recipes, Advancements, Loot Tables, Tags (blocks), Tags (items), Tags (fluids), Tags (entity_types), Blockstates, Item models, Lang (en_us/en_ud)]
2f1dad2a2e0086d54cf4b88378feacc04341d87f data/numismatics/tags/items/internal/ingots/iron_ingots.json
dc5c60bbbaf3a5d7bc1f9bc0c9377757dbd8de49 data/numismatics/loot_tables/blocks/bank_terminal.json
5b0244502972f49d063d98fa0cb3f6fc65af82b2 data/numismatics/tags/items/internal/string.json
Expand All @@ -8,7 +8,7 @@ a96d3d02794064cd9be1bca25a9ba6217675e6c5 assets/numismatics/models/item/white_id
bb2a77462e6213eddde134f3cc3e9a3f07f07f3f assets/numismatics/models/item/yellow_authorized_card.json
74a4c7ca7a48382782e5dba33018dfc8255192c5 assets/numismatics/models/block/brass_depositor_locked.json
3f0d912779200aaaf55bef102d9b96acead1a636 data/numismatics/tags/items/internal/dyes/purple_dyes.json
854b42b3b8d16001c7ba3ecf38736343281313df assets/numismatics/lang/en_us.json
7b8c264836550fb74e40d923ddc02f4be873eef5 assets/numismatics/lang/en_us.json
377e460c0dcf6d7de1b7ae235959105a7c45e4c4 assets/numismatics/models/item/cyan_authorized_card.json
bde18ccd9c21484154597c6271750c0406082f61 data/forge/tags/blocks/relocation_not_supported.json
eca751589c40725750e2c2baa6607e83255fd5f4 assets/numismatics/models/item/brown_authorized_card.json
Expand All @@ -18,7 +18,7 @@ ad712dd2a2a7268dfa773f38a50d526952758d5c data/numismatics/tags/items/internal/dy
8550097149cebbfd50bdeac2003327b60a4aee9a assets/numismatics/models/item/light_gray_card.json
95b492bd9230dc90fca9395c823cef39e644d8f2 assets/numismatics/models/item/sprocket.json
70c481f36a9718ac48632e6939ac6ba785be4c9e assets/numismatics/models/item/black_id_card.json
975cd8a9ed6f70432ae5514aac58513d47dd4bae assets/numismatics/lang/en_ud.json
b7cfcad20fb12b64f8d9a89d286888115676b99a assets/numismatics/lang/en_ud.json
1e78f650091a4a2c43e36fb815f23d0591e058a6 assets/numismatics/models/item/magenta_card.json
909f5d14f23199c064f6b91a421bb7b15e0f1a7d assets/numismatics/models/item/orange_authorized_card.json
d6f017479b3cc538f73d7fb0a1e65d1742bab266 assets/numismatics/models/item/light_blue_id_card.json
Expand Down Expand Up @@ -55,9 +55,9 @@ bde18ccd9c21484154597c6271750c0406082f61 data/c/tags/blocks/relocation_not_suppo
d048d04208faa63f0014d614d6026a66fe118c11 data/numismatics/loot_tables/blocks/brass_depositor.json
790ff3c5da6a67a5de1ceb7138fa3e1c0fe97f80 data/numismatics/tags/items/internal/dyes/lime_dyes.json
a8cb82f19034a0e724e12df45c883e9cd469c210 assets/numismatics/models/item/green_card.json
e1087e56db7b4d8812ab4617344f0ac8b0f0e6c7 assets/numismatics/models/item/light_gray_authorized_card.json
390db78c5393fca4f90018df51d1a79d11a64f72 assets/numismatics/models/item/light_blue_authorized_card.json
c09892d2d189f147997d77f4ce39b0570729f030 assets/numismatics/models/item/lime_authorized_card.json
e1087e56db7b4d8812ab4617344f0ac8b0f0e6c7 assets/numismatics/models/item/light_gray_authorized_card.json
06ecd28cd97f4e8200dc396858695cad57b871c8 assets/numismatics/blockstates/blaze_banker.json
95ef415a564eba1d212053195d25b199427b94e3 assets/numismatics/blockstates/creative_vendor.json
9fdcd12c871f136e66973a8c02be94a675a4b727 data/numismatics/tags/items/internal/dyes/yellow_dyes.json
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"gui.numismatics.salepoint.fluid_filter_empty.0": "ɹǝʇןıℲ pınןℲ",
"gui.numismatics.salepoint.fluid_filter_empty.1": "ǝןʇʇoq ɐ ɹo ʇǝʞɔnq ɐ sɐ ɥɔns ɯǝʇı buıpןoɥ-pınןɟ ɐ ɥʇıʍ ʞɔıןƆ",
"gui.numismatics.salepoint.go": "uoıʇɔɐsuɐɹʇ ʇɹɐʇS",
"gui.numismatics.salepoint.insufficient_space": "ןןnɟ sı ʇǝbɹɐ⟘",
"gui.numismatics.salepoint.insufficient_space": "pǝʇɔǝuuoɔ ʇou/ןןnɟ sı ʇǝbɹɐ⟘",
"gui.numismatics.salepoint.invalid_state": "ǝʇɐʇs pıןɐʌuI",
"gui.numismatics.salepoint.no_card": "pɹɐɔ oN",
"gui.numismatics.salepoint.no_filter": "ɹǝʇןıɟ oN",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"gui.numismatics.salepoint.fluid_filter_empty.0": "Fluid Filter",
"gui.numismatics.salepoint.fluid_filter_empty.1": "Click with a fluid-holding item such as a bucket or a bottle",
"gui.numismatics.salepoint.go": "Start transaction",
"gui.numismatics.salepoint.insufficient_space": "Target is full",
"gui.numismatics.salepoint.insufficient_space": "Target is full/not connected",
"gui.numismatics.salepoint.invalid_state": "Invalid state",
"gui.numismatics.salepoint.no_card": "No card",
"gui.numismatics.salepoint.no_filter": "No filter",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,15 @@
import com.google.common.collect.ImmutableList;
import com.simibubi.create.AllSoundEvents;
import com.simibubi.create.compat.computercraft.AbstractComputerBehaviour;
import com.simibubi.create.content.equipment.goggles.IHaveHoveringInformation;
import com.simibubi.create.foundation.blockEntity.SmartBlockEntity;
import com.simibubi.create.foundation.blockEntity.behaviour.BlockEntityBehaviour;
import com.simibubi.create.foundation.utility.Components;
import com.simibubi.create.foundation.utility.Couple;
import com.simibubi.create.foundation.utility.Lang;
import dev.ithundxr.createnumismatics.Numismatics;
import dev.ithundxr.createnumismatics.compat.computercraft.ComputerCraftProxy;
import dev.ithundxr.createnumismatics.config.NumismaticsConfig;
import dev.ithundxr.createnumismatics.content.backend.*;
import dev.ithundxr.createnumismatics.content.backend.behaviours.SliderStylePriceBehaviour;
import dev.ithundxr.createnumismatics.content.backend.trust_list.TrustListContainer;
Expand All @@ -42,14 +46,20 @@
import dev.ithundxr.createnumismatics.registry.NumismaticsPackets;
import dev.ithundxr.createnumismatics.registry.NumismaticsTags;
import dev.ithundxr.createnumismatics.registry.packets.OpenTrustListPacket;
import dev.ithundxr.createnumismatics.util.TextUtils;
import dev.ithundxr.createnumismatics.util.UsernameUtils;
import dev.ithundxr.createnumismatics.util.Utils;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.ChatFormatting;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.NbtUtils;
import net.minecraft.nbt.Tag;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.network.chat.contents.TranslatableContents;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.Container;
import net.minecraft.world.Containers;
Expand All @@ -72,7 +82,7 @@
import java.util.List;
import java.util.UUID;

public class SalepointBlockEntity extends SmartBlockEntity implements Trusted, TrustListHolder {
public class SalepointBlockEntity extends SmartBlockEntity implements Trusted, TrustListHolder, IHaveHoveringInformation {

public final Container cardContainer = new SimpleContainer(1) {
@Override
Expand Down Expand Up @@ -111,6 +121,8 @@ public void setChanged() {
int clientsideMultiplier;
int clientsideProgress;

private final List<Component> clientsideTooltip = new ArrayList<>();

AbstractComputerBehaviour computerBehaviour;

public SalepointBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockState state) {
Expand Down Expand Up @@ -204,6 +216,15 @@ protected void write(CompoundTag tag, boolean clientPacket) {
if (justCompletedMultiplier != null) {
tag.putInt("JustCompletedMultiplier", justCompletedMultiplier);
}

ListTag tooltip = new ListTag();
for (Component component : clientsideTooltip) {
String json = Component.Serializer.toJson(component);
CompoundTag compoundTag = new CompoundTag();
compoundTag.putString("Text", json);
tooltip.add(compoundTag);
}
tag.put("Tooltip", tooltip);
}
}

Expand Down Expand Up @@ -239,6 +260,14 @@ protected void read(CompoundTag tag, boolean clientPacket) {
justCompletedMultiplier = tag.contains("JustCompletedMultiplier", Tag.TAG_INT)
? tag.getInt("JustCompletedMultiplier")
: null;

clientsideTooltip.clear();
ListTag tooltip = tag.getList("Tooltip", Tag.TAG_COMPOUND);
for (Tag t : tooltip) {
CompoundTag compoundTag = (CompoundTag) t;
String json = compoundTag.getString("Text");
clientsideTooltip.add(Component.Serializer.fromJson(json));
}
}
}

Expand Down Expand Up @@ -390,6 +419,7 @@ public void lazyTick() {

justCompletedMultiplier = null;
attemptTransaction();
createTooltip();
}

void notifyDelayedDataSync() {
Expand Down Expand Up @@ -465,6 +495,77 @@ public void destroy() {
}
}

@Override
@Environment(EnvType.CLIENT)
public boolean addToTooltip(List<Component> tooltip, boolean isPlayerSneaking) {
if (getSalepointState() == null)
return false;

tooltip.addAll(clientsideTooltip);

return true;
}

private void createTooltip() {
clientsideTooltip.clear();
ISalepointState<?> state = getSalepointState();
if (state == null)
return;

ReasonHolder reasonHolder = new ReasonHolder();
if (!state.isValidForPurchase(getLevel(), getTargetedPos(), reasonHolder)) {
Lang.builder()
.add(reasonHolder.getMessageOrDefault(Components.translatable("gui.numismatics.salepoint.invalid_state")))
.style(ChatFormatting.DARK_RED)
.forGoggles(clientsideTooltip);

boolean showOwner = reasonHolder.getMessage() == null
|| !(reasonHolder.getMessage().getContents() instanceof TranslatableContents translatableContents)
|| !translatableContents.getKey().equals("gui.numismatics.salepoint.insufficient_space");

if (showOwner) {
String ownerName = UsernameUtils.INSTANCE.getName(owner, null);
if (ownerName != null) {
Lang.builder()
.add(Components.translatable("gui.numismatics.vendor.generic_named", ownerName))
.style(ChatFormatting.DARK_RED)
.forGoggles(clientsideTooltip);
}
}
}

Coin referenceCoin = NumismaticsConfig.common().referenceCoin.get();
Couple<Integer> referenceAndSpurs = referenceCoin.convert(getTotalPrice());
int reference = referenceAndSpurs.getFirst();
int spurs = referenceAndSpurs.getSecond();
MutableComponent balanceLabel = Components.translatable("gui.numismatics.salepoint.price",
TextUtils.formatInt(reference), referenceCoin.getName(reference), spurs);

state.createTooltip(clientsideTooltip, getLevel(), getTargetedPos());

clientsideTooltip.add(Components.immutableEmpty());

// For: ...

Lang.builder()
.add(balanceLabel.withStyle(Coin.closest(getTotalPrice()).rarity.color))
.forGoggles(clientsideTooltip);

for (MutableComponent component : price.getCondensedPriceBreakdown()) {
Lang.builder()
.add(component)
.forGoggles(clientsideTooltip);
}
sendData();
}

public ItemStack getDisplayItem() {
if (salepointState == null)
return ItemStack.EMPTY;

return salepointState.state().getDisplayItem();
}

private class ConfigMenuProvider implements MenuProvider {
@Override
public @NotNull Component getDisplayName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,15 @@
package dev.ithundxr.createnumismatics.content.salepoint;

import com.simibubi.create.AllSoundEvents;
import com.simibubi.create.CreateClient;
import com.simibubi.create.foundation.blockEntity.behaviour.BlockEntityBehaviour;
import com.simibubi.create.foundation.utility.Components;
import dev.ithundxr.createnumismatics.content.salepoint.behaviours.SalepointTargetBehaviour;
import dev.ithundxr.createnumismatics.content.salepoint.states.ISalepointState;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.ChatFormatting;
import net.minecraft.client.Minecraft;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtUtils;
Expand All @@ -35,7 +39,10 @@
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.shapes.VoxelShape;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class SalepointBlockItem extends BlockItem {
public SalepointBlockItem(Block block, Properties properties) {
Expand Down Expand Up @@ -139,4 +146,44 @@ public SalepointBlockItem(Block block, Properties properties) {

return super.useOn(context);
}

private static @Nullable BlockPos lastShownPos = null;
private static @Nullable AABB lastShownAABB = null;

@Environment(EnvType.CLIENT)
public static void clientTick() {
Player player = Minecraft.getInstance().player;
if (player == null)
return;
ItemStack heldItemMainhand = player.getMainHandItem();
if (!(heldItemMainhand.getItem() instanceof SalepointBlockItem))
return;
if (!heldItemMainhand.hasTag())
return;
CompoundTag stackTag = heldItemMainhand.getOrCreateTag();
if (!stackTag.contains("SelectedPos"))
return;

BlockPos selectedPos = NbtUtils.readBlockPos(stackTag.getCompound("SelectedPos"));

if (!selectedPos.equals(lastShownPos)) {
lastShownAABB = getBounds(selectedPos);
lastShownPos = selectedPos;
}

CreateClient.OUTLINER.showAABB("target", lastShownAABB)
.colored(0xffcb74)
.lineWidth(1 / 16f);
}

@Environment(EnvType.CLIENT)
private static AABB getBounds(BlockPos pos) {
Level world = Minecraft.getInstance().level;

BlockState state = world.getBlockState(pos);
VoxelShape shape = state.getShape(world, pos);
return shape.isEmpty() ? new AABB(BlockPos.ZERO)
: shape.bounds()
.move(pos);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package dev.ithundxr.createnumismatics.content.salepoint.states;

import com.simibubi.create.foundation.utility.Components;
import com.simibubi.create.foundation.utility.Lang;
import dev.architectury.injectables.annotations.ExpectPlatform;
import dev.ithundxr.createnumismatics.content.backend.ReasonHolder;
import dev.ithundxr.createnumismatics.content.salepoint.behaviours.SalepointTargetBehaviour;
Expand All @@ -29,12 +30,15 @@
import dev.ithundxr.createnumismatics.content.salepoint.types.SimpleEnergyBuffer;
import dev.ithundxr.createnumismatics.content.salepoint.widgets.SalepointEnergyConfigWidget;
import dev.ithundxr.createnumismatics.content.salepoint.widgets.SalepointEnergyDisplayWidget;
import dev.ithundxr.createnumismatics.util.TextUtils;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.ChatFormatting;
import net.minecraft.MethodsReturnNonnullByDefault;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.Tag;
import net.minecraft.network.chat.Component;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -269,4 +273,16 @@ public Map<String, Object> writeForComputerCraft() {
"filter", filter.getAmount()
);
}

@Override
public void createTooltip(List<Component> tooltip, Level level, BlockPos targetedPos) {
Lang.builder()
.add(Components.translatable("gui.numismatics.salepoint.energy"))
.forGoggles(tooltip);

Lang.builder()
.add(Components.literal(TextUtils.formatEnergy(filter.getAmount())))
.style(ChatFormatting.GREEN)
.forGoggles(tooltip);
}
}
Loading

0 comments on commit 9985089

Please sign in to comment.