Skip to content

Commit

Permalink
Added Entity.ItemTooltip operator and changes based on comments
Browse files Browse the repository at this point in the history
  • Loading branch information
pippinsmith committed Dec 30, 2024
1 parent f950649 commit 74b2dbc
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1260,28 +1260,28 @@ public void testInvalidInputTypeHasNbt() throws EvaluationException {
*/

@IntegrationTest
public void testItemStackTooltipLines() throws EvaluationException {
IValue res1 = Operators.OBJECT_ITEMSTACK_TOOLTIP_LINES.evaluate(new IVariable[]{iPickaxe});
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(tooltiplines(pickaxe)) = 5");
TestHelpers.assertEqual(((ValueTypeList.ValueList) res1).getRawValue().getLength(), 5, "size(tooltip(pickaxe)) = 5");

IValue res2 = Operators.OBJECT_ITEMSTACK_TOOLTIP_LINES.evaluate(new IVariable[]{iApple});
TestHelpers.assertEqual(((ValueTypeList.ValueList) res2).getRawValue().getLength(), 1, "size(tooltiplines(apple)) = 1");
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 testInvalidInputSizeTooltipLinesLarge() throws EvaluationException {
Operators.OBJECT_ITEMSTACK_TOOLTIP_LINES.evaluate(new IVariable[]{iPickaxe, iPickaxe});
public void testInvalidInputSizeTooltipLarge() throws EvaluationException {
Operators.OBJECT_ITEMSTACK_TOOLTIP.evaluate(new IVariable[]{iPickaxe, iPickaxe});
}

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

@IntegrationTest(expected = EvaluationException.class)
public void testInvalidInputTypeTooltipLines() throws EvaluationException {
Operators.OBJECT_ITEMSTACK_TOOLTIP_LINES.evaluate(new IVariable[]{DUMMY_VARIABLE});
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 @@ -1968,17 +1968,35 @@ public IValue evaluate(OperatorBase.SafeVariablesGetter variables) throws Evalua
)).build());

/**
* Get the tooltip lines of an itemstack.
* Get the tooltip of an itemstack in list form.
*/
public static final IOperator OBJECT_ITEMSTACK_TOOLTIP_LINES = REGISTRY.register(OperatorBuilders.ITEMSTACK_1_SUFFIX_LONG
.output(ValueTypes.LIST).symbol("tooltip_lines").operatorName("tooltiplines").interactName("tooltipLines")
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(Minecraft.getInstance().player, TooltipFlag.Default.NORMAL).stream()
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.itemTooltip").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
7 changes: 5 additions & 2 deletions src/main/resources/assets/integrateddynamics/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -1232,8 +1232,6 @@
"operator.integrateddynamics.itemstack.nbt.info": "Get the NBT tag of the given item.",
"operator.integrateddynamics.itemstack.hasnbt": "Has NBT",
"operator.integrateddynamics.itemstack.hasnbt.info": "If the item stack has an NBT tag.",
"operator.integrateddynamics.itemstack.tooltiplines": "Tooltip Lines",
"operator.integrateddynamics.itemstack.tooltiplines.info": "Get the tooltip of the given item in a list of strings.",

"operator.integrateddynamics.entity": "Entity",
"operator.integrateddynamics.entity.basename": "Entity %s",
Expand Down Expand Up @@ -1314,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

0 comments on commit 74b2dbc

Please sign in to comment.