-
Notifications
You must be signed in to change notification settings - Fork 5
Music Display #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
HyperRaccoon13
wants to merge
3
commits into
ethanicusss:master
Choose a base branch
from
HyperRaccoon13:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Music Display #24
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
412 changes: 253 additions & 159 deletions
412
src/main/java/com/github/ethanicuss/astraladditions/items/PylonItem.java
Large diffs are not rendered by default.
Oops, something went wrong.
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
34 changes: 34 additions & 0 deletions
34
src/main/java/com/github/ethanicuss/astraladditions/mixin/NowPlayingSoundMixin.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| package com.github.ethanicuss.astraladditions.mixin; | ||
|
|
||
| import com.github.ethanicuss.astraladditions.musicplayer.MusicPlayer; | ||
| import net.minecraft.client.sound.Sound; | ||
| import net.minecraft.client.sound.SoundInstance; | ||
| import net.minecraft.client.sound.SoundSystem; | ||
| import net.minecraft.client.sound.WeightedSoundSet; | ||
| import net.minecraft.sound.SoundCategory; | ||
| import net.minecraft.util.Identifier; | ||
| 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.LocalCapture; | ||
|
|
||
| @Mixin(SoundSystem.class) | ||
| public class NowPlayingSoundMixin { | ||
| @Inject(method = "play(Lnet/minecraft/client/sound/SoundInstance;)V", | ||
| at = @At(value = "INVOKE", target = "Lnet/minecraft/client/sound/Sound;getIdentifier()Lnet/minecraft/util/Identifier;"), | ||
| locals = LocalCapture.CAPTURE_FAILHARD | ||
| ) | ||
|
|
||
| private void onPlay(SoundInstance instance, CallbackInfo ci, | ||
| WeightedSoundSet weightedSoundSet, Identifier soundEventId, | ||
| Sound sound, float volume, float pitch, SoundCategory category, | ||
| float x, float y, SoundInstance.AttenuationType attenuationType, | ||
| boolean looping | ||
| ) { | ||
| if (instance.getCategory() != SoundCategory.MUSIC) return; | ||
|
|
||
| Identifier chosen = sound.getIdentifier(); | ||
| MusicPlayer.onTrackStarted(chosen); | ||
| } | ||
| } |
20 changes: 20 additions & 0 deletions
20
...ava/com/github/ethanicuss/astraladditions/mixin/knockback/AttackKnockbackCompatMixin.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package com.github.ethanicuss.astraladditions.mixin.knockback; | ||
|
|
||
| import net.minecraft.entity.attribute.EntityAttribute; | ||
| import net.minecraft.entity.attribute.EntityAttributes; | ||
| import net.minecraft.entity.player.PlayerEntity; | ||
| import org.spongepowered.asm.mixin.Mixin; | ||
| import org.spongepowered.asm.mixin.injection.At; | ||
| import org.spongepowered.asm.mixin.injection.Redirect; | ||
|
|
||
| @Mixin(PlayerEntity.class) | ||
| public class AttackKnockbackCompatMixin { | ||
|
|
||
| @Redirect(method = "attack(Lnet/minecraft/entity/Entity;)V", | ||
| at = @At(value = "FIELD", | ||
| target = "Lnet/minecraft/entity/attribute/EntityAttributes;ATTACK_KNOCKBACK:Lnet/minecraft/entity/attribute/EntityAttribute;") | ||
| ) | ||
| private EntityAttribute redirectAttackKnockbackAttribute() { | ||
| return EntityAttributes.GENERIC_ATTACK_KNOCKBACK; | ||
| } | ||
| } |
21 changes: 21 additions & 0 deletions
21
.../com/github/ethanicuss/astraladditions/mixin/knockback/MobAttackKnockbackCompatMixin.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| package com.github.ethanicuss.astraladditions.mixin.knockback; | ||
|
|
||
| import net.minecraft.entity.attribute.EntityAttribute; | ||
| import net.minecraft.entity.attribute.EntityAttributes; | ||
| import net.minecraft.entity.mob.MobEntity; | ||
| import org.spongepowered.asm.mixin.Mixin; | ||
| import org.spongepowered.asm.mixin.injection.At; | ||
| import org.spongepowered.asm.mixin.injection.Redirect; | ||
|
|
||
| @Mixin(MobEntity.class) | ||
| public class MobAttackKnockbackCompatMixin { | ||
|
|
||
| @Redirect(method = "tryAttack(Lnet/minecraft/entity/Entity;)Z", | ||
| at = @At(value = "FIELD", | ||
| target = "Lnet/minecraft/entity/attribute/EntityAttributes;ATTACK_KNOCKBACK:Lnet/minecraft/entity/attribute/EntityAttribute;"), | ||
| require = 0 | ||
| ) | ||
| private EntityAttribute redirectAttackKnockbackAttribute() { | ||
| return EntityAttributes.GENERIC_ATTACK_KNOCKBACK; | ||
| } | ||
| } |
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
63 changes: 63 additions & 0 deletions
63
src/main/java/com/github/ethanicuss/astraladditions/musicplayer/NowPlayingHud.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| package com.github.ethanicuss.astraladditions.musicplayer; | ||
|
|
||
| import net.minecraft.client.MinecraftClient; | ||
| import net.minecraft.client.font.TextRenderer; | ||
| import net.minecraft.client.gui.DrawableHelper; | ||
| import net.minecraft.client.util.math.MatrixStack; | ||
| import net.minecraft.text.Text; | ||
|
|
||
| public class NowPlayingHud { | ||
|
|
||
| private static final int showTick = 20*4; | ||
| private static final int fadeTick = 20; | ||
|
|
||
| private static Text title = Text.of(""); | ||
| private static Text artist = Text.of(""); | ||
| private static int ticksLeft = 0; | ||
|
|
||
| private NowPlayingHud() {} | ||
|
|
||
| public static void show(Text titleText, Text artistText) { | ||
| title = titleText; | ||
| artist = artistText; | ||
| ticksLeft = showTick + fadeTick * 2; | ||
| } | ||
|
|
||
| public static void tick() { | ||
| if (ticksLeft > 0) ticksLeft--; | ||
| } | ||
|
|
||
| public static void render(MatrixStack matrices) { | ||
| if (ticksLeft <= 0) return; | ||
|
|
||
| MinecraftClient client = MinecraftClient.getInstance(); | ||
| if (client.options.hudHidden) return; | ||
|
|
||
| float alpha = 1.0f; | ||
| if (ticksLeft > showTick + fadeTick) { | ||
| //fading out | ||
| int tick = (showTick + fadeTick * 2) - ticksLeft; | ||
| alpha = Math.min(1.0f, tick / (float) fadeTick); | ||
| } else if (ticksLeft < fadeTick) { | ||
| //fading out | ||
| alpha = ticksLeft / (float) fadeTick; | ||
| } | ||
|
|
||
| int a = ((int)(alpha * 255.0f) & 0xFF) << 24; | ||
|
|
||
| Text line1 = title; | ||
| Text line2 = artist; | ||
|
|
||
| TextRenderer textRenderer = client.textRenderer; | ||
| int x = 10; | ||
| int y = 10; | ||
|
|
||
| int w = Math.max(textRenderer.getWidth(line1), textRenderer.getWidth(line2)); | ||
| int h = textRenderer.fontHeight * 2 + 6; | ||
|
|
||
| DrawableHelper.fill(matrices, x - 4, y - 4, x + w + 4, y + h, a | 0x101010); | ||
|
|
||
| textRenderer.drawWithShadow(matrices, line1, x, y, a | 0xFFFFFF); | ||
| textRenderer.drawWithShadow(matrices, line2, x, y + textRenderer.fontHeight + 2, a | 0xB0B0B0); | ||
| } | ||
| } |
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
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
praise: this is beautiful