mirror of
https://github.com/FabricMC/fabric.git
synced 2025-04-21 03:10:54 -04:00
Move a few object builders to transitive AWs (#2154)
* Move a few object builders to transitive AWs * Remove outdated access widener * Remove controversial deprecation of FabricBlockEntityTypeBuilder
This commit is contained in:
parent
5eb68ef24d
commit
1e232e13ae
9 changed files with 39 additions and 50 deletions
fabric-object-builder-api-v1/src/main
java/net/fabricmc/fabric
api/object/builder/v1
block/entity
villager
mixin/object/builder
resources
fabric-transitive-access-wideners-v1
|
@ -29,9 +29,10 @@ import net.minecraft.block.entity.BlockEntityType;
|
|||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
/**
|
||||
* Fabric's version of BlockEntityType.Builder.
|
||||
* Removes the need to use an access widener on the BlockEntityFactory
|
||||
* Fabric's version of BlockEntityType.Builder with additional convenience methods.
|
||||
*
|
||||
* <p>Alternatively, use the access widener for {@link BlockEntityType.BlockEntityFactory}
|
||||
* in Fabric Transitive Access Wideners (v1).
|
||||
*/
|
||||
public final class FabricBlockEntityTypeBuilder<T extends BlockEntity> {
|
||||
private final Factory<? extends T> factory;
|
||||
|
|
|
@ -42,7 +42,11 @@ import net.minecraft.world.poi.PointOfInterestType;
|
|||
* <p>A corresponding <code>IDENTIFIER_PATH.mcmeta</code> file exits in the same directory to define properties such as the {@link net.minecraft.client.render.entity.feature.VillagerResourceMetadata.HatType HatType} this profession would use.
|
||||
*
|
||||
* <p>Note this does not register any trades to these villagers. To register trades, add a new entry with your profession as the key to {@link TradeOffers#PROFESSION_TO_LEVELED_TRADE}.
|
||||
*
|
||||
* @deprecated Replaced by access widener for {@link VillagerProfession#VillagerProfession}
|
||||
* in Fabric Transitive Access Wideners (v1).
|
||||
*/
|
||||
@Deprecated
|
||||
public final class VillagerProfessionBuilder {
|
||||
private final ImmutableSet.Builder<Item> gatherableItemsBuilder = ImmutableSet.builder();
|
||||
private final ImmutableSet.Builder<Block> secondaryJobSiteBlockBuilder = ImmutableSet.builder();
|
||||
|
|
|
@ -22,13 +22,12 @@ import org.slf4j.LoggerFactory;
|
|||
import org.slf4j.Logger;
|
||||
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.util.registry.RegistryKey;
|
||||
import net.minecraft.village.VillagerProfession;
|
||||
import net.minecraft.village.VillagerType;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
|
||||
import net.fabricmc.fabric.mixin.object.builder.VillagerTypeAccessor;
|
||||
|
||||
/**
|
||||
* Utilities related to the creation of {@link VillagerType}s.
|
||||
* Not to be confused with a {@link VillagerProfession}, a villager type defines the appearance of a villager.
|
||||
|
@ -40,7 +39,11 @@ import net.fabricmc.fabric.mixin.object.builder.VillagerTypeAccessor;
|
|||
* To allow a villager type to be spawned in a specific biome, use {@link VillagerTypeHelper#addVillagerTypeToBiome(RegistryKey, VillagerType)}.
|
||||
*
|
||||
* <p>The texture used for the appearance of the villager is located at {@code assets/IDENTIFIER_NAMESPACE/textures/entity/villager/type/IDENTIFIER_PATH.png}.
|
||||
*
|
||||
* @deprecated Replaced by access wideners for {@link VillagerType#create} and {@link VillagerType#BIOME_TO_TYPE}
|
||||
* in Fabric Transitive Access Wideners (v1).
|
||||
*/
|
||||
@Deprecated
|
||||
public final class VillagerTypeHelper {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(VillagerTypeHelper.class);
|
||||
|
||||
|
@ -52,7 +55,7 @@ public final class VillagerTypeHelper {
|
|||
*/
|
||||
public static VillagerType register(Identifier id) {
|
||||
Objects.requireNonNull(id, "Id of villager type cannot be null");
|
||||
return VillagerTypeAccessor.callRegister(id.toString());
|
||||
return Registry.register(Registry.VILLAGER_TYPE, new Identifier(id.toString()), new VillagerType(id.toString()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -65,7 +68,7 @@ public final class VillagerTypeHelper {
|
|||
Objects.requireNonNull(biomeKey, "Biome registry key cannot be null");
|
||||
Objects.requireNonNull(villagerType, "Villager type cannot be null");
|
||||
|
||||
if (VillagerTypeAccessor.getBiomeTypeToIdMap().put(biomeKey, villagerType) != null) {
|
||||
if (VillagerType.BIOME_TO_TYPE.put(biomeKey, villagerType) != null) {
|
||||
LOGGER.debug("Overriding existing Biome -> VillagerType registration for Biome {}", biomeKey.getValue().toString());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,41 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC
|
||||
*
|
||||
* 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 net.fabricmc.fabric.mixin.object.builder;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
import org.spongepowered.asm.mixin.gen.Invoker;
|
||||
|
||||
import net.minecraft.util.registry.RegistryKey;
|
||||
import net.minecraft.village.VillagerType;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
|
||||
@Mixin(VillagerType.class)
|
||||
public interface VillagerTypeAccessor {
|
||||
@Accessor("BIOME_TO_TYPE")
|
||||
static Map<RegistryKey<Biome>, VillagerType> getBiomeTypeToIdMap() {
|
||||
throw new AssertionError("Untransformed Accessor!");
|
||||
}
|
||||
|
||||
// FIXME: This should be called `register` in yarn
|
||||
@Invoker("create")
|
||||
static VillagerType callRegister(String id) {
|
||||
throw new AssertionError("Untransformed Accessor!");
|
||||
}
|
||||
}
|
|
@ -5,3 +5,6 @@ extendable method net/minecraft/block/AbstractBlock$Settings <init> (Lne
|
|||
accessible method net/minecraft/world/poi/PointOfInterestTypes register (Lnet/minecraft/util/registry/Registry;Lnet/minecraft/util/registry/RegistryKey;Ljava/util/Set;II)Lnet/minecraft/world/poi/PointOfInterestType;
|
||||
|
||||
extendable class net/minecraft/block/entity/BlockEntityType$BlockEntityFactory
|
||||
|
||||
accessible field net/minecraft/village/VillagerType BIOME_TO_TYPE Ljava/util/Map;
|
||||
accessible method net/minecraft/village/VillagerType <init> (Ljava/lang/String;)V
|
||||
|
|
|
@ -11,8 +11,7 @@
|
|||
"DetectorRailBlockMixin",
|
||||
"MaterialBuilderAccessor",
|
||||
"SpawnRestrictionAccessor",
|
||||
"TypeAwareTradeMixin",
|
||||
"VillagerTypeAccessor"
|
||||
"TypeAwareTradeMixin"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
|
|
|
@ -19,7 +19,7 @@ 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
|
||||
Path inputJar = loom.namedMinecraftProvider.parentMinecraftProvider.commonJar
|
||||
|
||||
try (def fs = FileSystems.newFileSystem(URI.create("jar:${inputJar.toUri()}"), [create: false])) {
|
||||
generateBlockConstructors(lines, fs)
|
||||
|
|
|
@ -24,6 +24,16 @@ transitive-accessible field net/minecraft/loot/LootPool bonusRolls Lnet/minecraf
|
|||
transitive-accessible field net/minecraft/loot/LootTable pools [Lnet/minecraft/loot/LootPool;
|
||||
transitive-accessible field net/minecraft/loot/LootTable functions [Lnet/minecraft/loot/function/LootFunction;
|
||||
|
||||
# Creating block entity types
|
||||
transitive-extendable class net/minecraft/block/entity/BlockEntityType$BlockEntityFactory
|
||||
|
||||
# Villagers
|
||||
transitive-accessible field net/minecraft/village/VillagerType BIOME_TO_TYPE Ljava/util/Map;
|
||||
transitive-accessible method net/minecraft/village/VillagerType <init> (Ljava/lang/String;)V
|
||||
|
||||
# Access stack list in SimpleInventory
|
||||
transitive-accessible field net/minecraft/inventory/SimpleInventory stacks Lnet/minecraft/util/collection/DefaultedList;
|
||||
|
||||
### Generated access wideners below
|
||||
# Constructors of non-abstract block classes
|
||||
transitive-accessible method net/minecraft/block/AirBlock <init> (Lnet/minecraft/block/AbstractBlock$Settings;)V
|
||||
|
|
|
@ -24,4 +24,14 @@ transitive-accessible field net/minecraft/loot/LootPool bonusRolls Lnet/minecraf
|
|||
transitive-accessible field net/minecraft/loot/LootTable pools [Lnet/minecraft/loot/LootPool;
|
||||
transitive-accessible field net/minecraft/loot/LootTable functions [Lnet/minecraft/loot/function/LootFunction;
|
||||
|
||||
# Creating block entity types
|
||||
transitive-extendable class net/minecraft/block/entity/BlockEntityType$BlockEntityFactory
|
||||
|
||||
# Villagers
|
||||
transitive-accessible field net/minecraft/village/VillagerType BIOME_TO_TYPE Ljava/util/Map;
|
||||
transitive-accessible method net/minecraft/village/VillagerType <init> (Ljava/lang/String;)V
|
||||
|
||||
# Access stack list in SimpleInventory
|
||||
transitive-accessible field net/minecraft/inventory/SimpleInventory stacks Lnet/minecraft/util/collection/DefaultedList;
|
||||
|
||||
### Generated access wideners below
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue