mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-12 16:27:47 +00:00
Re-introduce an attribute for entity step height in a non-breaking way (#8607)
This commit is contained in:
1 parent
e7a8da4d0b
commit
abc3353375
10 files changed
+125
-3
No files matched your search
@@ -93,6 +93,7 @@ public class ForgeMod
|
||||
public static final RegistryObject<Attribute> ENTITY_GRAVITY = ATTRIBUTES.register("entity_gravity", () -> new RangedAttribute("forge.entity_gravity", 0.08D, -8.0D, 8.0D).setSyncable(true));
|
||||
|
||||
public static final RegistryObject<Attribute> REACH_DISTANCE = ATTRIBUTES.register("reach_distance", () -> new RangedAttribute("generic.reachDistance", 5.0D, 0.0D, 1024.0D).setSyncable(true));
|
||||
public static final RegistryObject<Attribute> STEP_HEIGHT_ADDITION = ATTRIBUTES.register("step_height_addition", () -> new RangedAttribute("forge.stepHeight", 0.0D, -512.0D, 512.0D).setSyncable(true));
|
||||
|
||||
private static boolean enableMilkFluid = false;
|
||||
public static final RegistryObject<Fluid> MILK = RegistryObject.create(new ResourceLocation("milk"), ForgeRegistries.FLUIDS);
|
||||
|
||||
@@ -9,6 +9,7 @@ import java.util.Collection;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.ai.attributes.AttributeInstance;
|
||||
import net.minecraft.world.entity.boss.enderdragon.EnderDragon;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
@@ -191,4 +192,24 @@ public interface IForgeEntity extends ICapabilitySerializable<CompoundTag>
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Return the height in blocks the Entity can step up without needing to jump
|
||||
* This is the sum of vanilla's {@link Entity#maxUpStep} field and the current value
|
||||
* of the {@link net.minecraftforge.common.ForgeMod#STEP_HEIGHT_ADDITION} attribute
|
||||
* (if this Entity is a {@link LivingEntity} and has the attribute), clamped at 0.
|
||||
*/
|
||||
default float getStepHeight()
|
||||
{
|
||||
float vanillaStep = self().maxUpStep;
|
||||
if (self() instanceof LivingEntity living)
|
||||
{
|
||||
AttributeInstance stepHeightAttribute = living.getAttribute(ForgeMod.STEP_HEIGHT_ADDITION.get());
|
||||
if (stepHeightAttribute != null)
|
||||
{
|
||||
return (float) Math.max(0, vanillaStep + stepHeightAttribute.getValue());
|
||||
}
|
||||
}
|
||||
return vanillaStep;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user