Skip to content
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

Added TooltipLines operator #1450

Merged
merged 4 commits into from
Dec 31, 2024
Merged
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
Expand Up @@ -1255,4 +1255,33 @@ public void testInvalidInputTypeHasNbt() throws EvaluationException {
Operators.OBJECT_ITEMSTACK_HASNBT.evaluate(new IVariable[]{DUMMY_VARIABLE});
}

/**
* ----------------------------------- TOOLTIPLINES -----------------------------------
*/

@IntegrationTest
public void testItemStackTooltip() throws EvaluationException {
IValue res1 = Operators.OBJECT_ITEMSTACK_TOOLTIP.evaluate(new IVariable[]{iPickaxe});
Asserts.check(res1 instanceof ValueTypeList.ValueList, "result is a list");
TestHelpers.assertEqual(((ValueTypeList.ValueList) res1).getRawValue().getLength(), 5, "size(tooltip(pickaxe)) = 5");

IValue res2 = Operators.OBJECT_ITEMSTACK_TOOLTIP.evaluate(new IVariable[]{iApple});
TestHelpers.assertEqual(((ValueTypeList.ValueList) res2).getRawValue().getLength(), 1, "size(tooltip(apple)) = 1");
}

@IntegrationTest(expected = EvaluationException.class)
public void testInvalidInputSizeTooltipLarge() throws EvaluationException {
Operators.OBJECT_ITEMSTACK_TOOLTIP.evaluate(new IVariable[]{iPickaxe, iPickaxe});
}

@IntegrationTest(expected = EvaluationException.class)
public void testInvalidInputSizeTooltipSmall() throws EvaluationException {
Operators.OBJECT_ITEMSTACK_TOOLTIP.evaluate(new IVariable[]{});
}

@IntegrationTest(expected = EvaluationException.class)
public void testInvalidInputTypeTooltip() throws EvaluationException {
Operators.OBJECT_ITEMSTACK_TOOLTIP.evaluate(new IVariable[]{DUMMY_VARIABLE});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ public class OperatorBuilders {
public static final OperatorBuilder<OperatorBase.SafeVariablesGetter> ENTITY = OperatorBuilder.forType(ValueTypes.OBJECT_ENTITY).appendKind("entity");
public static final OperatorBuilder<OperatorBase.SafeVariablesGetter> ENTITY_1_SUFFIX = ENTITY.inputTypes(1, ValueTypes.OBJECT_ENTITY).renderPattern(IConfigRenderPattern.SUFFIX_1);
public static final OperatorBuilder<OperatorBase.SafeVariablesGetter> ENTITY_1_SUFFIX_LONG = ENTITY.inputTypes(1, ValueTypes.OBJECT_ENTITY).renderPattern(IConfigRenderPattern.SUFFIX_1_LONG);
public static final OperatorBuilder<OperatorBase.SafeVariablesGetter> ENTITY_1_ITEMSTACK_1 = ENTITY.inputTypes(new IValueType[]{ValueTypes.OBJECT_ENTITY, ValueTypes.OBJECT_ITEMSTACK}).renderPattern(IConfigRenderPattern.INFIX_LONG);
public static final IterativeFunction.PrePostBuilder<Entity, IValue> FUNCTION_ENTITY = IterativeFunction.PrePostBuilder.begin()
.appendPre(input -> {
ValueObjectTypeEntity.ValueEntity a = input.getValue(0, ValueTypes.OBJECT_ENTITY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.level.ClipContext;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.SoundType;
Expand Down Expand Up @@ -1965,6 +1966,37 @@ public IValue evaluate(OperatorBase.SafeVariablesGetter variables) throws Evalua
itemStack -> !itemStack.isEmpty() && itemStack.hasTag()
)).build());

/**
* Get the tooltip of an itemstack in list form.
*/
public static final IOperator OBJECT_ITEMSTACK_TOOLTIP = REGISTRY.register(OperatorBuilders.ITEMSTACK_1_SUFFIX_LONG
.output(ValueTypes.LIST).symbol("tooltip").operatorName("tooltip").interactName("tooltip")
.function(input -> {
ValueObjectTypeItemStack.ValueItemStack itemStack = input.getValue(0, ValueTypes.OBJECT_ITEMSTACK);
return ValueTypeList.ValueList.ofList(ValueTypes.STRING,
itemStack.getRawValue().getTooltipLines(null, TooltipFlag.Default.NORMAL).stream()
.map(c -> ValueTypeString.ValueString.of(c.getString()))
.toList());
}).build());
/**
* Get the tooltip of an itemstack in list form, using the provided player entity as the player context.
*/
public static final IOperator OBJECT_ITEMSTACK_ENTITY_TOOLTIP = REGISTRY.register(OperatorBuilders.ENTITY_1_ITEMSTACK_1
.inputTypes(ValueTypes.OBJECT_ENTITY, ValueTypes.OBJECT_ITEMSTACK)
.output(ValueTypes.LIST).symbol("entity_item_tooltip").operatorName("entityitemtooltip").interactName("entityItemTooltip")
.function(variables -> {
ValueObjectTypeEntity.ValueEntity a = variables.getValue(0, ValueTypes.OBJECT_ENTITY);
ValueObjectTypeItemStack.ValueItemStack itemStack = variables.getValue(1, ValueTypes.OBJECT_ITEMSTACK);
if(a.getRawValue().isPresent() && a.getRawValue().get() instanceof Player) {
Player entity = (Player) a.getRawValue().get();
return ValueTypeList.ValueList.ofList(ValueTypes.STRING,
itemStack.getRawValue().getTooltipLines(entity, TooltipFlag.Default.NORMAL).stream()
.map(c -> ValueTypeString.ValueString.of(c.getString()))
.toList());
}
return ValueTypes.LIST.getDefault();
}).build());

/**
* ----------------------------------- ENTITY OBJECT OPERATORS -----------------------------------
*/
Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/assets/integrateddynamics/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -1312,6 +1312,11 @@
"operator.integrateddynamics.entity.entityenergycapacity": "Entity Energy Capacity",
"operator.integrateddynamics.entity.entityenergycapacity.info": "The energy capacity of this entity.",

"operator.integrateddynamics.entity.entityitemtooltip": "Entity Tooltip",
"operator.integrateddynamics.entity.entityitemtooltip.info": "In the context of the given Player Entity, get the tooltip of the given item as a list of strings.",
"operator.integrateddynamics.itemstack.tooltip": "Tooltip",
"operator.integrateddynamics.itemstack.tooltip.info": "Get the tooltip of the given item as a list of strings.",

"operator.integrateddynamics.itemstack.isfecontainer": "Is FE Container",
"operator.integrateddynamics.itemstack.isfecontainer.info": "If the given item can hold FE",
"operator.integrateddynamics.itemstack.storedfe": "FE Stored",
Expand Down
Loading