Skip to content

Commit

Permalink
feat: indicate if signs have wax applied or not (#336)
Browse files Browse the repository at this point in the history
  • Loading branch information
Snownee committed Dec 8, 2023
1 parent f0e3b65 commit 9a8bd37
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 41 deletions.
3 changes: 3 additions & 0 deletions src/main/java/snownee/jade/addon/vanilla/VanillaPlugin.java
Expand Up @@ -38,6 +38,7 @@
import net.minecraft.world.level.block.JukeboxBlock;
import net.minecraft.world.level.block.LecternBlock;
import net.minecraft.world.level.block.NoteBlock;
import net.minecraft.world.level.block.SignBlock;
import net.minecraft.world.level.block.SpawnerBlock;
import net.minecraft.world.level.block.TntBlock;
import net.minecraft.world.level.block.entity.AbstractFurnaceBlockEntity;
Expand Down Expand Up @@ -181,6 +182,7 @@ public void registerClient(IWailaClientRegistration registration) {
registration.registerEntityIcon(ItemDisplayProvider.INSTANCE, ItemDisplay.class);
registration.registerEntityIcon(BlockDisplayProvider.INSTANCE, BlockDisplay.class);
registration.registerEntityComponent(ZombieVillagerProvider.INSTANCE, ZombieVillager.class);
registration.registerBlockIcon(WaxedProvider.INSTANCE, SignBlock.class);

registration.registerItemStorageClient(CampfireProvider.INSTANCE);

Expand Down Expand Up @@ -216,6 +218,7 @@ public void registerClient(IWailaClientRegistration registration) {
registration.markAsClientFeature(Identifiers.MC_ENTITY_ARMOR);
registration.markAsClientFeature(Identifiers.MC_CROP_PROGRESS);
registration.markAsClientFeature(Identifiers.MC_MOB_SPAWNER);
registration.markAsClientFeature(Identifiers.MC_WAXED);

registration.usePickedResult(EntityType.BOAT);
registration.usePickedResult(EntityType.CHEST_BOAT);
Expand Down
47 changes: 47 additions & 0 deletions src/main/java/snownee/jade/addon/vanilla/WaxedProvider.java
@@ -0,0 +1,47 @@
package snownee.jade.addon.vanilla;

import org.jetbrains.annotations.Nullable;

import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.block.entity.SignBlockEntity;
import snownee.jade.api.BlockAccessor;
import snownee.jade.api.IBlockComponentProvider;
import snownee.jade.api.ITooltip;
import snownee.jade.api.Identifiers;
import snownee.jade.api.config.IPluginConfig;
import snownee.jade.api.ui.IElement;
import snownee.jade.api.ui.IElementHelper;
import snownee.jade.impl.ui.CompoundElement;

public enum WaxedProvider implements IBlockComponentProvider {

INSTANCE;

@Override
public @Nullable IElement getIcon(BlockAccessor accessor, IPluginConfig config, IElement currentIcon) {
if (accessor.getPickedResult().isEmpty()) {
return currentIcon;
}
IElementHelper helper = IElementHelper.get();
IElement largeIcon = helper.item(accessor.getPickedResult());
if (accessor.getBlockEntity() instanceof SignBlockEntity sign) {
if (sign.isWaxed()) {
return new CompoundElement(largeIcon, helper.item(Items.HONEYCOMB.getDefaultInstance(), 0.5f));
} else {
return largeIcon;
}
}
return currentIcon;
}

@Override
public void appendTooltip(ITooltip tooltip, BlockAccessor accessor, IPluginConfig config) {

}

@Override
public ResourceLocation getUid() {
return Identifiers.MC_WAXED;
}
}
1 change: 1 addition & 0 deletions src/main/java/snownee/jade/api/Identifiers.java
Expand Up @@ -69,6 +69,7 @@ public class Identifiers {
public static final ResourceLocation MC_TNT_STABILITY = MC("tnt_stability");
public static final ResourceLocation MC_TOTAL_ENCHANTMENT_POWER = MC("total_enchantment_power");
public static final ResourceLocation MC_VILLAGER_PROFESSION = MC("villager_profession");
public static final ResourceLocation MC_WAXED = MC("waxed");
public static final ResourceLocation MC_ITEM_DISPLAY = MC("item_display");
public static final ResourceLocation MC_BLOCK_DISPLAY = MC("block_display");
public static final ResourceLocation MC_BREAKING_PROGRESS = MC("breaking_progress");
Expand Down
56 changes: 15 additions & 41 deletions src/main/java/snownee/jade/impl/ui/CompoundElement.java
@@ -1,60 +1,34 @@
package snownee.jade.impl.ui;

import org.jetbrains.annotations.Nullable;

import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.util.Mth;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.phys.Vec2;
import snownee.jade.api.ui.Element;
import snownee.jade.overlay.DisplayHelper;

public class ItemStackElement extends Element {

private final ItemStack stack;
private final float scale;
private final String text;
public static final ItemStackElement EMPTY = new ItemStackElement(ItemStack.EMPTY, 1, null);

private ItemStackElement(ItemStack stack, float scale, @Nullable String text) {
this.stack = stack;
this.scale = scale == 0 ? 1 : scale;
this.text = text;
}
import snownee.jade.api.ui.IElement;

public static ItemStackElement of(ItemStack stack) {
return of(stack, 1);
}
public class CompoundElement extends Element {

public static ItemStackElement of(ItemStack stack, float scale) {
return of(stack, scale, null);
}
protected final IElement large;
protected final IElement small;

public static ItemStackElement of(ItemStack stack, float scale, @Nullable String text) {
if (scale == 1 && stack.isEmpty()) {
return EMPTY;
}
return new ItemStackElement(stack, scale, text);
public CompoundElement(IElement large, IElement small) {
this.large = large;
this.small = small;
}

@Override
public Vec2 getSize() {
int size = Mth.floor(18 * scale);
return new Vec2(size, size);
return large.getSize();
}

@Override
public void render(GuiGraphics guiGraphics, float x, float y, float maxX, float maxY) {
if (stack.isEmpty())
return;
DisplayHelper.INSTANCE.drawItem(guiGraphics, x + 1, y + 1, stack, scale, text);
}

@Override
public @Nullable String getMessage() {
if (stack.isEmpty())
return null;
return "%s %s".formatted(stack.getCount(), stack.getHoverName().getString());
Vec2 largeSize = large.getCachedSize();
Vec2 smallSize = small.getCachedSize();
large.render(guiGraphics, x, y, maxX, maxY);
guiGraphics.pose().pushPose();
guiGraphics.pose().translate(0, 0, 100);
small.render(guiGraphics, x + largeSize.x - smallSize.x, y + largeSize.y - smallSize.y, maxX, maxY);
guiGraphics.pose().popPose();
}

}
2 changes: 2 additions & 0 deletions src/main/resources/assets/jade/lang/en_us.json
Expand Up @@ -264,6 +264,8 @@
"config.jade.plugin_minecraft.chiseled_bookshelf": "Chiseled Bookshelf",
"config.jade.plugin_minecraft.zombie_villager": "Zombie Villager Conversion",
"jade.zombieConversion.time": "Conversion time: %s",
"config.jade.plugin_minecraft.waxed": "Waxed State",
"config.jade.plugin_minecraft.waxed_desc": "Show the waxed state of the block, such as waxed sign.",
"toast.jade.toggle_hint.1": "Jade is now closed",
"toast.jade.toggle_hint.2": "Press %s again to reopen",
"toast.jade.tts_hint.1": "Jade's narrator is now open",
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/assets/jade/lang/zh_cn.json
Expand Up @@ -263,6 +263,8 @@
"config.jade.plugin_minecraft.chiseled_bookshelf": "雕纹书架",
"config.jade.plugin_minecraft.zombie_villager": "僵尸村民转化时间",
"jade.zombieConversion.time": "转化时间:%s",
"config.jade.plugin_minecraft.waxed": "上蜡状态",
"config.jade.plugin_minecraft.waxed_desc": "显示某些方块是否已打蜡,如告示牌。",
"toast.jade.toggle_hint.1": "Jade已关闭",
"toast.jade.toggle_hint.2": "按下%s重新打开",
"toast.jade.tts_hint.1": "Jade语音复述已开启",
Expand Down

0 comments on commit 9a8bd37

Please sign in to comment.