Skip to content

Commit

Permalink
Update to 24w21b
Browse files Browse the repository at this point in the history
  • Loading branch information
DrexHD committed May 24, 2024
1 parent 5dd087a commit 0cc1d37
Show file tree
Hide file tree
Showing 12 changed files with 58 additions and 78 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Done to increase the memory available to gradle.
org.gradle.jvmargs=-Xmx1G
# Fabric Properties
minecraft_version=24w18a
minecraft_version=24w21b
loader_version=0.15.11
# Mod Properties
mod_version=4.1.2
maven_group=me.drex
archives_base_name=villagerconfig
# Dependencies
fabric_version=0.97.8+1.20.6
fabric_version=0.99.0+1.21
mod_menu_version=10.0.0-beta.1
cloth_config_version=14.0.125
fiber_version=0.23.0-2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class ConfigScreen {
public static Screen getConfigScreen(Screen parentScreen) {
ConfigBuilder builder = ConfigBuilder.create()
.setParentScreen(parentScreen)
.setDefaultBackgroundTexture(new ResourceLocation("minecraft:textures/block/emerald_block.png"))
.setDefaultBackgroundTexture(ResourceLocation.parse("minecraft:textures/block/emerald_block.png"))
.setTitle(Component.translatable("config.villagerconfig.title"));

builder.setGlobalized(true);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package me.drex.villagerconfig.mixin.loot;

import com.google.common.collect.BiMap;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.storage.loot.parameters.LootContextParamSet;
import net.minecraft.world.level.storage.loot.parameters.LootContextParamSets;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Invoker;

import java.util.function.Consumer;
import org.spongepowered.asm.mixin.gen.Accessor;

@Mixin(LootContextParamSets.class)
public interface LootContextParamSetsAccessor {

@Invoker
static LootContextParamSet invokeRegister(String name, Consumer<LootContextParamSet.Builder> type) {
@Accessor
static BiMap<ResourceLocation, LootContextParamSet> getREGISTRY() {
throw new AssertionError();
}

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,6 @@ protected void apply(Map<ResourceLocation, JsonElement> prepared, @NotNull Resou

@Override
public ResourceLocation getFabricId() {
return new ResourceLocation(VillagerConfig.MOD_ID, "trades");
return ResourceLocation.fromNamespaceAndPath(VillagerConfig.MOD_ID, "trades");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public class TradeProvider implements DataProvider {
private final PackOutput.PathProvider pathResolver;
private final MinecraftServer server;
private final boolean experimental;
public static final ResourceLocation WANDERING_TRADER_ID = new ResourceLocation("wanderingtrader");
public static final ResourceLocation WANDERING_TRADER_ID = ResourceLocation.withDefaultNamespace("wanderingtrader");
private static final IntUnaryOperator WANDERING_TRADER_COUNT = i -> switch (i) {
case 1 -> 5;
case 2 -> 1;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
package me.drex.villagerconfig.util.loot;

import me.drex.villagerconfig.mixin.loot.LootItemFunctionsAccessor;
import com.mojang.serialization.MapCodec;
import me.drex.villagerconfig.util.loot.function.EnchantRandomlyLootFunction;
import me.drex.villagerconfig.util.loot.function.SetDyeFunction;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.storage.loot.functions.LootItemFunction;
import net.minecraft.world.level.storage.loot.functions.LootItemFunctionType;

import static me.drex.villagerconfig.VillagerConfig.modId;
import static me.drex.villagerconfig.VillagerConfig.MOD_ID;

public class LootItemFunctionTypes {

public static final LootItemFunctionType SET_DYE = LootItemFunctionsAccessor.invokeRegister(modId("set_dye"), SetDyeFunction.CODEC);
public static final LootItemFunctionType ENCHANT_RANDOMLY = LootItemFunctionsAccessor.invokeRegister(modId("enchant_randomly"), EnchantRandomlyLootFunction.CODEC);
public static final LootItemFunctionType<SetDyeFunction> SET_DYE = register("set_dye", SetDyeFunction.CODEC);
public static final LootItemFunctionType<EnchantRandomlyLootFunction> ENCHANT_RANDOMLY = register("enchant_randomly", EnchantRandomlyLootFunction.CODEC);

public static void init() {
}

private static <T extends LootItemFunction> LootItemFunctionType<T> register(String string, MapCodec<T> mapCodec) {
return Registry.register(BuiltInRegistries.LOOT_FUNCTION_TYPE, ResourceLocation.fromNamespaceAndPath(MOD_ID, string), new LootItemFunctionType<>(mapCodec));
}

}
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
package me.drex.villagerconfig.util.loot;

import me.drex.villagerconfig.mixin.loot.NumberProvidersAccessor;
import com.mojang.serialization.MapCodec;
import me.drex.villagerconfig.util.loot.number.AddLootNumberProvider;
import me.drex.villagerconfig.util.loot.number.MultiplyLootNumberProvider;
import me.drex.villagerconfig.util.loot.number.ReferenceLootNumberProvider;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.storage.loot.providers.number.LootNumberProviderType;
import net.minecraft.world.level.storage.loot.providers.number.NumberProvider;

import static me.drex.villagerconfig.VillagerConfig.modId;
import static me.drex.villagerconfig.VillagerConfig.MOD_ID;

public class LootNumberProviderTypes {

public static final LootNumberProviderType REFERENCE = NumberProvidersAccessor.invokeRegister(modId("reference"), ReferenceLootNumberProvider.CODEC);
public static final LootNumberProviderType ADD = NumberProvidersAccessor.invokeRegister(modId("add"), AddLootNumberProvider.CODEC);
public static final LootNumberProviderType MUL = NumberProvidersAccessor.invokeRegister(modId("multiply"), MultiplyLootNumberProvider.CODEC);
public static final LootNumberProviderType REFERENCE = register("reference", ReferenceLootNumberProvider.CODEC);
public static final LootNumberProviderType ADD = register("add", AddLootNumberProvider.CODEC);
public static final LootNumberProviderType MUL = register("multiply", MultiplyLootNumberProvider.CODEC);

public static void init() {
}

private static LootNumberProviderType register(String string, MapCodec<? extends NumberProvider> mapCodec) {
return Registry.register(BuiltInRegistries.LOOT_NUMBER_PROVIDER_TYPE, ResourceLocation.fromNamespaceAndPath(MOD_ID, string), new LootNumberProviderType(mapCodec));
}

}
Original file line number Diff line number Diff line change
@@ -1,21 +1,40 @@
package me.drex.villagerconfig.util.loot;

import me.drex.villagerconfig.mixin.loot.LootContextParamSetsAccessor;
import me.drex.villagerconfig.mixin.loot.LootContextParamsAccessor;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.storage.loot.parameters.LootContextParam;
import net.minecraft.world.level.storage.loot.parameters.LootContextParamSet;
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;

import java.util.Map;
import java.util.function.Consumer;

import static me.drex.villagerconfig.VillagerConfig.modId;
import static me.drex.villagerconfig.VillagerConfig.MOD_ID;

public class VCLootContextParams {

public static final LootContextParam<Map<String, Float>> NUMBER_REFERENCE = LootContextParamsAccessor.invokeCreate(modId("number_reference"));
public static final LootContextParamSet VILLAGER_LOOT_CONTEXT = LootContextParamSetsAccessor.invokeRegister("villager", builder -> builder.required(LootContextParams.ORIGIN).required(LootContextParams.THIS_ENTITY).required(NUMBER_REFERENCE));
public static final LootContextParam<Map<String, Float>> NUMBER_REFERENCE = create("number_reference");
public static final LootContextParamSet VILLAGER_LOOT_CONTEXT = register("villager", builder -> new LootContextParamSet.Builder().required(LootContextParams.ORIGIN).required(LootContextParams.THIS_ENTITY).required(NUMBER_REFERENCE));

public static void init() {
}

private static <T> LootContextParam<T> create(String string) {
return new LootContextParam<>(ResourceLocation.fromNamespaceAndPath(MOD_ID, string));
}

private static LootContextParamSet register(String string, Consumer<LootContextParamSet.Builder> consumer) {
// [VanillaCopy] - LootContextParamSets.register
LootContextParamSet.Builder builder = new LootContextParamSet.Builder();
consumer.accept(builder);
LootContextParamSet lootContextParamSet = builder.build();
ResourceLocation resourceLocation = ResourceLocation.fromNamespaceAndPath(MOD_ID, string); // ResourceLocation.withDefaultNamespace -> ResourceLocation.fromNamespaceAndPath
LootContextParamSet lootContextParamSet2 = LootContextParamSetsAccessor.getREGISTRY().put(resourceLocation, lootContextParamSet);
if (lootContextParamSet2 != null) {
throw new IllegalStateException("Loot table parameter set " + resourceLocation + " is already registered");
} else {
return lootContextParamSet;
}
}

}
3 changes: 0 additions & 3 deletions src/main/resources/villagerconfig.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,9 @@
"VillagerMixin",
"WanderingTraderMixin",
"ZombieMixin",
"loot.LootContextParamsAccessor",
"loot.LootContextParamSetsAccessor",
"loot.LootContextParamSetsMixin",
"loot.LootItemFunctionsAccessor",
"loot.LootItemFunctionsMixin",
"loot.NumberProvidersAccessor",
"loot.NumberProvidersMixin"
],
"injectors": {
Expand Down

0 comments on commit 0cc1d37

Please sign in to comment.