Create transitive AW module (#2044)

* Add transitive AW module with block constructors

* Add various registries to transitive AW module

* Fix module name in README, add skip flags to class reading

* Add reasons for TAWs, document Block ctor finding algorithm
This commit is contained in:
Juuxel 2022-03-13 15:52:38 +02:00 committed by GitHub
parent ac596cd27a
commit 40c91ec8c3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 244 additions and 0 deletions

View file

@ -28,7 +28,10 @@ import net.fabricmc.fabric.mixin.object.builder.CriteriaAccessor;
* {@link net.minecraft.advancement.criterion.Criteria#getById(Identifier)}.</p>
*
* @see net.minecraft.advancement.criterion.Criteria
* @deprecated Replaced by access widener for {@link net.minecraft.advancement.criterion.Criteria#register(Criterion)}
* in Fabric Transitive Access Wideners (v1).
*/
@Deprecated
public final class CriterionRegistry {
/**
* Registers a criterion for a trigger for advancements.

View file

@ -30,7 +30,10 @@ import net.fabricmc.fabric.mixin.object.builder.ModelPredicateProviderRegistrySp
* {@link net.minecraft.client.item.ModelPredicateProviderRegistry#get(Item, Identifier)}.</p>
*
* @see net.minecraft.client.item.ModelPredicateProviderRegistry
* @deprecated Replaced by access wideners for {@link net.minecraft.client.item.ModelPredicateProviderRegistry}
* registration methods in Fabric Transitive Access Wideners (v1).
*/
@Deprecated
public final class FabricModelPredicateProviderRegistry {
/**
* Registers a model predicate provider that is applicable for any item.

View file

@ -47,8 +47,11 @@ import net.fabricmc.api.Environment;
* </pre>
*
* @see net.fabricmc.fabric.api.screenhandler.v1.ScreenHandlerRegistry registering screen handlers
* @deprecated Replaced by access wideners for {@link HandledScreens#register(ScreenHandlerType, HandledScreens.Provider)}
* and {@link HandledScreens.Provider} in Fabric Transitive Access Wideners (v1).
*/
@Environment(EnvType.CLIENT)
@Deprecated
public final class ScreenRegistry {
private ScreenRegistry() {
}

View file

@ -78,7 +78,9 @@ public final class ScreenHandlerRegistry {
* @param factory the client-sided screen handler factory
* @param <T> the screen handler type
* @return the created type object
* @deprecated Replaced by access widener for {@link ScreenHandlerType#ScreenHandlerType(ScreenHandlerType.Factory)} in Fabric Transitive Access Wideners (v1).
*/
@Deprecated
public static <T extends ScreenHandler> ScreenHandlerType<T> registerSimple(Identifier id, SimpleClientHandlerFactory<T> factory) {
// Wrap our factory in vanilla's factory; it will not be public for users.
// noinspection Convert2MethodRef - Must be a lambda or else dedicated server will crash
@ -106,7 +108,9 @@ public final class ScreenHandlerRegistry {
* A factory for client-sided screen handler instances.
*
* @param <T> the screen handler type
* @deprecated Replaced by access widener for {@link ScreenHandlerType.Factory} in Fabric Transitive Access Wideners (v1).
*/
@Deprecated
public interface SimpleClientHandlerFactory<T extends ScreenHandler> {
/**
* Creates a new client-sided screen handler.

View file

@ -0,0 +1,3 @@
# Fabric Transitive Access Wideners (v1)
This module provides access wideners that provide access
to otherwise inaccessible Minecraft code.

View file

@ -0,0 +1,66 @@
archivesBaseName = "fabric-transitive-access-wideners-v1"
version = getSubprojectVersion(project)
loom {
accessWidenerPath = file('src/main/resources/fabric-transitive-access-wideners-v1.accesswidener')
}
import org.objectweb.asm.ClassReader
import org.objectweb.asm.Opcodes
import org.objectweb.asm.Type
import org.objectweb.asm.tree.ClassNode
import java.nio.file.FileSystem
import java.nio.file.FileSystems
import java.nio.file.Files
import java.nio.file.Path
import java.util.stream.Collectors
task generateAccessWidener {
doLast {
List<String> lines = file("template.accesswidener").text.lines().collect(Collectors.toCollection { [] })
Path inputJar = loom.namedMinecraftProvider.parentMinecraftProvider.mergedJar
try (def fs = FileSystems.newFileSystem(URI.create("jar:${inputJar.toUri()}"), [create: false])) {
generateBlockConstructors(lines, fs)
}
file('src/main/resources/fabric-transitive-access-wideners-v1.accesswidener').text = String.join('\n', lines) + '\n'
}
}
def generateBlockConstructors(List<String> lines, FileSystem fs) {
lines.add("# Constructors of non-abstract block classes")
Files.list(fs.getPath("net/minecraft/block"))
.filter { Files.isRegularFile(it) && it.toString().endsWith(".class") }
.map { loadClass(it) }
.sorted(Comparator.comparing { it.name })
.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)
// - method name == <init> (by definition)
// - contains an AbstractBlock$Settings parameter
// - only taking into account non-abstract classes and non-public constructors
// Block constructor...
if (method.name == "<init>" && Type.getArgumentTypes(method.desc).any { it.internalName == 'net/minecraft/block/AbstractBlock$Settings' }) {
// ...and non-public
if ((method.access & Opcodes.ACC_PUBLIC) == 0) {
lines.add("transitive-accessible method $node.name <init> $method.desc")
}
}
}
}
}
ClassNode loadClass(Path path) {
def node = new ClassNode()
try (def is = Files.newInputStream(path)) {
new ClassReader(is).accept(node, ClassReader.SKIP_CODE | ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES)
}
return node
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

View file

@ -0,0 +1,116 @@
accessWidener v2 named
# Registering custom model predicate providers for item models
transitive-accessible method net/minecraft/client/item/ModelPredicateProviderRegistry register (Lnet/minecraft/util/Identifier;Lnet/minecraft/client/item/UnclampedModelPredicateProvider;)Lnet/minecraft/client/item/UnclampedModelPredicateProvider;
transitive-accessible method net/minecraft/client/item/ModelPredicateProviderRegistry register (Lnet/minecraft/item/Item;Lnet/minecraft/util/Identifier;Lnet/minecraft/client/item/UnclampedModelPredicateProvider;)V
# Registering custom advancement criteria
transitive-accessible method net/minecraft/advancement/criterion/Criteria register (Lnet/minecraft/advancement/criterion/Criterion;)Lnet/minecraft/advancement/criterion/Criterion;
# Creating custom screen handler types
transitive-accessible class net/minecraft/screen/ScreenHandlerType$Factory
transitive-accessible method net/minecraft/screen/ScreenHandlerType <init> (Lnet/minecraft/screen/ScreenHandlerType$Factory;)V
# Registering custom screen handler type -> screen mappings
transitive-accessible class net/minecraft/client/gui/screen/ingame/HandledScreens$Provider
transitive-accessible method net/minecraft/client/gui/screen/ingame/HandledScreens register (Lnet/minecraft/screen/ScreenHandlerType;Lnet/minecraft/client/gui/screen/ingame/HandledScreens$Provider;)V
### Generated access wideners below
# Constructors of non-abstract block classes
transitive-accessible method net/minecraft/block/AirBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/AttachedStemBlock <init> (Lnet/minecraft/block/GourdBlock;Ljava/util/function/Supplier;Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/AzaleaBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/BarrierBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/BigDripleafBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/BigDripleafStemBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/BlastFurnaceBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/CactusBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/CakeBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/CandleCakeBlock <init> (Lnet/minecraft/block/Block;Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/CartographyTableBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/CarvedPumpkinBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/ChestBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;Ljava/util/function/Supplier;)V
transitive-accessible method net/minecraft/block/ChorusFlowerBlock <init> (Lnet/minecraft/block/ChorusPlantBlock;Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/ChorusPlantBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/ConnectingBlock <init> (FLnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/CoralBlock <init> (Lnet/minecraft/block/Block;Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/CoralFanBlock <init> (Lnet/minecraft/block/Block;Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/CoralParentBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/CoralWallFanBlock <init> (Lnet/minecraft/block/Block;Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/CraftingTableBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/CropBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/DeadBushBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/DeadCoralBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/DeadCoralFanBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/DeadCoralWallFanBlock <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;)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
transitive-accessible method net/minecraft/block/EndGatewayBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/EndPortalBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/EndRodBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/EnderChestBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/FarmlandBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/FernBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/FletchingTableBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/FluidBlock <init> (Lnet/minecraft/fluid/FlowableFluid;Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/FungusBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;Ljava/util/function/Supplier;)V
transitive-accessible method net/minecraft/block/FurnaceBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/GrindstoneBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/HangingRootsBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/HorizontalConnectingBlock <init> (FFFFFLnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/JigsawBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/JukeboxBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/KelpBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/KelpPlantBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/LadderBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/LecternBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/LeverBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/LilyPadBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/LoomBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/MelonBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/NetherWartBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/NyliumBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/PaneBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/PlantBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/PlayerSkullBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/PoweredRailBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/PressurePlateBlock <init> (Lnet/minecraft/block/PressurePlateBlock$ActivationRule;Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/PumpkinBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/RailBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/RedstoneTorchBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;)V
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
transitive-accessible method net/minecraft/block/SkullBlock <init> (Lnet/minecraft/block/SkullBlock$SkullType;Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/SmithingTableBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/SmokerBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/SnowBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/SnowyBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/SpawnerBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/SpongeBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/StairsBlock <init> (Lnet/minecraft/block/BlockState;Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/StemBlock <init> (Lnet/minecraft/block/GourdBlock;Ljava/util/function/Supplier;Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/StoneButtonBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/StructureBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/StructureVoidBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/SugarCaneBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/TorchBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;Lnet/minecraft/particle/ParticleEffect;)V
transitive-accessible method net/minecraft/block/TransparentBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/TrapdoorBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/WallMountedBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/WallPlayerSkullBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/WallRedstoneTorchBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/WallSkullBlock <init> (Lnet/minecraft/block/SkullBlock$SkullType;Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/WallTorchBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;Lnet/minecraft/particle/ParticleEffect;)V
transitive-accessible method net/minecraft/block/WallWitherSkullBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;)V
transitive-accessible method net/minecraft/block/WeightedPressurePlateBlock <init> (ILnet/minecraft/block/AbstractBlock$Settings;)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/WoodenButtonBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;)V

View file

@ -0,0 +1,26 @@
{
"schemaVersion": 1,
"id": "fabric-transitive-access-wideners-v1",
"name": "Fabric Transitive Access Wideners (v1)",
"version": "${version}",
"environment": "*",
"license": "Apache-2.0",
"icon": "assets/fabric-transitive-access-wideners-v1/icon.png",
"contact": {
"homepage": "https://fabricmc.net",
"irc": "irc://irc.esper.net:6667/fabric",
"issues": "https://github.com/FabricMC/fabric/issues",
"sources": "https://github.com/FabricMC/fabric"
},
"authors": [
"FabricMC"
],
"depends": {
"fabricloader": ">=0.12.12"
},
"description": "Contains transitive access wideners that provide access to otherwise inaccessible Minecraft code.",
"accessWidener": "fabric-transitive-access-wideners-v1.accesswidener",
"custom": {
"fabric-api:module-lifecycle": "stable"
}
}

View file

@ -0,0 +1,18 @@
accessWidener v2 named
# Registering custom model predicate providers for item models
transitive-accessible method net/minecraft/client/item/ModelPredicateProviderRegistry register (Lnet/minecraft/util/Identifier;Lnet/minecraft/client/item/UnclampedModelPredicateProvider;)Lnet/minecraft/client/item/UnclampedModelPredicateProvider;
transitive-accessible method net/minecraft/client/item/ModelPredicateProviderRegistry register (Lnet/minecraft/item/Item;Lnet/minecraft/util/Identifier;Lnet/minecraft/client/item/UnclampedModelPredicateProvider;)V
# Registering custom advancement criteria
transitive-accessible method net/minecraft/advancement/criterion/Criteria register (Lnet/minecraft/advancement/criterion/Criterion;)Lnet/minecraft/advancement/criterion/Criterion;
# Creating custom screen handler types
transitive-accessible class net/minecraft/screen/ScreenHandlerType$Factory
transitive-accessible method net/minecraft/screen/ScreenHandlerType <init> (Lnet/minecraft/screen/ScreenHandlerType$Factory;)V
# Registering custom screen handler type -> screen mappings
transitive-accessible class net/minecraft/client/gui/screen/ingame/HandledScreens$Provider
transitive-accessible method net/minecraft/client/gui/screen/ingame/HandledScreens register (Lnet/minecraft/screen/ScreenHandlerType;Lnet/minecraft/client/gui/screen/ingame/HandledScreens$Provider;)V
### Generated access wideners below

View file

@ -51,3 +51,4 @@ fabric-screen-handler-api-v1-version=1.1.13
fabric-structure-api-v1-version=3.0.1
fabric-textures-v0-version=1.0.11
fabric-transfer-api-v1-version=1.5.13
fabric-transitive-access-wideners-v1-version=1.0.0

View file

@ -54,3 +54,4 @@ include 'fabric-screen-api-v1'
include 'fabric-screen-handler-api-v1'
include 'fabric-textures-v0'
include 'fabric-transfer-api-v1'
include 'fabric-transitive-access-wideners-v1'