Skip to content

pattern overlays #879

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package at.petrak.hexcasting.interop.inline;

import at.petrak.hexcasting.api.casting.math.HexPattern;
import at.petrak.hexcasting.api.utils.NBTHelper;
import at.petrak.hexcasting.client.render.PatternColors;
import at.petrak.hexcasting.client.render.PatternRenderer;
import at.petrak.hexcasting.client.render.PatternSettings;
import at.petrak.hexcasting.client.render.RenderLib;
import at.petrak.hexcasting.common.items.storage.ItemScroll;
import at.petrak.hexcasting.common.items.storage.ItemSlate;
import com.samsthenerd.inline.api.client.extrahooks.ItemOverlayRenderer;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.world.item.ItemStack;

import java.util.function.Function;

public record HexPatternOverlayRenderer(Function<ItemStack, HexPattern> patternRetriever) implements ItemOverlayRenderer {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: why is this a record holding a FI and not just a FI itself? i.e.

@FunctionalInterface
public interface HexPatternOverlayRenderer extends ItemOverlayRenderer {
  HexPattern getPattern(ItemStack stack);
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't remember, prob just didn't think of it. Want me to change it ?


public static final HexPatternOverlayRenderer SCROLL_RENDERER = new HexPatternOverlayRenderer((stack) -> {
var compound = NBTHelper.getCompound(stack, ItemScroll.TAG_PATTERN);
if (compound != null && !NBTHelper.getBoolean(stack, ItemScroll.TAG_NEEDS_PURCHASE)) {
return HexPattern.fromNBT(compound);

}
return null;
});

public static final HexPatternOverlayRenderer SLATE_RENDERER = new HexPatternOverlayRenderer(
(stack) -> ItemSlate.getPattern(stack).orElse(null));

public static final PatternSettings OVERLAY_RENDER_SETTINGS = new PatternSettings("overlay",
new PatternSettings.PositionSettings(14, 14, 0.5, 0.5,
PatternSettings.AxisAlignment.CENTER_FIT, PatternSettings.AxisAlignment.CENTER_FIT, 4.0, 0, 0),
PatternSettings.StrokeSettings.fromStroke(1.5),
new PatternSettings.ZappySettings(10, 0, 0, 0,
PatternSettings.ZappySettings.READABLE_OFFSET, 0.7f)
);

// higher contrast purple based on slate wobble color
public static final PatternColors HC_PURPLE_COLOR =
new PatternColors(RenderLib.screenCol(0xff_cfa0f3), 0xff_763fa1);

@Override
public void render(ItemStack itemStack, GuiGraphics guiGraphics) {
if(!Screen.hasShiftDown()) return;
HexPattern pat = patternRetriever().apply(itemStack);
if(pat == null) return;
var ps = guiGraphics.pose();
ps.pushPose();
ps.translate(1,1,100);
PatternRenderer.renderPattern(pat, guiGraphics.pose(), OVERLAY_RENDER_SETTINGS, HC_PURPLE_COLOR, 0, 16);
ps.popPose();
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
package at.petrak.hexcasting.interop.inline;

import at.petrak.hexcasting.common.lib.HexItems;
import com.samsthenerd.inline.api.client.InlineClientAPI;
import com.samsthenerd.inline.api.client.extrahooks.ItemOverlayRenderer;

public class InlineHexClient {

public static void init(){
InlineClientAPI.INSTANCE.addMatcher(HexPatternMatcher.INSTANCE);
InlineClientAPI.INSTANCE.addRenderer(InlinePatternRenderer.INSTANCE);

ItemOverlayRenderer.registerRenderer(HexItems.SCROLL_LARGE, HexPatternOverlayRenderer.SCROLL_RENDERER);
ItemOverlayRenderer.registerRenderer(HexItems.SCROLL_MEDIUM, HexPatternOverlayRenderer.SCROLL_RENDERER);
ItemOverlayRenderer.registerRenderer(HexItems.SCROLL_SMOL, HexPatternOverlayRenderer.SCROLL_RENDERER);
ItemOverlayRenderer.registerRenderer(HexItems.SLATE, HexPatternOverlayRenderer.SLATE_RENDERER);
}
}
2 changes: 1 addition & 1 deletion Fabric/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"paucal": ">=0.6.0-pre <0.7.0",
"cloth-config": "11.1.*",
"patchouli": ">=1.20.1-80",
"inline": ">=1.20.1-1.0.1"
"inline": ">=1.20.1-1.1.1"
},
"suggests": {
"pehkui": ">=3.7.6",
Expand Down
2 changes: 1 addition & 1 deletion Forge/src/main/resources/META-INF/mods.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ side = "BOTH"
[[dependencies.hexcasting]]
modId = "inline"
mandatory = true
versionRange = "[1.20.1-1.0.1,)"
versionRange = "[1.20.1-1.1.1,)"
ordering = "NONE"
side = "BOTH"
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ patchouliVersion=83
jeiVersion=15.0.0.12
pehkuiVersion=3.7.7

inlineVersion=1.0.1
inlineVersion=1.1.1
clothConfigVersion=11.1.106
Loading