Skip to content

Commit

Permalink
Add EntityTag.step_height property (#2454)
Browse files Browse the repository at this point in the history
  • Loading branch information
tal5 committed Apr 3, 2023
1 parent 7a9f210 commit 49590a9
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 0 deletions.
Expand Up @@ -445,4 +445,12 @@ public void setTrackingRange(Entity entity, int range) {
public void setUUID(Entity entity, UUID id) {
throw new UnsupportedOperationException();
}

public float getStepHeight(Entity entity) {
throw new UnsupportedOperationException();
}

public void setStepHeight(Entity entity, float stepHeight) {
throw new UnsupportedOperationException();
}
}
Expand Up @@ -115,6 +115,9 @@ public static void registerMainProperties() {
PropertyParser.registerProperty(EntitySize.class, EntityTag.class);
PropertyParser.registerProperty(EntitySpeed.class, EntityTag.class);
PropertyParser.registerProperty(EntitySpell.class, EntityTag.class);
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_19)) {
PropertyParser.registerProperty(EntityStepHeight.class, EntityTag.class);
}
PropertyParser.registerProperty(EntityStrength.class, EntityTag.class);
PropertyParser.registerProperty(EntityTame.class, EntityTag.class);
PropertyParser.registerProperty(EntityEyeTargetLocation.class, EntityTag.class);
Expand Down
@@ -0,0 +1,56 @@
package com.denizenscript.denizen.objects.properties.entity;

import com.denizenscript.denizen.nms.NMSHandler;
import com.denizenscript.denizencore.objects.core.ElementTag;
import com.denizenscript.denizencore.objects.properties.PropertyParser;

public class EntityStepHeight extends EntityProperty {

@Override
public ElementTag getPropertyValue() {
return new ElementTag(NMSHandler.entityHelper.getStepHeight(getEntity()));
}

@Override
public String getPropertyId() {
return "step_height";
}

public static void register() {

// <--[tag]
// @attribute <EntityTag.step_height>
// @returns ElementTag(Decimal)
// @mechanism EntityTag.step_height
// @group properties
// @description
// Returns the entity's step height, which controls how many blocks can it walk over.
// As this is based on an internal value, it has some edge-cases, for example:
// - most (but not all) living entities can still step over 1 block tall things as usual, even if this is set to 0.
// - this doesn't apply to vehicles when the player is controlling them.
// Note that this also applies to things like getting pushed.
// -->
PropertyParser.registerTag(EntityStepHeight.class, ElementTag.class, "step_height", (attribute, prop) -> {
return prop.getPropertyValue();
});

// <--[mechanism]
// @object EntityTag
// @name step_height
// @input ElementTag(Decimal)
// @description
// Sets the entity's step height, which controls how many blocks can it walk over.
// As this is based on an internal value, it has some edge-cases, for example:
// - most (but not all) living entities can still step over 1 block tall things as usual, even if this is set to 0.
// - this doesn't apply to vehicles when the player is controlling them.
// Note that this also applies to things like getting pushed.
// @tags
// <EntityTag.step_height>
// -->
PropertyParser.registerMechanism(EntityStepHeight.class, ElementTag.class, "step_height", (prop, mechanism, input) -> {
if (mechanism.requireFloat()) {
NMSHandler.entityHelper.setStepHeight(prop.getEntity(), input.asFloat());
}
});
}
}
Expand Up @@ -831,4 +831,14 @@ public void setUUID(Entity entity, UUID id) {
Debug.echoError(ex);
}
}

@Override
public float getStepHeight(Entity entity) {
return ((CraftEntity) entity).getHandle().maxUpStep();
}

@Override
public void setStepHeight(Entity entity, float stepHeight) {
((CraftEntity) entity).getHandle().setMaxUpStep(stepHeight);
}
}

0 comments on commit 49590a9

Please sign in to comment.