Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: indicate if signs have wax applied or not (#336)
- Loading branch information
Showing
6 changed files
with
70 additions
and
41 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
47 changes: 47 additions & 0 deletions
47
src/main/java/snownee/jade/addon/vanilla/WaxedProvider.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,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; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
|
||
} |
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