diff --git a/src/integrationtest/java/org/cyclops/integrateddynamics/core/evaluate/variable/integration/TestItemStackOperators.java b/src/integrationtest/java/org/cyclops/integrateddynamics/core/evaluate/variable/integration/TestItemStackOperators.java index c4dc49c1351..ff8f6f557a9 100644 --- a/src/integrationtest/java/org/cyclops/integrateddynamics/core/evaluate/variable/integration/TestItemStackOperators.java +++ b/src/integrationtest/java/org/cyclops/integrateddynamics/core/evaluate/variable/integration/TestItemStackOperators.java @@ -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}); } } diff --git a/src/main/java/org/cyclops/integrateddynamics/core/evaluate/OperatorBuilders.java b/src/main/java/org/cyclops/integrateddynamics/core/evaluate/OperatorBuilders.java index 51c7857f550..a5715cde80e 100644 --- a/src/main/java/org/cyclops/integrateddynamics/core/evaluate/OperatorBuilders.java +++ b/src/main/java/org/cyclops/integrateddynamics/core/evaluate/OperatorBuilders.java @@ -172,6 +172,7 @@ public class OperatorBuilders { public static final OperatorBuilder ENTITY = OperatorBuilder.forType(ValueTypes.OBJECT_ENTITY).appendKind("entity"); public static final OperatorBuilder ENTITY_1_SUFFIX = ENTITY.inputTypes(1, ValueTypes.OBJECT_ENTITY).renderPattern(IConfigRenderPattern.SUFFIX_1); public static final OperatorBuilder ENTITY_1_SUFFIX_LONG = ENTITY.inputTypes(1, ValueTypes.OBJECT_ENTITY).renderPattern(IConfigRenderPattern.SUFFIX_1_LONG); + public static final OperatorBuilder ENTITY_1_ITEMSTACK_1 = ENTITY.inputTypes(new IValueType[]{ValueTypes.OBJECT_ENTITY, ValueTypes.OBJECT_ITEMSTACK}).renderPattern(IConfigRenderPattern.INFIX_LONG); public static final IterativeFunction.PrePostBuilder FUNCTION_ENTITY = IterativeFunction.PrePostBuilder.begin() .appendPre(input -> { ValueObjectTypeEntity.ValueEntity a = input.getValue(0, ValueTypes.OBJECT_ENTITY); diff --git a/src/main/java/org/cyclops/integrateddynamics/core/evaluate/operator/Operators.java b/src/main/java/org/cyclops/integrateddynamics/core/evaluate/operator/Operators.java index 542461accac..24ea262cf68 100644 --- a/src/main/java/org/cyclops/integrateddynamics/core/evaluate/operator/Operators.java +++ b/src/main/java/org/cyclops/integrateddynamics/core/evaluate/operator/Operators.java @@ -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 ----------------------------------- diff --git a/src/main/resources/assets/integrateddynamics/lang/en_us.json b/src/main/resources/assets/integrateddynamics/lang/en_us.json index fb55801e51e..026ce8e78fb 100644 --- a/src/main/resources/assets/integrateddynamics/lang/en_us.json +++ b/src/main/resources/assets/integrateddynamics/lang/en_us.json @@ -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", @@ -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",