Skip to content

Commit

Permalink
A little reorg for docs integration
Browse files Browse the repository at this point in the history
Also added a couple more examples for patchouli entity filter page
  • Loading branch information
desht committed Oct 20, 2024
1 parent 346e5a1 commit bc97af6
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@
import static me.desht.pneumaticcraft.common.util.PneumaticCraftUtils.xlate;

public interface IDocsProvider {
void showWidgetDocs(String path);
default void showWidgetDocs(String path) {
showDocsPage("programming/" + path);
}

void showDocsPage(String path);

default void addTooltip(List<Component> tooltip, boolean showingAll) {
tooltip.add(xlate(showingAll ? "pneumaticcraft.gui.programmer.pressIForInfoTrayOpen" : "pneumaticcraft.gui.programmer.pressIForInfo"));
Expand All @@ -37,7 +41,7 @@ default boolean isInstalled() {

class NoDocsProvider implements IDocsProvider {
@Override
public void showWidgetDocs(String path) {
public void showDocsPage(String path) {
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ public void clientInit() {
}

@Override
public void showWidgetDocs(String path) {
public void showDocsPage(String path) {
Screen prev = Minecraft.getInstance().screen; // should be the programmer GUI
if (PatchouliAccess.openBookEntry(RL("programming/" + path))) {
if (PatchouliAccess.openBookEntry(RL(path))) {
bookGui = Minecraft.getInstance().screen;
prevGui = prev;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package me.desht.pneumaticcraft.common.util.entityfilter;

import me.desht.pneumaticcraft.common.util.PneumaticCraftUtils;
import net.minecraft.ResourceLocationException;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceLocation;
Expand All @@ -14,6 +15,7 @@
import net.minecraft.world.entity.animal.Cat;
import net.minecraft.world.entity.animal.Sheep;
import net.minecraft.world.entity.animal.Wolf;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.scores.PlayerTeam;
Expand Down Expand Up @@ -138,11 +140,20 @@ private static boolean hasColor(Entity entity, String val) {

private static boolean isHeldItem(Entity entity, String name, boolean mainHand) {
if (entity instanceof LivingEntity l) {
if (!name.contains(":")) {
name = "minecraft:" + name;
if (name.startsWith("#")) {
try {
TagKey<Item> tag = TagKey.create(Registries.ITEM, ResourceLocation.parse(name.substring(1)));
return mainHand ? l.getMainHandItem().is(tag) : l.getOffhandItem().is(tag);
} catch (ResourceLocationException ignored) {
return false;
}
} else {
if (!name.contains(":")) {
name = "minecraft:" + name;
}
ItemStack stack = mainHand ? l.getMainHandItem() : l.getOffhandItem();
return PneumaticCraftUtils.getRegistryName(stack.getItem()).orElseThrow().toString().equals(name);
}
ItemStack stack = mainHand ? l.getMainHandItem() : l.getOffhandItem();
return PneumaticCraftUtils.getRegistryName(stack.getItem()).orElseThrow().toString().equals(name);
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
{
"type": "text",
"title": "Examples",
"text": "$(li)$(#800)@player/$ matches all players$(li)$(#800)@mob/$ matches all aggressive creatures$(li)$(#800)@animal/$ matches all passive creatures (animals)$(li)$(#800)@animal(age = adult)/$ matches all adult animals$(li)$(#800)@animal(age = baby)/$ matches all baby animals$(li)$(#800)@animal(breedable = yes)/$ matches all animals that can breed right now$(li)$(#800)sheep(shearable = yes)/$ matches all sheep which can be sheared"
"text": "$(li)$(#800)@player/$ matches all players$(li)$(#800)@mob/$ matches all aggressive creatures$(li)$(#800)@animal/$ matches all passive creatures (animals)$(li)$(#800)@animal(age=adult)/$ matches all adult animals$(li)$(#800)@animal(age=baby)/$ matches all baby animals$(li)$(#800)@animal(breedable=yes)/$ matches all animals that can breed right now$(li)$(#800)sheep(shearable=yes)/$ matches all sheep which can be sheared"
},
{
"type": "text",
"title": "Examples (cont.)",
"text": "$(li)$(#800)sheep(shearable = yes,color = black)/$ matches all black sheep which can be sheared$(li)$(#800)wolf(color = blue)/$ matches all wolves/dogs with a blue collar. $(li)$(#800)cat(color = white)/$ matches all cats with a white collar.$(li)$(#800)@minecart/$ matches Minecarts$(li)$(#800)@boat/$ matches Boats$(li)$(#800)@living/$ matches all living entities$(li)$(#800)@item/$ matches item entities$(li)$(#800)@orb/$ matches experience orbs"
"text": "$(li)$(#800)sheep(shearable=yes,color=black)/$ matches all black sheep which can be sheared$(li)$(#800)wolf(color=blue)/$ matches all wolves/dogs with a blue collar. $(li)$(#800)cat(color=white)/$ matches all cats with a white collar.$(li)$(#800)@minecart/$ matches Minecarts$(li)$(#800)@boat/$ matches Boats$(li)$(#800)@living/$ matches all living entities$(li)$(#800)@item/$ matches item entities$(li)$(#800)@orb/$ matches experience orbs"
},
{
"type": "text",
Expand All @@ -28,7 +28,7 @@
},
{
"type": "text",
"text": "$(li)$(#800)@player(team=team1)/$ matches players on vanilla scoreboard team \"team1\""
"text": "$(li)$(#800)@player(team=team1)/$ matches players on vanilla scoreboard team \"team1\"$(li)$(#800)@player(holding=stick)/$ matches players who are holding a stick right now$(li)$(#800)@player(holding=#minecraft:planks)/$ matches players holding any item in the $(thing)minecraft:planks/$ item tag"
},
{
"type": "text",
Expand Down

0 comments on commit bc97af6

Please sign in to comment.