AbstractDonkeyEntityMixin.java 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package monkey.lumpy.horse.stats.vanilla.mixin;
  2. import com.ibm.icu.math.BigDecimal;
  3. import com.ibm.icu.text.DecimalFormat;
  4. import org.spongepowered.asm.mixin.Mixin;
  5. import org.spongepowered.asm.mixin.injection.Inject;
  6. import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
  7. import me.shedaniel.autoconfig.AutoConfig;
  8. import monkey.lumpy.horse.stats.vanilla.config.ModConfig;
  9. import monkey.lumpy.horse.stats.vanilla.gui.ToolTipGui;
  10. import monkey.lumpy.horse.stats.vanilla.gui.Tooltip;
  11. import monkey.lumpy.horse.stats.vanilla.util.Converter;
  12. import org.spongepowered.asm.mixin.injection.At;
  13. import net.minecraft.client.MinecraftClient;
  14. import net.minecraft.entity.EntityType;
  15. import net.minecraft.entity.attribute.EntityAttributes;
  16. import net.minecraft.entity.passive.AbstractDonkeyEntity;
  17. import net.minecraft.entity.passive.HorseBaseEntity;
  18. import net.minecraft.entity.player.PlayerEntity;
  19. import net.minecraft.util.ActionResult;
  20. import net.minecraft.util.Hand;
  21. import net.minecraft.world.World;
  22. @Mixin(AbstractDonkeyEntity.class)
  23. public class AbstractDonkeyEntityMixin extends HorseBaseEntity {
  24. private ModConfig config;
  25. protected AbstractDonkeyEntityMixin(EntityType<? extends HorseBaseEntity> entityType, World world) {
  26. super(entityType, world);
  27. }
  28. @Inject(at = @At("HEAD"), method = "interactMob")
  29. public ActionResult interactMob(PlayerEntity player, Hand hand, CallbackInfoReturnable<ActionResult> ret) {
  30. if(config == null) {
  31. config = AutoConfig.getConfigHolder(ModConfig.class).getConfig();
  32. }
  33. if (this.world.isClient && !this.isTame() && player.shouldCancelInteraction() && (config == null || config.isTooltipEnabled())) {
  34. // Show tooltip
  35. DecimalFormat df = new DecimalFormat("#.#");
  36. String jumpstrength = df.format( Converter.jumpStrengthToJumpHeight(this.getJumpStrength()) );
  37. String maxHealth = df.format(this.getMaxHealth());
  38. String speed = df.format(Converter.genericSpeedToBlocPerSec(this.getAttributes().getValue(EntityAttributes.GENERIC_MOVEMENT_SPEED)));
  39. double jumpValue = new BigDecimal(jumpstrength.replace(',', '.')).doubleValue();
  40. double speedValue = new BigDecimal(speed.replace(',', '.')).doubleValue();
  41. double healthValue = new BigDecimal(maxHealth.replace(',', '.')).doubleValue();
  42. MinecraftClient.getInstance().openScreen(
  43. new ToolTipGui(new Tooltip(speedValue, jumpValue, healthValue))
  44. );
  45. }
  46. return ret.getReturnValue();
  47. }
  48. }