-
Notifications
You must be signed in to change notification settings - Fork 16
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
Showing
16 changed files
with
706 additions
and
1 deletion.
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
80 changes: 80 additions & 0 deletions
80
src/main/java/dev/kir/sync/easteregg/mixin/MixinEasterEggs.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,80 @@ | ||
package dev.kir.sync.easteregg.mixin; | ||
|
||
import com.google.gson.JsonObject; | ||
import com.google.gson.JsonParser; | ||
import com.google.gson.JsonPrimitive; | ||
import org.objectweb.asm.tree.ClassNode; | ||
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; | ||
import org.spongepowered.asm.mixin.extensibility.IMixinInfo; | ||
|
||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
public final class MixinEasterEggs implements IMixinConfigPlugin { | ||
@Override | ||
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) { | ||
String name = getPackageName(mixinClassName); | ||
JsonObject config = this.getConfig(); | ||
if ( | ||
config.has(name) && config.get(name) instanceof JsonObject configEntry && | ||
configEntry.has("enable") && configEntry.get("enable") instanceof JsonPrimitive enable && enable.isBoolean() | ||
) { | ||
return enable.getAsBoolean(); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
@Override | ||
public void onLoad(String mixinPackage) { } | ||
|
||
@Override | ||
public String getRefMapperConfig() { return null; } | ||
|
||
@Override | ||
public List<String> getMixins() { return null; } | ||
|
||
@Override | ||
public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) { } | ||
|
||
@Override | ||
public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { } | ||
|
||
@Override | ||
public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { } | ||
|
||
private static String getPackageName(String mixinClassName) { | ||
int mixinStartI = mixinClassName.lastIndexOf("mixin."); | ||
if (mixinStartI == -1) | ||
return mixinClassName; | ||
|
||
int endI = mixinClassName.indexOf('.', mixinStartI + 6); | ||
return mixinClassName.substring(mixinStartI + 6, endI); | ||
} | ||
|
||
private JsonObject config; | ||
private JsonObject getConfig() { | ||
if (this.config == null) { | ||
try { | ||
Path path = Path.of("./config/sync.json"); | ||
if (Files.isReadable(path)) { | ||
String json = Files.readString(path); | ||
this.config = (JsonObject)JsonParser.parseString(json); | ||
} | ||
} catch (Throwable e) { | ||
this.config = null; | ||
} | ||
|
||
if (this.config == null) { | ||
this.config = new JsonObject(); | ||
} | ||
|
||
if (this.config.has("easterEggs") && this.config.get("easterEggs") instanceof JsonObject easterEggs) { | ||
this.config = easterEggs; | ||
} | ||
} | ||
return this.config; | ||
} | ||
} |
104 changes: 104 additions & 0 deletions
104
src/main/java/dev/kir/sync/easteregg/mixin/technoblade/ClientWorldMixin.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,104 @@ | ||
package dev.kir.sync.easteregg.mixin.technoblade; | ||
|
||
import dev.kir.sync.easteregg.technoblade.Technoblade; | ||
import dev.kir.sync.easteregg.technoblade.TechnobladeTransformable; | ||
import net.fabricmc.api.EnvType; | ||
import net.fabricmc.api.Environment; | ||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.client.sound.EntityTrackingSoundInstance; | ||
import net.minecraft.client.sound.PositionedSoundInstance; | ||
import net.minecraft.client.world.ClientWorld; | ||
import net.minecraft.entity.Entity; | ||
import net.minecraft.entity.mob.MobEntity; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.sound.SoundCategory; | ||
import net.minecraft.sound.SoundEvent; | ||
import net.minecraft.util.Identifier; | ||
import net.minecraft.util.math.Box; | ||
import net.minecraft.util.profiler.Profiler; | ||
import net.minecraft.util.registry.Registry; | ||
import net.minecraft.util.registry.RegistryEntry; | ||
import net.minecraft.util.registry.RegistryKey; | ||
import net.minecraft.world.MutableWorldProperties; | ||
import net.minecraft.world.World; | ||
import net.minecraft.world.dimension.DimensionType; | ||
import org.jetbrains.annotations.Nullable; | ||
import org.spongepowered.asm.mixin.Final; | ||
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.CallbackInfo; | ||
|
||
import java.util.List; | ||
import java.util.function.Supplier; | ||
|
||
@Environment(EnvType.CLIENT) | ||
@Mixin(ClientWorld.class) | ||
abstract class ClientWorldMixin extends World { | ||
@Shadow | ||
private @Final MinecraftClient client; | ||
|
||
private ClientWorldMixin(MutableWorldProperties properties, RegistryKey<World> registryRef, RegistryEntry<DimensionType> registryEntry, Supplier<Profiler> profiler, boolean isClient, boolean debugWorld, long seed) { | ||
super(properties, registryRef, registryEntry, profiler, isClient, debugWorld, seed); | ||
} | ||
|
||
@Inject(method = "playSound(DDDLnet/minecraft/sound/SoundEvent;Lnet/minecraft/sound/SoundCategory;FFZ)V", at = @At("HEAD"), cancellable = true) | ||
private void playSound(double x, double y, double z, SoundEvent sound, SoundCategory category, float volume, float pitch, boolean useDistance, CallbackInfo ci) { | ||
if (category != SoundCategory.NEUTRAL) { | ||
return; | ||
} | ||
|
||
List<MobEntity> Technoblades = this.getEntitiesByClass(MobEntity.class, new Box(x - 0.1, y - 0.1, z - 0.1, x + 0.1, y + 0.1, z + 0.1), e -> e instanceof TechnobladeTransformable && ((TechnobladeTransformable)e).isTechnoblade()); | ||
MobEntity entity = Technoblades.size() == 0 ? null : Technoblades.get(0); | ||
if (entity == null) { | ||
return; | ||
} | ||
|
||
Technoblade Technoblade = ((TechnobladeTransformable)entity).asTechnoblade(); | ||
sound = this.getTechnobladeSound(sound); | ||
if (sound == null) { | ||
ci.cancel(); | ||
return; | ||
} | ||
|
||
double distance = this.client.gameRenderer.getCamera().getPos().squaredDistanceTo(x, y, z); | ||
PositionedSoundInstance positionedSoundInstance = new PositionedSoundInstance(sound, Technoblade.getSoundCategory(), volume, pitch, x, y, z); | ||
if (useDistance && distance > 100) { | ||
this.client.getSoundManager().play(positionedSoundInstance, (int)(Math.sqrt(distance) * 0.5)); | ||
} else { | ||
this.client.getSoundManager().play(positionedSoundInstance); | ||
} | ||
ci.cancel(); | ||
} | ||
|
||
@Inject(method = "playSoundFromEntity", at = @At("HEAD"), cancellable = true) | ||
private void playSoundFromEntity(PlayerEntity except, Entity entity, SoundEvent sound, SoundCategory category, float volume, float pitch, CallbackInfo ci) { | ||
if (except != this.client.player || !(entity instanceof TechnobladeTransformable) || !((TechnobladeTransformable)entity).isTechnoblade()) { | ||
return; | ||
} | ||
|
||
Technoblade Technoblade = ((TechnobladeTransformable)entity).asTechnoblade(); | ||
sound = this.getTechnobladeSound(sound); | ||
if (sound == null) { | ||
ci.cancel(); | ||
return; | ||
} | ||
|
||
this.client.getSoundManager().play(new EntityTrackingSoundInstance(sound, Technoblade.getSoundCategory(), volume, pitch, entity)); | ||
ci.cancel(); | ||
} | ||
|
||
private @Nullable SoundEvent getTechnobladeSound(SoundEvent sound) { | ||
Identifier originalSoundId = sound.getId(); | ||
if (originalSoundId.getPath().endsWith(".ambient") || originalSoundId.getPath().endsWith(".death")) { | ||
return null; | ||
} | ||
|
||
SoundEvent fixedSound = Registry.SOUND_EVENT.get(new Identifier(originalSoundId.getNamespace(), originalSoundId.getPath().replaceFirst("\\.[^.]+", ".player"))); | ||
if (fixedSound == null) { | ||
fixedSound = sound; | ||
} | ||
return fixedSound; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/dev/kir/sync/easteregg/mixin/technoblade/EntityRenderDispatcherMixin.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,24 @@ | ||
package dev.kir.sync.easteregg.mixin.technoblade; | ||
|
||
import dev.kir.sync.easteregg.technoblade.TechnobladeTransformable; | ||
import net.fabricmc.api.EnvType; | ||
import net.fabricmc.api.Environment; | ||
import net.minecraft.client.render.VertexConsumerProvider; | ||
import net.minecraft.client.render.entity.EntityRenderDispatcher; | ||
import net.minecraft.client.util.math.MatrixStack; | ||
import net.minecraft.entity.Entity; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.ModifyArgs; | ||
import org.spongepowered.asm.mixin.injection.invoke.arg.Args; | ||
|
||
@Environment(EnvType.CLIENT) | ||
@Mixin(EntityRenderDispatcher.class) | ||
abstract class EntityRenderDispatcherMixin { | ||
@ModifyArgs(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/entity/EntityRenderDispatcher;renderShadow(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;Lnet/minecraft/entity/Entity;FFLnet/minecraft/world/WorldView;F)V")) | ||
private void getShadowOpacity(Args args, Entity entity, double x, double y, double z, float yaw, float tickDelta, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light) { | ||
if (entity instanceof TechnobladeTransformable technobladeTransformable && technobladeTransformable.isTechnoblade()) { | ||
args.set(6, 0f); | ||
} | ||
} | ||
} |
Oops, something went wrong.
ed82e02
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.
Back XYZ: mm dd yyyy, dd mm yyyy, or yyyy mm dd