-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
58 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 5 additions & 5 deletions
10
src/main/java/me/drex/villagerconfig/mixin/loot/LootContextParamSetsAccessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 0 additions & 16 deletions
16
src/main/java/me/drex/villagerconfig/mixin/loot/LootContextParamsAccessor.java
This file was deleted.
Oops, something went wrong.
18 changes: 0 additions & 18 deletions
18
src/main/java/me/drex/villagerconfig/mixin/loot/LootItemFunctionsAccessor.java
This file was deleted.
Oops, something went wrong.
18 changes: 0 additions & 18 deletions
18
src/main/java/me/drex/villagerconfig/mixin/loot/NumberProvidersAccessor.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 12 additions & 4 deletions
16
src/main/java/me/drex/villagerconfig/util/loot/LootItemFunctionTypes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
|
||
} |
18 changes: 13 additions & 5 deletions
18
src/main/java/me/drex/villagerconfig/util/loot/LootNumberProviderTypes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
|
||
} |
27 changes: 23 additions & 4 deletions
27
src/main/java/me/drex/villagerconfig/util/loot/VCLootContextParams.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters