Skip to content
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

[1.20.2] Initial port work; port resource loader #336

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build-logic/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ asm = "9.5"
indra_git = "3.1.2"
quilt_gradle_licenser = "2.+"
quilt_parsers = "0.2.1"
quilt_loom = "1.3.+"
quilt_loom = "1.3.3"

[libraries]
asm = { module = "org.ow2.asm:asm", version.ref = "asm" }
Expand Down
10 changes: 5 additions & 5 deletions build-logic/src/main/java/qsl/internal/Versions.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,27 @@ public final class Versions {
/**
* The QSL version
*/
public static final String QSL_VERSION = "6.1.1";
public static final String QSL_VERSION = "7.0.0-alpha.1";

/**
* The target Minecraft version.
*/
public static final MinecraftVersion MINECRAFT_VERSION = new MinecraftVersion("1.20.1");
public static final MinecraftVersion MINECRAFT_VERSION = new MinecraftVersion("23w32a", "1.20.2");

/**
* The Minecraft versions this version of QSL is compatible with.
*/
public static final List<MinecraftVersion> COMPATIBLE_VERSIONS = versions("1.20");
public static final List<MinecraftVersion> COMPATIBLE_VERSIONS = versions();

/**
* The target Quilt Mappings build.
*/
public static final int MAPPINGS_BUILD = 20;
public static final int MAPPINGS_BUILD = 3;

/**
* The version of Quilt Loader to use.
*/
public static final String LOADER_VERSION = "0.19.2";
public static final String LOADER_VERSION = "0.19.4";

/**
* The target Java version.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,25 @@ public static Path getClassPath(FileSystem jarFs, String path) {
}

public static Stream<ClassNode> readPackage(FileSystem jarFs, String targetPackage) throws IOException {
return Files.list(jarFs.getPath(targetPackage.replace('.', '/')))
.filter(path -> path.toString().endsWith(".class") && Files.isRegularFile(path))
.map(path -> {
try {
return readClass(path);
} catch (IOException e) {
throw new RuntimeException(e);
}
})
.sorted(Comparator.comparing(classNode -> classNode.name));
return readPackage(Files.list(jarFs.getPath(targetPackage.replace('.', '/'))));
}

public static Stream<ClassNode> readPackageRecursive(FileSystem jarFs, String targetPackage) throws IOException {
return readPackage(Files.walk(jarFs.getPath(targetPackage.replace('.', '/'))));
}

public static Stream<ClassNode> readPackage(Stream<Path> in) {
return in
.filter(path -> path.toString().endsWith(".class") && Files.isRegularFile(path))
.map(path -> {
try {
return readClass(path);
} catch (IOException e) {
throw new RuntimeException(e);
}
})
.sorted(Comparator.comparing(classNode -> classNode.name));
}
public static FileSystem loadMinecraftJar(Project project) throws IOException {
var namedMinecraftProvider = ((LoomGradleExtension) project.getExtensions().getByType(LoomGradleExtensionAPI.class))
.getNamedMinecraftProvider();
Expand Down
4 changes: 2 additions & 2 deletions library/block/block_extensions/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ tasks.register("generateAccessWidener", GenerateAccessWidenerTask) {

def generateBlockConstructors(List<String> lines, FileSystem fs) {
lines.add("# Constructors of non-abstract block classes")
ClassAnalysisUtils.readPackage(fs, "net.minecraft.block")
ClassAnalysisUtils.readPackageRecursive(fs, "net.minecraft.block")
.filter { (it.access & Opcodes.ACC_ABSTRACT) == 0 }
.forEach { node ->
for (def method : node.methods) {
// Checklist for finding block constructors as of 1.18.2:
// - class directly in net.minecraft.block (excluding subpackages)
// - class in net.minecraft.block or subpackages
// - method name == <init> (by definition)
// - contains an AbstractBlock$Settings parameter
// - only taking into account non-abstract classes and non-public constructors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ transitive-accessible method net/minecraft/block/DeadCoralFanBlock <init> (Lnet/
transitive-accessible method net/minecraft/block/DeadCoralWallFanBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/DecoratedPotBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/DirtPathBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/DispenserBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/DoorBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;Lnet/minecraft/block/BlockSetType;)V
transitive-accessible method net/minecraft/block/DyedCarpetBlock <init> (Lnet/minecraft/util/DyeColor;Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/EnchantingTableBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;)V
Expand Down Expand Up @@ -76,7 +75,6 @@ transitive-accessible method net/minecraft/block/RedstoneTorchBlock <init> (Lnet
transitive-accessible method net/minecraft/block/RepeaterBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/RodBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/RootsBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/SaplingBlock <init> (Lnet/minecraft/block/sapling/SaplingGenerator;Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/ScaffoldingBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/SeaPickleBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/SeagrassBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;)V
Expand Down Expand Up @@ -104,3 +102,5 @@ transitive-accessible method net/minecraft/block/WallWitherSkullBlock <init> (Ln
transitive-accessible method net/minecraft/block/WeightedPressurePlateBlock <init> (ILnet/minecraft/block/AbstractBlock$Settings;Lnet/minecraft/block/BlockSetType;)V
transitive-accessible method net/minecraft/block/WetSpongeBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/WitherSkullBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/dispenser/DispenserBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/sapling/SaplingBlock <init> (Lnet/minecraft/block/sapling/SaplingGenerator;Lnet/minecraft/block/AbstractBlock$Settings;)V
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@

/**
* Events related to a ticking Minecraft server's worlds.
*
* <h2>A note of warning</h2>
* <p>
* <h2>A note of warning</h2>
* Callbacks registered to any of these events should ensure as little time as possible is spent executing, since the tick
* loop is a very hot code path.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ public static void send(ServerPlayerEntity player, Identifier channelName, Packe
Objects.requireNonNull(channelName, "Channel name cannot be null");
Objects.requireNonNull(buf, "Packet byte buf cannot be null");

player.networkHandler.sendPacket(createS2CPacket(channelName, buf));
player.networkHandler.(createS2CPacket(channelName, buf));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
player.networkHandler.(createS2CPacket(channelName, buf));
player.networkHandler.getConnection().send(createS2CPacket(channelName, buf));

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ public static PacketSender getSender() throws IllegalStateException {
public static void send(Identifier channelName, PacketByteBuf buf) throws IllegalStateException {
// You cant send without a client player, so this is fine
if (MinecraftClient.getInstance().getNetworkHandler() != null) {
MinecraftClient.getInstance().getNetworkHandler().sendPacket(createC2SPacket(channelName, buf));
MinecraftClient.getInstance().getNetworkHandler().getConnection().send(createC2SPacket(channelName, buf));
return;
}

Expand All @@ -246,7 +246,7 @@ public interface ChannelReceiver {
* String message = buf.readString(32767);
*
* // All operations on the server or world must be executed on the server thread
* client.execute(() -&rt; {
* client.execute(() -> {
* client.inGameHud.setOverlayMessage(message, true);
* });
* });
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import com.google.gson.JsonObject;
import com.mojang.logging.LogUtils;
import net.minecraft.SharedConstants;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't forget about checkstyle

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.Unmodifiable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.quiltmc.qsl.resource.loader.api;

import net.minecraft.resource.pack.ResourcePack;
import org.jetbrains.annotations.NotNull;

import net.minecraft.resource.pack.ResourcePackProfile;
Expand All @@ -39,4 +40,18 @@ public interface QuiltResourcePackProfile {
default @NotNull ResourcePackActivationType getActivationType() {
return ResourcePackActivationType.NORMAL;
}

static ResourcePackProfile.ResourcePackFactory identityFactory(ResourcePack pack) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this in API?

Copy link
Contributor Author

@TheGlitch76 TheGlitch76 Aug 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved it to API after noticing that the testmods need it. Vanilla does exactly the same thing, but their implementation BuiltinResourcePackProvider#method_52435(ResourcePack) is protected

return new ResourcePackProfile.ResourcePackFactory() {
@Override
public ResourcePack method_52424(String string) {
return pack;
}

@Override
public ResourcePack method_52425(String string, ResourcePackProfile.Info info) {
return pack;
}
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright 2023 The Quilt Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.quiltmc.qsl.resource.loader.impl;

import net.minecraft.resource.pack.ResourcePackSource;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;

/**
* Represents a built-in resource pack source.
* Similar to {@link ResourcePackSource#PACK_SOURCE_BUILTIN} but specifies the mod name too.
*/
public class BuiltinResourcePackSource implements ResourcePackSource {
private static final Text SOURCE_BUILTIN_TEXT = Text.translatable("pack.source.builtin");
private final ModNioResourcePack pack;
private final Text text;
private final Text tooltip;

BuiltinResourcePackSource(ModNioResourcePack pack) {
String modName = pack.modInfo.name();

if (modName == null) {
modName = pack.modInfo.id();
}

this.pack = pack;
this.text = SOURCE_BUILTIN_TEXT;
this.tooltip = Text.translatable("options.generic_value", SOURCE_BUILTIN_TEXT, modName);
}

@Override
public Text decorate(Text description) {
return Text.translatable("pack.nameAndSource", description, this.text).formatted(Formatting.GRAY);
}

@Override
public boolean shouldAddAutomatically() {
return this.pack.getActivationType().isEnabledByDefault();
}

public Text getTooltip() {
return this.tooltip;
}
}
Loading
Loading