Skip to content

Commit

Permalink
24w09a (#3623)
Browse files Browse the repository at this point in the history
* In game

* More fixes

* Small fixes + changes

* Rename

* Fix test
  • Loading branch information
modmuss50 committed Feb 29, 2024
1 parent c81ced1 commit 1172e89
Show file tree
Hide file tree
Showing 53 changed files with 444 additions and 712 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import static net.fabricmc.fabric.test.lookup.FabricApiLookupTest.ensureException;

import net.minecraft.component.DataComponentTypes;
import net.minecraft.item.Item;
import net.minecraft.item.Items;
import net.minecraft.item.ToolItem;
Expand All @@ -41,7 +42,7 @@ public static void onInitialize() {

// Diamonds and diamond blocks can be inspected and will also print their name.
INSPECTABLE.registerForItems((stack, ignored) -> () -> {
if (stack.hasCustomName()) {
if (stack.contains(DataComponentTypes.CUSTOM_NAME)) {
return stack.getName();
} else {
return Text.literal("Unnamed gem.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,4 @@ private static void getCommonNodeType(BlockView world, BlockPos pos, CallbackInf
cir.setReturnValue(nodeType);
}
}

/**
* Overrides the node type for the specified position, if the position is found as neighbor block in a path.
*/
@Inject(method = "getNodeTypeFromNeighbors", at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/entity/ai/pathing/LandPathNodeMaker;getCommonNodeType(Lnet/minecraft/world/BlockView;Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/entity/ai/pathing/PathNodeType;"), cancellable = true)
private static void getNodeTypeFromNeighbors(BlockView world, BlockPos.Mutable pos, PathNodeType nodeType, CallbackInfoReturnable<PathNodeType> cir) {
PathNodeType neighborNodeType = LandPathNodeTypesRegistry.getPathNodeType(world.getBlockState(pos), world, pos, true);

if (neighborNodeType != null) {
cir.setReturnValue(neighborNodeType);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* 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.content.registry;

import com.llamalad7.mixinextras.sugar.Local;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import net.minecraft.block.BlockState;
import net.minecraft.class_9316;
import net.minecraft.entity.ai.pathing.PathNodeType;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.CollisionView;

import net.fabricmc.fabric.api.registry.LandPathNodeTypesRegistry;

@Mixin(class_9316.class)
public abstract class class_9316Mixin {
@Shadow
public abstract BlockState method_57623(BlockPos blockPos);

@Shadow
public abstract CollisionView method_57621();

/**
* Overrides the node type for the specified position, if the position is found as neighbor block in a path.
*/
@Inject(method = "method_57622", at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/util/math/BlockPos$Mutable;set(III)Lnet/minecraft/util/math/BlockPos$Mutable;"), cancellable = true)
private void method_57622(int x, int y, int z, CallbackInfoReturnable<PathNodeType> cir, @Local BlockPos pos) {
final PathNodeType neighborNodeType = LandPathNodeTypesRegistry.getPathNodeType(method_57623(pos), method_57621(), pos, true);

if (neighborNodeType != null) {
cir.setReturnValue(neighborNodeType);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"compatibilityLevel": "JAVA_17",
"mixins": [
"AxeItemAccessor",
"class_9316Mixin",
"FarmerWorkTaskAccessor",
"GiveGiftsToHeroTaskAccessor",
"HoeItemAccessor",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public static void serializeAttachmentData(NbtCompound nbt, RegistryWrapper.Wrap
Codec<Object> codec = (Codec<Object>) type.persistenceCodec();

if (codec != null) {
RegistryOps<NbtElement> registryOps = wrapperLookup.method_57093(NbtOps.INSTANCE);
RegistryOps<NbtElement> registryOps = wrapperLookup.getOps(NbtOps.INSTANCE);
codec.encodeStart(registryOps, entry.getValue())
.get()
.ifRight(partial -> {
Expand Down Expand Up @@ -81,7 +81,7 @@ public static IdentityHashMap<AttachmentType<?>, Object> deserializeAttachmentDa
Codec<?> codec = type.persistenceCodec();

if (codec != null) {
RegistryOps<NbtElement> registryOps = wrapperLookup.method_57093(NbtOps.INSTANCE);
RegistryOps<NbtElement> registryOps = wrapperLookup.getOps(NbtOps.INSTANCE);
codec.parse(registryOps, compound.get(key))
.get()
.ifRight(partial -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ void testWorldPersistentState() {

private static DynamicRegistryManager mockDRM() {
DynamicRegistryManager drm = mock(DynamicRegistryManager.class);
when(drm.method_57093(any())).thenReturn((RegistryOps<Object>) (Object) RegistryOps.of(NbtOps.INSTANCE, drm));
when(drm.getOps(any())).thenReturn((RegistryOps<Object>) (Object) RegistryOps.of(NbtOps.INSTANCE, drm));
return drm;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ protected FabricAdvancementProvider(FabricDataOutput output, CompletableFuture<R
*
* <p>Use {@link Advancement.Builder#build(Consumer, String)} to help build advancements.
*/
public abstract void generateAdvancement(Consumer<AdvancementEntry> consumer);
public abstract void generateAdvancement(RegistryWrapper.WrapperLookup registryLookup, Consumer<AdvancementEntry> consumer);

/**
* Return a new exporter that applies the specified conditions to any advancement it receives.
Expand All @@ -80,13 +80,13 @@ protected Consumer<AdvancementEntry> withConditions(Consumer<AdvancementEntry> e

@Override
public CompletableFuture<?> run(DataWriter writer) {
final Set<Identifier> identifiers = Sets.newHashSet();
final Set<AdvancementEntry> advancements = Sets.newHashSet();
return this.registryLookup.thenCompose(lookup -> {
final Set<Identifier> identifiers = Sets.newHashSet();
final Set<AdvancementEntry> advancements = Sets.newHashSet();

generateAdvancement(advancements::add);
generateAdvancement(lookup, advancements::add);

return this.registryLookup.thenCompose(lookup -> {
RegistryOps<JsonElement> ops = lookup.method_57093(JsonOps.INSTANCE);
RegistryOps<JsonElement> ops = lookup.getOps(JsonOps.INSTANCE);
final List<CompletableFuture<?>> futures = new ArrayList<>();

for (AdvancementEntry advancement : advancements) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void excludeFromStrictValidation(Block block) {
}

@Override
public void accept(BiConsumer<Identifier, LootTable.Builder> biConsumer) {
public void accept(RegistryWrapper.WrapperLookup registryLookup, BiConsumer<Identifier, LootTable.Builder> biConsumer) {
generate();

for (Map.Entry<Identifier, LootTable.Builder> entry : lootTables.entrySet()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ protected FabricCodecDataProvider(FabricDataOutput dataOutput, CompletableFuture
public CompletableFuture<?> run(DataWriter writer) {
return this.registriesFuture.thenCompose(lookup -> {
Map<Identifier, JsonElement> entries = new HashMap<>();
RegistryOps<JsonElement> ops = lookup.method_57093(JsonOps.INSTANCE);
RegistryOps<JsonElement> ops = lookup.getOps(JsonOps.INSTANCE);

BiConsumer<Identifier, T> provider = (id, value) -> {
JsonElement json = this.convert(id, value, ops);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public CompletableFuture<?> run(DataWriter writer) {
return entries;
})
.thenCompose(entries -> {
final RegistryOps<JsonElement> dynamicOps = registries.method_57093(JsonOps.INSTANCE);
final RegistryOps<JsonElement> dynamicOps = registries.getOps(JsonOps.INSTANCE);
ArrayList<CompletableFuture<?>> futures = new ArrayList<>();

for (RegistryEntries<?> registryEntries : entries.queuedEntries.values()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import net.minecraft.item.ItemGroup;
import net.minecraft.registry.Registries;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryWrapper;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.stat.StatType;
import net.minecraft.text.TextContent;
Expand All @@ -52,52 +53,56 @@

/**
* Extend this class and implement {@link FabricLanguageProvider#generateTranslations(TranslationBuilder)}.
* Make sure to use {@link FabricLanguageProvider#FabricLanguageProvider(FabricDataOutput, String)} FabricLanguageProvider} to declare what language code is being generated if it isn't {@code en_us}.
* Make sure to use {@link FabricLanguageProvider#FabricLanguageProvider(FabricDataOutput, String, CompletableFuture)} FabricLanguageProvider} to declare what language code is being generated if it isn't {@code en_us}.
*
* <p>Register an instance of the class with {@link FabricDataGenerator.Pack#addProvider} in a {@link net.fabricmc.fabric.api.datagen.v1.DataGeneratorEntrypoint}.
*/
public abstract class FabricLanguageProvider implements DataProvider {
protected final FabricDataOutput dataOutput;
private final String languageCode;
private final CompletableFuture<RegistryWrapper.WrapperLookup> registryLookup;

protected FabricLanguageProvider(FabricDataOutput dataOutput) {
this(dataOutput, "en_us");
protected FabricLanguageProvider(FabricDataOutput dataOutput, CompletableFuture<RegistryWrapper.WrapperLookup> registryLookup) {
this(dataOutput, "en_us", registryLookup);
}

protected FabricLanguageProvider(FabricDataOutput dataOutput, String languageCode) {
protected FabricLanguageProvider(FabricDataOutput dataOutput, String languageCode, CompletableFuture<RegistryWrapper.WrapperLookup> registryLookup) {
this.dataOutput = dataOutput;
this.languageCode = languageCode;
this.registryLookup = registryLookup;
}

/**
* Implement this method to register languages.
*
* <p>Call {@link TranslationBuilder#add(String, String)} to add a translation.
*/
public abstract void generateTranslations(TranslationBuilder translationBuilder);
public abstract void generateTranslations(RegistryWrapper.WrapperLookup registryLookup, TranslationBuilder translationBuilder);

@Override
public CompletableFuture<?> run(DataWriter writer) {
TreeMap<String, String> translationEntries = new TreeMap<>();

generateTranslations((String key, String value) -> {
Objects.requireNonNull(key);
Objects.requireNonNull(value);
return this.registryLookup.thenCompose(lookup -> {
generateTranslations(lookup, (String key, String value) -> {
Objects.requireNonNull(key);
Objects.requireNonNull(value);

if (translationEntries.containsKey(key)) {
throw new RuntimeException("Existing translation key found - " + key + " - Duplicate will be ignored.");
}
if (translationEntries.containsKey(key)) {
throw new RuntimeException("Existing translation key found - " + key + " - Duplicate will be ignored.");
}

translationEntries.put(key, value);
});
translationEntries.put(key, value);
});

JsonObject langEntryJson = new JsonObject();
JsonObject langEntryJson = new JsonObject();

for (Map.Entry<String, String> entry : translationEntries.entrySet()) {
langEntryJson.addProperty(entry.getKey(), entry.getValue());
}
for (Map.Entry<String, String> entry : translationEntries.entrySet()) {
langEntryJson.addProperty(entry.getKey(), entry.getValue());
}

return DataProvider.writeToPath(writer, langEntryJson, getLangFilePath(this.languageCode));
return DataProvider.writeToPath(writer, langEntryJson, getLangFilePath(this.languageCode));
});
}

private Path getLangFilePath(String code) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public void accept(Identifier recipeId, Recipe<?> recipe, @Nullable AdvancementE
throw new IllegalStateException("Duplicate recipe " + identifier);
}

RegistryOps<JsonElement> registryOps = wrapperLookup.method_57093(JsonOps.INSTANCE);
RegistryOps<JsonElement> registryOps = wrapperLookup.getOps(JsonOps.INSTANCE);
JsonObject recipeJson = Util.getResult(Recipe.CODEC.encodeStart(registryOps, recipe), IllegalStateException::new).getAsJsonObject();
ConditionJsonProvider[] conditions = FabricDataGenHelper.consumeConditions(recipe);
ConditionJsonProvider.write(recipeJson, conditions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public FabricTagProvider(FabricDataOutput output, RegistryKey<? extends Registry
/**
* Implement this method and then use {@link FabricTagProvider#getOrCreateTagBuilder} to get and register new tag builders.
*/
protected abstract void configure(RegistryWrapper.WrapperLookup arg);
protected abstract void configure(RegistryWrapper.WrapperLookup wrapperLookup);

/**
* Override to enable adding objects to the tag builder directly.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,17 @@ public static CompletableFuture<?> run(
HashMap<Identifier, LootTable> builders = Maps.newHashMap();
HashMap<Identifier, ConditionJsonProvider[]> conditionMap = new HashMap<>();

provider.accept((identifier, builder) -> {
ConditionJsonProvider[] conditions = FabricDataGenHelper.consumeConditions(builder);
conditionMap.put(identifier, conditions);
return registryLookup.thenApply(lookup -> {
provider.accept(lookup, (identifier, builder) -> {
ConditionJsonProvider[] conditions = FabricDataGenHelper.consumeConditions(builder);
conditionMap.put(identifier, conditions);

if (builders.put(identifier, builder.type(lootContextType).build()) != null) {
throw new IllegalStateException("Duplicate loot table " + identifier);
}
});
if (builders.put(identifier, builder.type(lootContextType).build()) != null) {
throw new IllegalStateException("Duplicate loot table " + identifier);
}
});

return registryLookup.thenCompose(lookup -> {
RegistryOps<JsonElement> ops = lookup.method_57093(JsonOps.INSTANCE);
RegistryOps<JsonElement> ops = lookup.getOps(JsonOps.INSTANCE);
final List<CompletableFuture<?>> futures = new ArrayList<>();

for (Map.Entry<Identifier, LootTable> entry : builders.entrySet()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ transitive-accessible method net/minecraft/data/server/loottable/BlockLootTableG
transitive-accessible method net/minecraft/data/client/ItemModelGenerator register (Lnet/minecraft/item/Item;Lnet/minecraft/data/client/Model;)V
transitive-accessible method net/minecraft/data/client/ItemModelGenerator register (Lnet/minecraft/item/Item;Ljava/lang/String;Lnet/minecraft/data/client/Model;)V
transitive-accessible method net/minecraft/data/client/ItemModelGenerator register (Lnet/minecraft/item/Item;Lnet/minecraft/item/Item;Lnet/minecraft/data/client/Model;)V
transitive-accessible method net/minecraft/data/client/ItemModelGenerator registerWolfArmor (Lnet/minecraft/item/Item;)V
transitive-accessible method net/minecraft/data/client/ItemModelGenerator registerCompass (Lnet/minecraft/item/Item;)V
transitive-accessible method net/minecraft/data/client/ItemModelGenerator registerClock (Lnet/minecraft/item/Item;)V
transitive-accessible method net/minecraft/data/client/ItemModelGenerator uploadArmor (Lnet/minecraft/util/Identifier;Lnet/minecraft/util/Identifier;Lnet/minecraft/util/Identifier;)V
Expand All @@ -322,6 +323,7 @@ transitive-extendable method net/minecraft/data/dev/NbtProvider getName ()Ljava/
transitive-extendable method net/minecraft/data/report/BlockListProvider getName ()Ljava/lang/String;
transitive-extendable method net/minecraft/data/report/CommandSyntaxProvider getName ()Ljava/lang/String;
transitive-extendable method net/minecraft/data/report/DynamicRegistriesProvider getName ()Ljava/lang/String;
transitive-extendable method net/minecraft/data/report/ItemListProvider getName ()Ljava/lang/String;
transitive-extendable method net/minecraft/data/report/RegistryDumpProvider getName ()Ljava/lang/String;
transitive-extendable method net/minecraft/data/server/BiomeParametersProvider getName ()Ljava/lang/String;
transitive-extendable method net/minecraft/data/server/advancement/AdvancementProvider getName ()Ljava/lang/String;
Expand Down
Loading

0 comments on commit 1172e89

Please sign in to comment.