-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Tenzin Pelletier
committed
Jan 12, 2022
1 parent
a634776
commit b10bbd1
Showing
7 changed files
with
160 additions
and
39 deletions.
There are no files selected for viewing
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
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
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
22 changes: 22 additions & 0 deletions
22
src/main/java/com/t2pellet/teams/events/AdvancementEvents.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.t2pellet.teams.events; | ||
|
||
import net.fabricmc.fabric.api.event.Event; | ||
import net.fabricmc.fabric.api.event.EventFactory; | ||
import net.minecraft.advancement.Advancement; | ||
import net.minecraft.server.network.ServerPlayerEntity; | ||
|
||
public class AdvancementEvents { | ||
|
||
public static final Event<PlayerAdvancement> ADVANCEMENT_GRANTED = EventFactory.createArrayBacked(PlayerAdvancement.class, | ||
listeners -> (player, advancement) -> { | ||
for (PlayerAdvancement listener : listeners) { | ||
listener.onPlayerAdvancement(player, advancement); | ||
} | ||
}); | ||
|
||
@FunctionalInterface | ||
public interface PlayerAdvancement { | ||
void onPlayerAdvancement(ServerPlayerEntity player, Advancement advancement); | ||
} | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/com/t2pellet/teams/mixin/AdvancementAccessor.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.t2pellet.teams.mixin; | ||
|
||
import net.minecraft.advancement.Advancement; | ||
import net.minecraft.advancement.PlayerAdvancementTracker; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.gen.Accessor; | ||
|
||
import java.util.Set; | ||
|
||
@Mixin(PlayerAdvancementTracker.class) | ||
public interface AdvancementAccessor { | ||
|
||
@Accessor("visibleAdvancements") | ||
Set<Advancement> getVisibleAdvancements(); | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/com/t2pellet/teams/mixin/AdvancementMixin.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.t2pellet.teams.mixin; | ||
|
||
import com.t2pellet.teams.TeamsMod; | ||
import com.t2pellet.teams.events.AdvancementEvents; | ||
import net.minecraft.advancement.Advancement; | ||
import net.minecraft.advancement.PlayerAdvancementTracker; | ||
import net.minecraft.server.network.ServerPlayerEntity; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
||
@Mixin(PlayerAdvancementTracker.class) | ||
public class AdvancementMixin { | ||
|
||
@Shadow private ServerPlayerEntity owner; | ||
|
||
@Inject(method = "grantCriterion", at = @At(value = "INVOKE", target = "Lnet/minecraft/advancement/PlayerAdvancementTracker;updateDisplay(Lnet/minecraft/advancement/Advancement;)V")) | ||
public void advancementCompleted(Advancement advancement, String criterionName, CallbackInfoReturnable<Boolean> ci) { | ||
if (!TeamsMod.getServer().getOverworld().isClient) { | ||
AdvancementEvents.ADVANCEMENT_GRANTED.invoker().onPlayerAdvancement(owner, advancement); | ||
} | ||
} | ||
} |
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