HorseScreenMixin.java 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package net.horse.stats.vanilla.mixin;
  2. import java.text.DecimalFormat;
  3. import org.spongepowered.asm.mixin.Mixin;
  4. import org.spongepowered.asm.mixin.injection.At;
  5. import org.spongepowered.asm.mixin.injection.Inject;
  6. import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
  7. import net.minecraft.client.gui.screen.ingame.AbstractContainerScreen;
  8. import net.minecraft.client.gui.screen.ingame.HorseScreen;
  9. import net.minecraft.container.HorseContainer;
  10. import net.minecraft.entity.attribute.EntityAttributes;
  11. import net.minecraft.entity.passive.AbstractDonkeyEntity;
  12. import net.minecraft.entity.passive.HorseBaseEntity;
  13. import net.minecraft.entity.passive.LlamaEntity;
  14. import net.minecraft.entity.player.PlayerInventory;
  15. @Mixin(HorseScreen.class)
  16. public abstract class HorseScreenMixin extends AbstractContainerScreen<HorseContainer> {
  17. public HorseScreenMixin(HorseContainer container_1, PlayerInventory playerInventory_1, HorseBaseEntity horseBaseEntity_1) {
  18. super(container_1, playerInventory_1, horseBaseEntity_1.getDisplayName());
  19. }
  20. HorseBaseEntity horseBaseEntity;
  21. @Inject(method = "<init>*", at = @At("RETURN"))
  22. private void onConstructed(HorseContainer horseContainer_1, PlayerInventory playerInventory_1, HorseBaseEntity horseBaseEntity_1, CallbackInfo ci) {
  23. horseBaseEntity = horseBaseEntity_1;
  24. }
  25. @Inject(method = "drawForeground", at = @At("RETURN"))
  26. private void onDrawForeground(int int_1, int int_2, CallbackInfo ci) {
  27. boolean hasChest = false;
  28. if(AbstractDonkeyEntity.class.isAssignableFrom(horseBaseEntity.getClass())) {
  29. if(((AbstractDonkeyEntity) horseBaseEntity).hasChest()) {
  30. hasChest = true;
  31. }
  32. }
  33. DecimalFormat df = new DecimalFormat("#.#");
  34. String jumpstrength = df.format(horseBaseEntity.getJumpStrength() * 10);
  35. String maxHealth = df.format(horseBaseEntity.getMaximumHealth());
  36. String speed = df.format(horseBaseEntity.getAttributes().get(EntityAttributes.MOVEMENT_SPEED).getValue() * 100);
  37. if(!hasChest) {
  38. this.font.draw("➟ ", 89.0F, 26.0F, 4210752);
  39. this.font.draw("" + speed, 100.0F, 26.0F, 4210752);
  40. this.font.draw("⇮", 91.0F, 36.0F, 4210752);
  41. this.font.draw("" + jumpstrength, 100.0F, 36.0F, 4210752);
  42. this.font.draw("♥", 90.0F, 46.0F, 4210752);
  43. this.font.draw("" + maxHealth, 100.0F, 46.0F, 4210752);
  44. } else {
  45. this.font.draw("➟ " + speed, 80.0F, 6.0F, 4210752);
  46. this.font.draw("⇮ " + jumpstrength, 115.0F, 6.0F, 4210752);
  47. this.font.draw("♥ " + maxHealth, 140.0F, 6.0F, 4210752);
  48. }
  49. if(LlamaEntity.class.isAssignableFrom(horseBaseEntity.getClass())) {
  50. int strength = 3 * ((LlamaEntity)horseBaseEntity).getStrength();
  51. if(!hasChest) {
  52. this.font.draw("▦", 91.0F, 56.0F, 4210752);
  53. this.font.draw("" + strength, 100.0F, 56.0F, 4210752);
  54. }
  55. }
  56. }
  57. }