Skip to content

Commit

Permalink
Merge pull request #16 from Pixaurora/feature/minecraft-b1.7
Browse files Browse the repository at this point in the history
Add support for Minecraft Beta 1.7
  • Loading branch information
Pixaurora authored Dec 30, 2024
2 parents 6660337 + 10a4439 commit 06cba65
Show file tree
Hide file tree
Showing 54 changed files with 1,179 additions and 13 deletions.
5 changes: 5 additions & 0 deletions build-logic/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,16 @@ repositories {
name = "Fabric"
url = uri("https://maven.fabricmc.net/")
}
maven {
name = "Ornithe Releases"
url = uri("https://maven.ornithemc.net/releases")
}
gradlePluginPortal()
}

dependencies {
implementation(libs.quilt.loom)
implementation(libs.ploceus)

implementation(libs.gson)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ public JsonElement serialize(ModInfoExtension modInfo, Type typeOfSrc, JsonSeria
qmjRoot.addProperty("mixin", mixin.get());
}

var accessWidener = modInfo.getAccessWidener();
if (accessWidener.isPresent()) {
qmjRoot.addProperty("access_widener", accessWidener.get());
}

var modmenuBlock = this.createModmenuBlock(modInfo);
if (modmenuBlock.size() > 0) {
qmjRoot.add("modmenu", modmenuBlock);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.UnknownTaskException;

import net.pixaurora.kit_tunes.build_logic.mod_resources_gen.extension.ModResourcesExtension;
import net.pixaurora.kit_tunes.build_logic.mod_resources_gen.task.CleanModIconTask;
Expand All @@ -22,6 +23,11 @@ public void apply(Project target) {
var cleanResources = tasks.create("cleanResources");

tasks.named("processResources").configure(task -> task.dependsOn(generateResources));
try {
tasks.named("genSources").configure(task -> task.dependsOn(generateResources));
} catch (UnknownTaskException e) {
}

tasks.named("clean").configure(task -> task.dependsOn(cleanResources));

var copyModIcon = tasks.register("copyModIcon", CopyModIconTask.class, modIcon);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,20 @@
import java.nio.file.Path;

import org.gradle.api.Action;
import org.gradle.api.Project;
import org.gradle.api.provider.Property;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.Nested;

import net.fabricmc.loom.api.LoomGradleExtensionAPI;

public abstract class ModInfoExtension {
private final Project project;

public ModInfoExtension(Project project) {
this.project = project;
}

@Input
public abstract Property<String> getId();

Expand All @@ -29,11 +38,25 @@ public abstract class ModInfoExtension {
@Input
public abstract Property<String> getMixinFile();

@Input
public abstract Property<String> getAccessWidener();

public void mixin(String path) {
var mixinFile = Path.of(path);
this.getMixinFile().set(mixinFile.toString());
}

public void accessWidener(String path) {
var loom = this.project.getExtensions().getByType(LoomGradleExtensionAPI.class);

var projectDir = project.getProjectDir().toPath();
var accessWidenerPath = projectDir.resolve(Path.of("src", "main", "resources", path));

loom.getAccessWidenerPath().set(accessWidenerPath.toFile());

this.getAccessWidener().set(path);
}

public void metadata(Action<? super ModMetadata> configuration) {
configuration.execute(this.getMetadata());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public abstract class ModResourcesExtension extends ModInfoExtension {

@Inject
public ModResourcesExtension(Project project) {
super(project);
this.propertiesWorkaround = new ProjectProperties(project);
}

Expand All @@ -25,7 +26,7 @@ public void modIdFromProperties() {
}

public String workaroundProperty(String propertyKey) {
return propertiesWorkaround.requireString(propertyKey);
return this.propertiesWorkaround.requireString(propertyKey);
}

public Provider<String> nameFromModId() {
Expand Down
33 changes: 33 additions & 0 deletions build-logic/src/main/kotlin/kit_tunes.legacy_submodule.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import org.gradle.accessors.dm.LibrariesForLibs
import net.pixaurora.kit_tunes.build_logic.ProjectMetadata
import net.pixaurora.kit_tunes.build_logic.mod_resources_gen.extension.ModResourcesExtension

plugins {
id("kit_tunes.submodule")
id("ploceus")
}

val libs = the<LibrariesForLibs>()

loom {
clientOnlyMinecraftJar()
}

ploceus {
clientOnlyMappings()
}

val minecraft_version = project.property("minecraft_version")

dependencies {
minecraft("com.mojang:minecraft:${minecraft_version}")
mappings(ploceus.featherMappings(project.property("feather_build") as String))

exceptions(ploceus.raven(project.property("raven_build") as String))
signatures(ploceus.sparrow(project.property("sparrow_build") as String))
nests(ploceus.nests(project.property("nests_build") as String))


modImplementation(libs.quilt.loader)
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
plugins {
id("kit_tunes.submodule")
}

dependencies {
mappings(loom.officialMojangMappings())
}
1 change: 0 additions & 1 deletion build-logic/src/main/kotlin/kit_tunes.module.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,5 @@ loom {
dependencies {
modImplementation(libs.quilt.loader)

mappings(loom.officialMojangMappings())
minecraft("com.mojang:minecraft:${project.property("minecraft_version")}")
}
4 changes: 4 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@ mod {
}

dependencies {
mappings(loom.officialMojangMappings())

include(project(":projects:kit-tunes-api"))
include(project(":projects:kitten-heart"))
include(project(":projects:catculator"))

include(project(":projects:kitten-sounds:b1.7.3"))
include(project(":projects:kitten-sounds:r1.17.0"))
include(project(":projects:kitten-sounds:r1.20.3"))

include(project(":projects:kitten-square:b1.7.3"))
include(project(":projects:kitten-square:r1.17.0"))
include(project(":projects:kitten-square:r1.19.0"))
include(project(":projects:kitten-square:r1.19.3"))
Expand Down
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ minecraft = "1.20.4"
quilt_mappings = "1.20.4+build.3"

quilt_loom = "1.8.4"
ploceus = "1.8.3"
quilt_loader = "0.26.3"

qsl = "8.0.0-alpha.11+1.20.4"
Expand All @@ -17,6 +18,7 @@ mod_publish = "0.7.4"
minecraft = { module = "com.mojang:minecraft", version.ref = "minecraft" }

quilt_loom = { module = "org.quiltmc:loom", version.ref = "quilt_loom" }
ploceus = { module = "net.ornithemc:ploceus", version.ref = "ploceus" }
quilt_loader = { module = "org.quiltmc:quilt-loader", version.ref = "quilt_loader" }

qsl_resource_loader = { module = "org.quiltmc.qsl.core:resource_loader", version.ref = "qsl"}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public Optional<Track> getTrack(ResourcePath path) {

@Override
public Optional<Track> matchTrack(ResourcePath soundPath) {
String[] splitPath = soundPath.representation().split("/");
String[] splitPath = soundPath.path().split("/");
String filename = splitPath[splitPath.length - 1];

int lastFullStop = filename.lastIndexOf(".");
Expand Down
15 changes: 15 additions & 0 deletions projects/kitten-sounds/b1.7.3/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
plugins {
id("kit_tunes.java.08")
id("kit_tunes.legacy_submodule")
}

mod {
intermediaryMappings = "net.fabricmc:intermediary"
accessWidener("kitten_sounds.accesswidener")
mixin("kitten_sounds.mixins.json")
}

dependencies {
implementation(project(":projects:kit-tunes-api"))
implementation(project(":projects:kitten-heart"))
}
11 changes: 11 additions & 0 deletions projects/kitten-sounds/b1.7.3/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Mod properties

minecraft_version_min = 1.0.0-beta.7.3
minecraft_version_max = 1.0.0-beta.7.3

minecraft_version = b1.7.3

feather_build = 23
raven_build = 1
sparrow_build = 1
nests_build = 4
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package net.pixaurora.kitten_sounds.impl;

import java.util.concurrent.atomic.AtomicReference;

import net.pixaurora.kitten_heart.impl.music.control.MusicControls;
import net.pixaurora.kitten_heart.impl.music.control.PlaybackState;

public class MusicControlsImpl implements MusicControls {
private String source;
private final AtomicReference<PlaybackState> playbackState = new AtomicReference<>(PlaybackState.STOPPED);

public void channel(String source) {
this.source = source;
}

@Override
public void pause() {
SoundEventsUtils.system().pause(this.source);
}

@Override
public void unpause() {
SoundEventsUtils.system().play(this.source);
}

@Override
public PlaybackState playbackState() {
return this.playbackState.get();
}

public void updatePlaybackState() {
this.playbackState.set(computePlaybackState());
}

public PlaybackState computePlaybackState() {
if (SoundEventsUtils.system().playing(this.source)) {
return PlaybackState.PLAYING;
} else {
return PlaybackState.PAUSED;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package net.pixaurora.kitten_sounds.impl;

import java.util.ArrayList;
import java.util.List;

import net.minecraft.client.sound.system.SoundFile;
import net.pixaurora.kitten_heart.impl.EventHandling;
import net.pixaurora.kitten_heart.impl.music.progress.PolledListeningProgress;

public class MusicPolling {
public static List<PolledSong> TRACKS_TO_POLL = new ArrayList<>();
public static List<PolledSong> POLLED_TRACKS = new ArrayList<>();

public static void onPlaySong(SoundFile sound, String source) {
MusicControlsImpl controls = new MusicControlsImpl();

PolledListeningProgress progress = EventHandling
.handleTrackStart(SoundEventsUtils.minecraftTypeToInternalType(sound.path), controls);

TRACKS_TO_POLL.add(new PolledSong(source, progress, controls));
}

public static void pollTrackProgress() {
TRACKS_TO_POLL.removeIf((polledSong) -> {
if (SoundEventsUtils.system().playing(polledSong.polled())) {
POLLED_TRACKS.add(polledSong);
return true;
} else {
return false;
}
});

POLLED_TRACKS.removeIf((polledSong) -> {
if (!SoundEventsUtils.system().playing(polledSong.polled())) {
EventHandling.handleTrackEnd(polledSong.progress());

return true;
} else {
polledSong.progress().measureProgress(polledSong);
polledSong.controls().updatePlaybackState();

return false;
}

});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package net.pixaurora.kitten_sounds.impl;

import net.pixaurora.kitten_heart.impl.music.progress.PolledListeningProgress;
import net.pixaurora.kitten_heart.impl.music.progress.SongProgressTracker;

public class PolledSong implements SongProgressTracker {
private final String source;

private final PolledListeningProgress progress;
private final MusicControlsImpl controls;

public PolledSong(String source, PolledSong previous) {
this.source = source;
this.progress = previous.progress;
this.controls = previous.controls;
}

public PolledSong(String source, PolledListeningProgress progress, MusicControlsImpl controls) {
this.source = source;
this.progress = progress;
this.controls = controls;
}

public String polled() {
return this.source;
}

public PolledListeningProgress progress() {
return this.progress;
}

public MusicControlsImpl controls() {
return this.controls;
}

@Override
public float kit_tunes$playbackPosition() {
float millisPlayed = System.currentTimeMillis() - this.progress.startTime().toEpochMilli();
return millisPlayed / 1000;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package net.pixaurora.kitten_sounds.impl;

import net.minecraft.client.sound.system.SoundEngine;
import net.pixaurora.kit_tunes.api.resource.ResourcePath;
import net.pixaurora.kitten_heart.impl.resource.ResourcePathImpl;
import paulscode.sound.SoundSystem;

public class SoundEventsUtils {
public static SoundSystem system() {
return SoundEngine.system;
}

public static ResourcePath minecraftTypeToInternalType(String identifier) {
return new ResourcePathImpl("", identifier);
}
}
Loading

0 comments on commit 06cba65

Please sign in to comment.