Created
June 15, 2023 20:59
-
-
Save Daomephsta/b9d88c435e6b4f7723685bd73ac7b109 to your computer and use it in GitHub Desktop.
Step Height Attribute
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package io.github.daomephsta.mixin; | |
import org.spongepowered.asm.mixin.Debug; | |
import org.spongepowered.asm.mixin.Mixin; | |
import org.spongepowered.asm.mixin.gen.Accessor; | |
import org.spongepowered.asm.mixin.injection.At; | |
import org.spongepowered.asm.mixin.injection.Inject; | |
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | |
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | |
import net.minecraft.entity.Entity; | |
@Debug(export = true) | |
@Mixin(Entity.class) | |
public abstract class EntityMixin | |
{ | |
@Accessor("stepHeight") | |
protected abstract void setStepHeightDirect(float stepHeight); | |
@Inject(method = "getStepHeight", at = @At("TAIL")) | |
protected abstract void scratch_getStepHeightShim(CallbackInfoReturnable<Float> info); | |
@Inject(method = "setStepHeight", at = @At("TAIL")) | |
protected abstract void scratch_setStepHeightShim(float stepHeight, CallbackInfo info); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package io.github.daomephsta.mixin; | |
import org.spongepowered.asm.mixin.Debug; | |
import org.spongepowered.asm.mixin.Mixin; | |
import org.spongepowered.asm.mixin.Shadow; | |
import net.minecraft.entity.LivingEntity; | |
import net.minecraft.entity.attribute.EntityAttribute; | |
import net.minecraft.entity.attribute.EntityAttributeInstance; | |
@Debug(export = true) | |
@Mixin(LivingEntity.class) | |
public abstract class LivingEntityMixin extends EntityMixin | |
{ | |
@Shadow | |
public abstract double getAttributeValue(EntityAttribute attribute); | |
@Shadow | |
public abstract EntityAttributeInstance getAttributeInstance(EntityAttribute attribute); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package io.github.daomephsta.mixin; | |
import org.spongepowered.asm.mixin.Debug; | |
import org.spongepowered.asm.mixin.Mixin; | |
import org.spongepowered.asm.mixin.injection.At; | |
import org.spongepowered.asm.mixin.injection.Inject; | |
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | |
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | |
import io.github.daomephsta.api.StepHeightApi; | |
import net.minecraft.entity.attribute.DefaultAttributeContainer; | |
import net.minecraft.entity.player.PlayerEntity; | |
@Debug(export = true) | |
@Mixin(PlayerEntity.class) | |
public abstract class PlayerEntityMixin extends LivingEntityMixin | |
{ | |
@Inject(method = "createPlayerAttributes", at = @At("RETURN")) | |
private static void scratch_addStepHeightAttribute(CallbackInfoReturnable<DefaultAttributeContainer.Builder> info) | |
{ | |
info.getReturnValue().add(StepHeightApi.PLAYER_STEP_HEIGHT, 0.6); | |
} | |
@Override | |
protected void scratch_getStepHeightShim(CallbackInfoReturnable<Float> info) | |
{ | |
setStepHeightDirect((float) getAttributeValue(StepHeightApi.PLAYER_STEP_HEIGHT)); | |
} | |
@Override | |
protected void scratch_setStepHeightShim(float stepHeight, CallbackInfo info) | |
{ | |
this.getAttributeInstance(StepHeightApi.PLAYER_STEP_HEIGHT).setBaseValue(stepHeight); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package io.github.daomephsta.api; | |
import io.github.daomephsta.Scratch; | |
import net.minecraft.entity.attribute.ClampedEntityAttribute; | |
import net.minecraft.entity.attribute.EntityAttribute; | |
import net.minecraft.registry.Registries; | |
import net.minecraft.registry.Registry; | |
public class StepHeightApi | |
{ | |
public static final EntityAttribute PLAYER_STEP_HEIGHT = Registry.register(Registries.ATTRIBUTE, Scratch.id("player.step_height"), | |
new ClampedEntityAttribute("attribute.name.player.step_height", 1.0, 0.6, 1024.0)); | |
public static void initialise() | |
{ | |
// Force static init | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment