Created
September 4, 2022 15:28
-
-
Save Daomephsta/71917657feaa7f6428fd2671707df6b0 to your computer and use it in GitHub Desktop.
Mixin for traits
This file contains hidden or 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
@Mixin({FallingBlockDestroyerItem.class, FallingBlockStabiliserItem.class}) | |
public abstract class ChargeBarTrait extends Item implements IPolarisedItem | |
{ | |
// Make the compiler happy | |
// Ignored by Mixin | |
public ChargeBarTrait(Settings settings) | |
{ | |
super(settings); | |
} | |
@Override | |
@Overwrite // Error if another trait overrides the same method | |
public boolean isItemBarVisible(ItemStack stack) | |
{ | |
return true; | |
} | |
@Override | |
@Overwrite // Error if another trait overrides the same method | |
public int getItemBarStep(ItemStack stack) | |
{ | |
IPolarChargeStorage chargeable = PolarApi.CHARGE_STORAGE.get(stack); | |
// storedCharge units of 1 / damageBarWidth / maxCharge and rounded | |
return Math.round(chargeable.getStoredCharge() * 13.0F / chargeable.getMaxCharge()); | |
} | |
@Override | |
@Overwrite // Error if another trait overrides the same method | |
public int getItemBarColor(ItemStack stack) | |
{ | |
return switch (getPolarity(stack)) | |
{ | |
case RED -> MathHelper.packRgb(227, 66, 52); | |
case BLUE -> MathHelper.packRgb(0, 128, 255); | |
default -> super.getItemBarColor(stack); | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment