Skip to content

Instantly share code, notes, and snippets.

@shartte
Last active September 8, 2021 20:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shartte/760c7fce30d81cd248c2f91005565613 to your computer and use it in GitHub Desktop.
Save shartte/760c7fce30d81cd248c2f91005565613 to your computer and use it in GitHub Desktop.

APIs made possible by Interface Injection and Global Access Wideners

CriterionRegistry

Current API

Replaced (along the Accessor) fully by:

global accessible method net/minecraft/advancement/criterion/Criteria register (Lnet/minecraft/advancement/criterion/Criterion;)Lnet/minecraft/advancement/criterion/Criterion;

Mod code changes from:

net.fabricmc.fabric.api.object.builder.v1.advancement.CriterionRegistry.register(...)

to calling Vanillas

net.minecraft.advancement.criterion.Criteria.register(...)

FabricBlockSettings

Current API

Replaced by an interface that is injected into Vanilla's Block.Settings:

public interface FabricBlockSettings {
	AbstractBlock.Settings breakByHand(boolean breakByHand);
	AbstractBlock.Settings breakByTool(Tag<Item> tag, int miningLevel);
	default AbstractBlock.Settings breakByTool(Tag<Item> tag) {
		return breakByTool(tag, 0);
	}
}
  • NOTE: It'd be Fabric's choice to be bold and omit a prefix here, or use a fabric Prefix for the added Methods (i.e. fabricBreakByHand).

using the V2 access widener:

global add-interface net/minecraft/block/AbstractBlock$Settings net/fabricmc/fabric/api/object/builder/v2/block/FabricBlockSettings

It is then implemented using the existing mixin net.fabricmc.fabric.mixin.object.builder.AbstractBlockSettingsMixin:

@Mixin(AbstractBlock.Settings.class)
public abstract class AbstractBlockSettingsMixin implements BlockSettingsInternals, **FabricBlockSettings** {
  [...]

	@Override
	public AbstractBlock.Settings breakByHand(boolean breakByHand) {
		getOrCreateExtraData().breakByHand(breakByHand);
		return (AbstractBlock.Settings) (Object) this;
	}

	@Override
	public AbstractBlock.Settings breakByTool(Tag<Item> tag, int miningLevel) {
		getOrCreateExtraData().addMiningLevel(tag, miningLevel);
		return (AbstractBlock.Settings) (Object) this;
	}
}

Mods can replace their uses of FabricBlockSettings with the Vanilla block settings builder, and still call the Fabric specific methods.

FabricMaterialBuilder

Current API

Replaced by an interface that is injected into Vanilla's Material.Builder, and a global access widener:

public interface FabricMaterialBuilder {
	Material.Builder pistonBehavior(PistonBehavior behavior);
}
  • NOTE: It'd be Fabric's choice to be bold and omit a prefix here, or use a fabric Prefix for the added Methods (i.e. fabricPistonBehavior).

using the V2 access widener:

global add-interface net/minecraft/block/Material$Builder net/fabricmc/fabric/api/object/builder/v2/block/FabricMaterialBuilder
global accessible method net/minecraft/block/Material$Builder lightPassesThrough ()Lnet/minecraft/block/Material$Builder;

Mods can replace their uses of FabricMaterialBuilder with the Vanilla material builder, and still call the Fabric specific methods.

FabricBlockEntityTypeBuilder

Current API

can be replaced using a V2 access widener:

global accessible class net/minecraft/block/entity/BlockEntityType$BlockEntityFactory

Mods can replace their uses of FabricBlockEntityTypeBuilder with the Vanilla block entity type builder.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment