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
Scale Attack Range with Pehkui's entity scale #49
Comments
Hello! |
That's strange -- usually something like this should just make it an optional dependency as opposed to a mandatory one. I'll ask around and see if there's any way to just make it the former. |
Just to clarify: On the other hand I am open for communicating with that mod via Minecraft's Vanilla API. If there is a scale EntityAttribute Pehkui introduces, I could use the value of that. However their developer documentation contains no information in this regard. |
Since you mentioned using attributes, instead of using Pehkui directly it would probably be better if you were to make use of Reach-Entity-Attributes, which Pehkui has compat code for to adjust the attribute values based on one's scale. Would also improve compat with other Fabric mods that adjust attack and block reach. |
Hi! I think the correct solution is for Better Combat to obtain the scale (float value) of the player, so the OBB used for weapon collision could be scaled with it. What do you think, what would be a good way to obtain this? |
I would not consider the following as a good way in the slightest, but, a way to obtain a scale without a dependency would be something equivalent to this terrible chunk of reflection: Show/Hide Reflectionprivate static final Method GET_SCALE_DATA;
private static final Method GET_SCALE;
private static final Map<Identifier, Object> SCALE_TYPES;
static
{
Method getScaleDataMethod = null;
Method getScaleMethod = null;
Map<Identifier, Object> scaleTypes = null;
if (FabricLoader.getInstance().isModLoaded("pehkui"))
{
try
{
Class<?> scaleTypeClass = Class.forName("virtuoel.pehkui.api.ScaleType");
Class<?> scaleDataClass = Class.forName("virtuoel.pehkui.api.ScaleData");
Class<?> scaleRegistriesClass = Class.forName("virtuoel.pehkui.api.ScaleRegistries");
Field scaleTypesField = scaleRegistriesClass.getField("SCALE_TYPES");
getScaleDataMethod = scaleTypeClass.getMethod("getScaleData", Entity.class);
getScaleMethod = scaleDataClass.getMethod("getScale", float.class);
scaleTypes = (Map<Identifier, Object>) scaleTypesField.get(null);
}
catch (ClassNotFoundException | NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException | NoSuchMethodException e)
{
getScaleDataMethod = null;
getScaleMethod = null;
scaleTypes = null;
}
}
GET_SCALE_DATA = getScaleDataMethod;
GET_SCALE = getScaleMethod;
SCALE_TYPES = scaleTypes;
}
public static float getScale(Entity entity, Identifier scaleId)
{
return getScale(entity, scaleId, 1.0F);
}
public static float getScale(Entity entity, Identifier scaleId, float tickDelta)
{
if (GET_SCALE_DATA != null && GET_SCALE != null && SCALE_TYPES != null)
{
try
{
return (float) GET_SCALE.invoke(GET_SCALE_DATA.invoke(SCALE_TYPES.get(scaleId), entity), tickDelta);
}
catch (SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e)
{
return 1.0F;
}
}
return 1.0F;
} |
Thanks for all this code. Yes this looks rather suboptimal. That way any mod could add compatibility easily. |
Unfortunately attributes are limited to living entities, while scales are applicable to every entity, living or otherwise. |
Just a thought that popped up in my head, not exactly sure if it counts for your goal of not needing a dependency in mind, but something you could theoretically do, should that code not work out right, is release an extension mod for Better Combat that uses Pehkui scales. An example would be here with Create Support for Open Parties and Claims; a mod separate from 'Open Parties and Claims' that uses Create as a dependency so that the main mod doesn't need Create as a dependency. |
I've run it in both dev and prod, and since the strings passed to the reflection don't reference vanilla classes, only Pehkui ones, it does work outside the dev enviroment, yes. |
What would be the |
It'd be |
I created a Pekhui integration branch, using the reflection based solution. Unfortunately I am getting the following crash:
I am really not sure if reflection based solution can be stable in the long term. Is there no way to provide the scale values via any Vanilla API? |
Looks like the crash is because you misspelt pehkui as pekhui in the Identifier. Also since Pehkui has a Forge version you don't need to keep the compat Fabric-specific. |
Wow big mistake from my part, sorry! |
Just an idea for something long down the road, but, I figured this is probably one of the easier ways to add compatibility between Better Combat and Pehkui.
So, if Pehkui doubles your "block reach" by 2, your attack range likewise multiplies by 2 -- and vise versa.
The reason why I mention "block reach" specifically is because it's usually calculated when growing or shrinking players' base height.
Assuming this wouldn't be a total pain in the arse to program, that is. Thanks for reading.
The text was updated successfully, but these errors were encountered: