diff --git a/src/main/java/com/minelittlepony/unicopia/datagen/DataCollector.java b/src/main/java/com/minelittlepony/unicopia/datagen/DataCollector.java index 2dabd5cd..b2e086b3 100644 --- a/src/main/java/com/minelittlepony/unicopia/datagen/DataCollector.java +++ b/src/main/java/com/minelittlepony/unicopia/datagen/DataCollector.java @@ -3,6 +3,7 @@ package com.minelittlepony.unicopia.datagen; import java.util.HashMap; import java.util.concurrent.CompletableFuture; import java.util.function.BiConsumer; +import java.util.function.Consumer; import java.util.function.Supplier; import com.google.common.base.Preconditions; @@ -26,6 +27,11 @@ public class DataCollector { return values.containsKey(id); } + public > Consumer prime(BiConsumer>> converter) { + var consumer = prime(); + return element -> converter.accept(element, consumer); + } + public BiConsumer> prime() { values.clear(); return (Identifier id, Supplier value) -> @@ -39,4 +45,8 @@ public class DataCollector { .toArray(CompletableFuture[]::new) ); } + + public interface Identifiable { + Identifier getId(); + } } diff --git a/src/main/java/com/minelittlepony/unicopia/datagen/DataGenRegistryProvider.java b/src/main/java/com/minelittlepony/unicopia/datagen/DataGenRegistryProvider.java new file mode 100644 index 00000000..cc1c9115 --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/datagen/DataGenRegistryProvider.java @@ -0,0 +1,87 @@ +package com.minelittlepony.unicopia.datagen; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.CompletableFuture; + +import com.mojang.serialization.Lifecycle; + +import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput; +import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator.Pack; +import net.fabricmc.fabric.api.datagen.v1.provider.FabricDynamicRegistryProvider; +import net.fabricmc.fabric.api.datagen.v1.provider.FabricTagProvider; +import net.minecraft.registry.Registerable; +import net.minecraft.registry.Registry; +import net.minecraft.registry.RegistryBuilder.BootstrapFunction; +import net.minecraft.registry.RegistryEntryLookup; +import net.minecraft.registry.RegistryKey; +import net.minecraft.registry.RegistryWrapper.WrapperLookup; +import net.minecraft.registry.entry.RegistryEntry.Reference; +import net.minecraft.registry.tag.TagKey; + +public abstract class DataGenRegistryProvider implements BootstrapFunction { + + private final RegistryKey> registryRef; + private final List> keys = new ArrayList<>(); + + public DataGenRegistryProvider(RegistryKey> registryRef) { + this.registryRef = registryRef; + } + + public final void addToPack(Pack pack) { + pack.addProvider(this::createDataGenerator); + pack.addProvider(this::createTagProvider); + } + + protected List> getKeys() { + return keys; + } + + protected abstract void configureTags(TagProvider tagProvider, WrapperLookup lookup); + + public FabricDynamicRegistryProvider createDataGenerator(FabricDataOutput output, CompletableFuture registriesFuture) { + return new FabricDynamicRegistryProvider(output, registriesFuture) { + @Override + public String getName() { + return "Unicopia Registry Data Gen " + registryRef.getValue(); + } + + @Override + protected void configure(WrapperLookup registries, Entries entries) { + DataGenRegistryProvider.this.run(new Registerable() { + @Override + public Reference register(RegistryKey key, T value, Lifecycle lifecycle) { + keys.add(key); + entries.add(key, value); + return null; + } + + @Override + public RegistryEntryLookup getRegistryLookup(RegistryKey> registryRef) { + return registries.getWrapperOrThrow(registryRef); + } + }); + } + }; + } + + public FabricTagProvider createTagProvider(FabricDataOutput output, CompletableFuture registriesFuture) { + return new TagProvider(output, registriesFuture); + } + + protected class TagProvider extends FabricTagProvider { + public TagProvider(FabricDataOutput output, CompletableFuture registriesFuture) { + super(output, DataGenRegistryProvider.this.registryRef, registriesFuture); + } + + @Override + public FabricTagBuilder getOrCreateTagBuilder(TagKey tag) { + return super.getOrCreateTagBuilder(tag); + } + + @Override + protected void configure(WrapperLookup lookup) { + DataGenRegistryProvider.this.configureTags(this, lookup); + } + } +} diff --git a/src/main/java/com/minelittlepony/unicopia/datagen/Datagen.java b/src/main/java/com/minelittlepony/unicopia/datagen/Datagen.java index 6d669289..929a3182 100644 --- a/src/main/java/com/minelittlepony/unicopia/datagen/Datagen.java +++ b/src/main/java/com/minelittlepony/unicopia/datagen/Datagen.java @@ -3,10 +3,10 @@ package com.minelittlepony.unicopia.datagen; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import com.minelittlepony.unicopia.block.EdibleBlock; import com.minelittlepony.unicopia.datagen.providers.DietsProvider; import com.minelittlepony.unicopia.datagen.providers.SeasonsGrowthRatesProvider; import com.minelittlepony.unicopia.datagen.providers.UAdvancementsProvider; +import com.minelittlepony.unicopia.datagen.providers.UEnchantmentProvider; import com.minelittlepony.unicopia.datagen.providers.UJukeboxSongProvider; import com.minelittlepony.unicopia.datagen.providers.UModelProvider; import com.minelittlepony.unicopia.datagen.providers.UPaintingVariantProvider; @@ -16,42 +16,26 @@ import com.minelittlepony.unicopia.datagen.providers.loot.UChestAdditionsLootTab import com.minelittlepony.unicopia.datagen.providers.loot.UChestLootTableProvider; import com.minelittlepony.unicopia.datagen.providers.loot.UEntityAdditionsLootTableProvider; import com.minelittlepony.unicopia.datagen.providers.loot.UEntityLootTableProvider; -import com.minelittlepony.unicopia.datagen.providers.recipe.CuttingBoardRecipeJsonBuilder; import com.minelittlepony.unicopia.datagen.providers.recipe.URecipeProvider; import com.minelittlepony.unicopia.datagen.providers.tag.UBlockTagProvider; import com.minelittlepony.unicopia.datagen.providers.tag.UDamageTypeProvider; import com.minelittlepony.unicopia.datagen.providers.tag.UDimensionTypeTagProvider; import com.minelittlepony.unicopia.datagen.providers.tag.UEntityTypeTagProvider; import com.minelittlepony.unicopia.datagen.providers.tag.UItemTagProvider; -import com.minelittlepony.unicopia.datagen.providers.tag.UPaintingVariantTagProvider; import com.minelittlepony.unicopia.datagen.providers.tag.UStatusEffectTagProvider; import com.minelittlepony.unicopia.entity.damage.UDamageTypes; import com.minelittlepony.unicopia.server.world.UWorldGen; import net.fabricmc.fabric.api.datagen.v1.DataGeneratorEntrypoint; import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator; -import net.minecraft.block.Block; -import net.minecraft.item.Item; -import net.minecraft.registry.Registries; -import net.minecraft.registry.Registry; import net.minecraft.registry.RegistryBuilder; import net.minecraft.registry.RegistryKeys; -import net.minecraft.util.Identifier; public class Datagen implements DataGeneratorEntrypoint { public static final Logger LOGGER = LogManager.getLogger(); - public static Block getOrCreateBaleBlock(Identifier id) { - return Registries.BLOCK.getOrEmpty(id).orElseGet(() -> { - return Registry.register(Registries.BLOCK, id, new EdibleBlock(id, id, false)); - }); - } - - public static Item getOrCreateItem(Identifier id) { - return Registries.ITEM.getOrEmpty(id).orElseGet(() -> { - return Registry.register(Registries.ITEM, id, new Item(new Item.Settings())); - }); - } + private final UPaintingVariantProvider paintingVariants = new UPaintingVariantProvider(); + private final UEnchantmentProvider enchantments = new UEnchantmentProvider(); @Override public void onInitializeDataGenerator(FabricDataGenerator fabricDataGenerator) { @@ -64,8 +48,8 @@ public class Datagen implements DataGeneratorEntrypoint { pack.addProvider(UStatusEffectTagProvider::new); pack.addProvider(UDimensionTypeTagProvider::new); - final var paintingVariantProvider = pack.addProvider(UPaintingVariantProvider::new); - pack.addProvider((output, registries) -> new UPaintingVariantTagProvider(output, registries, paintingVariantProvider)); + paintingVariants.addToPack(pack); + enchantments.addToPack(pack); pack.addProvider(UJukeboxSongProvider::new); pack.addProvider(UModelProvider::new); @@ -82,8 +66,9 @@ public class Datagen implements DataGeneratorEntrypoint { @Override public void buildRegistry(RegistryBuilder builder) { - CuttingBoardRecipeJsonBuilder.CuttingBoardRecipe.bootstrap(); builder.addRegistry(RegistryKeys.BIOME, UWorldGen.REGISTRY); builder.addRegistry(RegistryKeys.DAMAGE_TYPE, UDamageTypes.REGISTRY); + builder.addRegistry(RegistryKeys.PAINTING_VARIANT, paintingVariants); + builder.addRegistry(RegistryKeys.ENCHANTMENT, enchantments); } } diff --git a/src/main/java/com/minelittlepony/unicopia/datagen/IndirectionUtils.java b/src/main/java/com/minelittlepony/unicopia/datagen/IndirectionUtils.java new file mode 100644 index 00000000..149e8f47 --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/datagen/IndirectionUtils.java @@ -0,0 +1,136 @@ +package com.minelittlepony.unicopia.datagen; + +import java.util.ArrayList; +import java.util.List; +import java.util.function.Supplier; + +import com.google.common.collect.ImmutableList; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.minelittlepony.unicopia.util.Untyped; + +import net.minecraft.block.Block; +import net.minecraft.data.client.BlockStateSupplier; +import net.minecraft.data.client.BlockStateVariant; +import net.minecraft.data.client.When; +import net.minecraft.registry.Registries; +import net.minecraft.registry.Registry; +import net.minecraft.registry.RegistryKey; +import net.minecraft.registry.entry.RegistryEntry; +import net.minecraft.state.StateManager; +import net.minecraft.util.Identifier; + +public interface IndirectionUtils { + + static RegistryEntry entryOf(RegistryKey> registry, Identifier value, T dummyValue) { + final Registry registryRef = Untyped.cast(Registries.REGISTRIES.get(registry.getValue())); + class Entry extends RegistryEntry.Reference { + Entry() { + super( + RegistryEntry.Reference.Type.STAND_ALONE, + registryRef.getEntryOwner(), + RegistryKey.of(registry, value), + dummyValue + ); + } + } + return new Entry(); + } + + static IndirectMultipartBlockStateSupplier multipartBlockStateSupplier(Identifier block) { + return new IndirectMultipartBlockStateSupplier(block); + } + + public class IndirectMultipartBlockStateSupplier implements BlockStateSupplier, DataCollector.Identifiable { + private final List multiparts = new ArrayList<>(); + + private final Identifier block; + + private IndirectMultipartBlockStateSupplier(Identifier block) { + this.block = block; + } + + @Override + public Block getBlock() { + throw new RuntimeException("Stub"); + } + + @Override + public Identifier getId() { + return block; + } + + public IndirectMultipartBlockStateSupplier with(List variants) { + this.multiparts.add(new IndirectMultipartBlockStateSupplier.Multipart(variants)); + return this; + } + + public IndirectMultipartBlockStateSupplier with(BlockStateVariant variant) { + return this.with(ImmutableList.of(variant)); + } + + public IndirectMultipartBlockStateSupplier with(When condition, List variants) { + this.multiparts.add(new IndirectMultipartBlockStateSupplier.ConditionalMultipart(condition, variants)); + return this; + } + + public IndirectMultipartBlockStateSupplier with(When condition, BlockStateVariant... variants) { + return this.with(condition, ImmutableList.copyOf(variants)); + } + + public IndirectMultipartBlockStateSupplier with(When condition, BlockStateVariant variant) { + return this.with(condition, ImmutableList.of(variant)); + } + + @Override + public JsonElement get() { + JsonArray jsonArray = new JsonArray(); + this.multiparts.stream().map(IndirectMultipartBlockStateSupplier.Multipart::get).forEach(jsonArray::add); + JsonObject jsonObject = new JsonObject(); + jsonObject.add("multipart", jsonArray); + return jsonObject; + } + + static class ConditionalMultipart extends IndirectMultipartBlockStateSupplier.Multipart { + private final When when; + + ConditionalMultipart(When when, List variants) { + super(variants); + this.when = when; + } + + @Override + public void validate(StateManager stateManager) { + this.when.validate(stateManager); + } + + @Override + public void extraToJson(JsonObject json) { + json.add("when", this.when.get()); + } + } + + static class Multipart implements Supplier { + private final List variants; + + Multipart(List variants) { + this.variants = variants; + } + + public void validate(StateManager stateManager) { + } + + public void extraToJson(JsonObject json) { + } + + @Override + public JsonElement get() { + JsonObject jsonObject = new JsonObject(); + this.extraToJson(jsonObject); + jsonObject.add("apply", BlockStateVariant.toJson(this.variants)); + return jsonObject; + } + } + } +} diff --git a/src/main/java/com/minelittlepony/unicopia/datagen/providers/UBlockStateModelGenerator.java b/src/main/java/com/minelittlepony/unicopia/datagen/providers/UBlockStateModelGenerator.java index 2a74f4dd..566c0c5a 100644 --- a/src/main/java/com/minelittlepony/unicopia/datagen/providers/UBlockStateModelGenerator.java +++ b/src/main/java/com/minelittlepony/unicopia/datagen/providers/UBlockStateModelGenerator.java @@ -8,7 +8,6 @@ import java.util.function.Supplier; import com.google.gson.JsonElement; import com.minelittlepony.unicopia.Unicopia; -import com.minelittlepony.unicopia.block.EdibleBlock; import com.minelittlepony.unicopia.block.FruitBearingBlock; import com.minelittlepony.unicopia.block.PieBlock; import com.minelittlepony.unicopia.block.PileBlock; @@ -16,7 +15,6 @@ import com.minelittlepony.unicopia.block.ShellsBlock; import com.minelittlepony.unicopia.block.SlimePustuleBlock; import com.minelittlepony.unicopia.block.UBlocks; import com.minelittlepony.unicopia.block.zap.ZapAppleLeavesBlock; -import com.minelittlepony.unicopia.datagen.Datagen; import com.minelittlepony.unicopia.datagen.UBlockFamilies; import com.minelittlepony.unicopia.server.world.Tree; @@ -48,7 +46,6 @@ import net.minecraft.state.property.EnumProperty; import net.minecraft.state.property.Properties; import net.minecraft.state.property.Property; import net.minecraft.util.Identifier; -import net.minecraft.util.Pair; import net.minecraft.util.StringIdentifiable; import net.minecraft.util.math.Direction; @@ -164,12 +161,6 @@ public class UBlockStateModelGenerator extends BlockStateModelGenerator { // fruit UModelProvider.FRUITS.forEach((block, item) -> registerSingleton(block, TextureMap.cross(ModelIds.getItemModelId(item)), BlockModels.FRUIT)); - // bales - registerAll((g, block) -> g.registerBale(Unicopia.id(block.getLeft().getPath().replace("bale", "block")), block.getLeft(), block.getRight()), - new Pair<>(Identifier.ofVanilla("hay_block"), "_top"), - new Pair<>(Identifier.of("farmersdelight", "rice_bale"), "_top"), - new Pair<>(Identifier.of("farmersdelight", "straw_bale"), "_end") - ); // shells registerAll(UBlockStateModelGenerator::registerShell, UBlocks.CLAM_SHELL, UBlocks.TURRET_SHELL, UBlocks.SCALLOP_SHELL); // other @@ -444,31 +435,6 @@ public class UBlockStateModelGenerator extends BlockStateModelGenerator { Models.CUBE_ALL.upload(ModelIds.getItemModelId(hive.asItem()), TextureMap.all(ModelIds.getBlockSubModelId(hive, "_side")), modelCollector); } - public void registerBale(Identifier blockId, Identifier baseBlockId, String endSuffex) { - Identifier top = baseBlockId.withPath(p -> "block/" + p + endSuffex); - Identifier side = baseBlockId.withPath(p -> "block/" + p + "_side"); - TextureMap textures = new TextureMap().put(TOP, top).put(SIDE, side); - - MultipartBlockStateSupplier supplier = MultipartBlockStateSupplier.create(Datagen.getOrCreateBaleBlock(blockId)); - Map uploadedModels = new HashMap<>(); - - for (Direction.Axis axis : Direction.Axis.VALUES) { - for (int i = 0; i < EdibleBlock.SEGMENTS.length; i++) { - BooleanProperty segment = EdibleBlock.SEGMENTS[i]; - segment.getName(); - supplier.with(When.create().set(EdibleBlock.AXIS, axis).set(segment, true), BlockStateVariant.create() - .put(MODEL, uploadedModels.computeIfAbsent(i, ii -> { - return BlockModels.BALE_MODELS[ii].getLeft().upload(blockId.withPath(p -> "block/" + p + BlockModels.BALE_MODELS[ii].getRight()), textures, modelCollector); - })) - .put(X, axis == Direction.Axis.Y ? R0 : R90) - .put(Y, axis == Direction.Axis.X ? R90 : R0) - ); - } - } - - blockStateCollector.accept(supplier); - } - public void registerWithStages(Block crop, Property ageProperty, BlockModels.Factory modelFactory, int ... stages) { if (ageProperty.getValues().size() != stages.length) { throw new IllegalArgumentException(); diff --git a/src/main/java/com/minelittlepony/unicopia/datagen/providers/UEnchantmentProvider.java b/src/main/java/com/minelittlepony/unicopia/datagen/providers/UEnchantmentProvider.java new file mode 100644 index 00000000..e75de143 --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/datagen/providers/UEnchantmentProvider.java @@ -0,0 +1,193 @@ +package com.minelittlepony.unicopia.datagen.providers; + +import java.util.Optional; +import com.minelittlepony.unicopia.UTags; +import com.minelittlepony.unicopia.Unicopia; +import com.minelittlepony.unicopia.datagen.DataGenRegistryProvider; +import com.minelittlepony.unicopia.entity.mob.UEntityAttributes; +import com.minelittlepony.unicopia.item.enchantment.AmbientSoundsEnchantmentEffect; +import com.minelittlepony.unicopia.item.enchantment.DangerSensingEnchantmentEffect; +import com.minelittlepony.unicopia.item.enchantment.GroupBasedAttributeEnchantmentEffect; +import com.minelittlepony.unicopia.item.enchantment.ParticleTrailEnchantmentEntityEffect; +import com.minelittlepony.unicopia.item.enchantment.Rarity; +import com.minelittlepony.unicopia.item.enchantment.UEnchantments; +import net.minecraft.component.EnchantmentEffectComponentTypes; +import net.minecraft.component.type.AttributeModifierSlot; +import net.minecraft.enchantment.Enchantment; +import net.minecraft.enchantment.EnchantmentLevelBasedValue; +import net.minecraft.enchantment.effect.AttributeEnchantmentEffect; +import net.minecraft.entity.attribute.EntityAttributeModifier; +import net.minecraft.entity.attribute.EntityAttributes; +import net.minecraft.entity.attribute.EntityAttributeModifier.Operation; +import net.minecraft.registry.Registerable; +import net.minecraft.registry.RegistryKey; +import net.minecraft.registry.RegistryKeys; +import net.minecraft.registry.RegistryWrapper.WrapperLookup; +import net.minecraft.registry.tag.EnchantmentTags; +import net.minecraft.registry.tag.ItemTags; + +public class UEnchantmentProvider extends DataGenRegistryProvider { + public UEnchantmentProvider() { + super(RegistryKeys.ENCHANTMENT); + } + + @Override + public void run(Registerable registry) { + var items = registry.getRegistryLookup(RegistryKeys.ITEM); + var enchantments = registry.getRegistryLookup(RegistryKeys.ENCHANTMENT); + + register(registry, UEnchantments.GEM_FINDER, Enchantment.builder(Enchantment.definition( + items.getOrThrow(ItemTags.MINING_ENCHANTABLE), + Rarity.RARE, + 3, + Enchantment.constantCost(1), Enchantment.constantCost(41), + 4, + AttributeModifierSlot.HAND + ))); + + register(registry, UEnchantments.PADDED, Enchantment.builder(Enchantment.definition( + items.getOrThrow(ItemTags.HEAD_ARMOR_ENCHANTABLE), + Rarity.UNCOMMON, + 3, + Enchantment.constantCost(1), Enchantment.constantCost(41), + 4, + AttributeModifierSlot.ARMOR + ))); + register(registry, UEnchantments.FEATHER_TOUCH, Enchantment.builder(Enchantment.definition( + items.getOrThrow(ItemTags.MINING_ENCHANTABLE), + Rarity.UNCOMMON, + 1, + Enchantment.constantCost(1), Enchantment.constantCost(31), + 3, + AttributeModifierSlot.HAND + ))); + register(registry, UEnchantments.HEAVY, Enchantment.builder( + Enchantment.definition( + items.getOrThrow(ItemTags.ARMOR_ENCHANTABLE), + Rarity.RARE, + 4, + Enchantment.constantCost(7), Enchantment.constantCost(23), + 2, + AttributeModifierSlot.ARMOR + ) + ).exclusiveSet(enchantments.getOrThrow(EnchantmentTags.ARMOR_EXCLUSIVE_SET)) + .addEffect(EnchantmentEffectComponentTypes.ATTRIBUTES, new AttributeEnchantmentEffect( + Unicopia.id("enchantment.heaviness"), + EntityAttributes.GENERIC_MOVEMENT_SPEED, + EnchantmentLevelBasedValue.linear(-0.1F, -0.1F), + EntityAttributeModifier.Operation.ADD_MULTIPLIED_TOTAL + ) + )); + register(registry, UEnchantments.HERDS, Enchantment.builder( + Enchantment.definition( + items.getOrThrow(ItemTags.WEAPON_ENCHANTABLE), + Rarity.RARE, + 3, + Enchantment.constantCost(8), Enchantment.constantCost(20), + 1, + AttributeModifierSlot.MAINHAND + ) + ).addEffect(EnchantmentEffectComponentTypes.TICK, new GroupBasedAttributeEnchantmentEffect(new AttributeEnchantmentEffect( + Unicopia.id("enchantment.team.strength"), + EntityAttributes.GENERIC_ATTACK_DAMAGE, + EnchantmentLevelBasedValue.linear(0, 1), + Operation.ADD_VALUE + ), EnchantmentLevelBasedValue.linear(2, 2)))); + + register(registry, UEnchantments.REPULSION, Enchantment.builder( + Enchantment.definition( + items.getOrThrow(ItemTags.FOOT_ARMOR_ENCHANTABLE), + Rarity.VERY_RARE, + 3, + Enchantment.constantCost(9), Enchantment.constantCost(28), + 3, + AttributeModifierSlot.FEET + ) + ).exclusiveSet(enchantments.getOrThrow(EnchantmentTags.ARMOR_EXCLUSIVE_SET)) + .addEffect(EnchantmentEffectComponentTypes.ATTRIBUTES, new AttributeEnchantmentEffect( + Unicopia.id("enchantment.repulsion"), + UEntityAttributes.ENTITY_GRAVITY_MODIFIER, + EnchantmentLevelBasedValue.linear(-0.5F, -0.375F), + EntityAttributeModifier.Operation.ADD_MULTIPLIED_TOTAL + ) + )); + + register(registry, UEnchantments.WANT_IT_NEED_IT, Enchantment.builder(Enchantment.definition( + items.getOrThrow(ItemTags.VANISHING_ENCHANTABLE), + Rarity.VERY_RARE, + 1, + Enchantment.constantCost(2), Enchantment.constantCost(10), + 4, + AttributeModifierSlot.ANY + )).addEffect(EnchantmentEffectComponentTypes.TICK, new ParticleTrailEnchantmentEntityEffect(Optional.empty(), 0.2F, 1, 10))); + + register(registry, UEnchantments.POISONED_JOKE, Enchantment.builder(Enchantment.definition( + items.getOrThrow(ItemTags.VANISHING_ENCHANTABLE), + Rarity.VERY_RARE, + 1, + Enchantment.constantCost(2), Enchantment.constantCost(10), + 4, + AttributeModifierSlot.ANY + )).addEffect(EnchantmentEffectComponentTypes.TICK, new AmbientSoundsEnchantmentEffect(Unicopia.id("poisoned_joke_level"), UTags.Sounds.POISON_JOKE_EVENTS))); + + register(registry, UEnchantments.STRESSED, Enchantment.builder(Enchantment.definition( + items.getOrThrow(ItemTags.VANISHING_ENCHANTABLE), + Rarity.VERY_RARE, + 3, + Enchantment.constantCost(2), Enchantment.constantCost(12), + 4, + AttributeModifierSlot.ANY + )).addEffect(EnchantmentEffectComponentTypes.TICK, DangerSensingEnchantmentEffect.INSTANCE)); + + register(registry, UEnchantments.CLINGY, Enchantment.builder(Enchantment.definition( + items.getOrThrow(ItemTags.EQUIPPABLE_ENCHANTABLE), + Rarity.VERY_RARE, + 6, + Enchantment.constantCost(2), Enchantment.constantCost(12), + 1, + AttributeModifierSlot.ANY + ))); + + register(registry, UEnchantments.HEART_BOUND, Enchantment.builder(Enchantment.definition( + items.getOrThrow(ItemTags.VANISHING_ENCHANTABLE), + Rarity.UNCOMMON, + 5, + Enchantment.constantCost(6), Enchantment.constantCost(41), + 3, + AttributeModifierSlot.ANY + ))); + + register(registry, UEnchantments.CONSUMPTION, Enchantment.builder(Enchantment.definition( + items.getOrThrow(ItemTags.MINING_ENCHANTABLE), + Rarity.VERY_RARE, + 1, + Enchantment.constantCost(10), Enchantment.constantCost(71), + 5, + AttributeModifierSlot.MAINHAND + ))); + } + + static void register(Registerable registry, RegistryKey key, Enchantment.Builder builder) { + registry.register(key, builder.build(key.getValue())); + } + + @Override + protected void configureTags(TagProvider tagProvider, WrapperLookup lookup) { + tagProvider.getOrCreateTagBuilder(EnchantmentTags.IN_ENCHANTING_TABLE).add( + UEnchantments.GEM_FINDER, UEnchantments.PADDED, UEnchantments.FEATHER_TOUCH, + UEnchantments.HEAVY, UEnchantments.HERDS, UEnchantments.CLINGY, UEnchantments.HEART_BOUND, + UEnchantments.CONSUMPTION + ); + tagProvider.getOrCreateTagBuilder(EnchantmentTags.TRADEABLE).add( + UEnchantments.GEM_FINDER, UEnchantments.PADDED, UEnchantments.FEATHER_TOUCH, + UEnchantments.HEAVY, UEnchantments.HERDS, UEnchantments.REPULSION, UEnchantments.WANT_IT_NEED_IT, + UEnchantments.POISONED_JOKE, UEnchantments.STRESSED, UEnchantments.CLINGY, UEnchantments.CONSUMPTION + ); + tagProvider.getOrCreateTagBuilder(EnchantmentTags.NON_TREASURE).add( + UEnchantments.FEATHER_TOUCH, UEnchantments.HEAVY, UEnchantments.POISONED_JOKE + ); + tagProvider.getOrCreateTagBuilder(EnchantmentTags.CURSE).add( + UEnchantments.WANT_IT_NEED_IT, UEnchantments.POISONED_JOKE, UEnchantments.STRESSED + ); + } +} diff --git a/src/main/java/com/minelittlepony/unicopia/datagen/providers/UExternalBlockStateModelGenerator.java b/src/main/java/com/minelittlepony/unicopia/datagen/providers/UExternalBlockStateModelGenerator.java new file mode 100644 index 00000000..3c3309e0 --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/datagen/providers/UExternalBlockStateModelGenerator.java @@ -0,0 +1,70 @@ +package com.minelittlepony.unicopia.datagen.providers; + +import static net.minecraft.data.client.TextureKey.SIDE; +import static net.minecraft.data.client.TextureKey.TOP; +import static net.minecraft.data.client.VariantSettings.MODEL; +import static net.minecraft.data.client.VariantSettings.X; +import static net.minecraft.data.client.VariantSettings.Y; +import static net.minecraft.data.client.VariantSettings.Rotation.R0; +import static net.minecraft.data.client.VariantSettings.Rotation.R90; + +import java.util.HashMap; +import java.util.Map; +import java.util.function.Consumer; + +import com.minelittlepony.unicopia.Unicopia; +import com.minelittlepony.unicopia.block.EdibleBlock; +import com.minelittlepony.unicopia.datagen.IndirectionUtils; +import com.minelittlepony.unicopia.datagen.IndirectionUtils.IndirectMultipartBlockStateSupplier; + +import net.minecraft.data.client.BlockStateModelGenerator; +import net.minecraft.data.client.BlockStateSupplier; +import net.minecraft.data.client.BlockStateVariant; +import net.minecraft.data.client.TextureMap; +import net.minecraft.data.client.When; +import net.minecraft.state.property.BooleanProperty; +import net.minecraft.util.Identifier; +import net.minecraft.util.Pair; +import net.minecraft.util.math.Direction; + +public class UExternalBlockStateModelGenerator extends UBlockStateModelGenerator { + public UExternalBlockStateModelGenerator(BlockStateModelGenerator modelGenerator, Consumer blockStateCollector) { + super(blockStateCollector, modelGenerator.modelCollector, modelGenerator::excludeFromSimpleItemModelGeneration); + } + + @Override + public void register() { + // bales + registerAll((g, block) -> registerBale(Unicopia.id(block.getLeft().getPath().replace("bale", "block")), block.getLeft(), block.getRight()), + new Pair<>(Identifier.ofVanilla("hay_block"), "_top"), + new Pair<>(Identifier.of("farmersdelight", "rice_bale"), "_top"), + new Pair<>(Identifier.of("farmersdelight", "straw_bale"), "_end") + ); + } + + + public void registerBale(Identifier blockId, Identifier baseBlockId, String endSuffex) { + Identifier top = baseBlockId.withPath(p -> "block/" + p + endSuffex); + Identifier side = baseBlockId.withPath(p -> "block/" + p + "_side"); + TextureMap textures = new TextureMap().put(TOP, top).put(SIDE, side); + + IndirectMultipartBlockStateSupplier supplier = IndirectionUtils.multipartBlockStateSupplier(blockId); + Map uploadedModels = new HashMap<>(); + + for (Direction.Axis axis : Direction.Axis.VALUES) { + for (int i = 0; i < EdibleBlock.SEGMENTS.length; i++) { + BooleanProperty segment = EdibleBlock.SEGMENTS[i]; + segment.getName(); + supplier.with(When.create().set(EdibleBlock.AXIS, axis).set(segment, true), BlockStateVariant.create() + .put(MODEL, uploadedModels.computeIfAbsent(i, ii -> { + return BlockModels.BALE_MODELS[ii].getLeft().upload(blockId.withPath(p -> "block/" + p + BlockModels.BALE_MODELS[ii].getRight()), textures, modelCollector); + })) + .put(X, axis == Direction.Axis.Y ? R0 : R90) + .put(Y, axis == Direction.Axis.X ? R90 : R0) + ); + } + } + + blockStateCollector.accept(supplier); + } +} diff --git a/src/main/java/com/minelittlepony/unicopia/datagen/providers/UModelProvider.java b/src/main/java/com/minelittlepony/unicopia/datagen/providers/UModelProvider.java index 08eb9bf8..ed092815 100644 --- a/src/main/java/com/minelittlepony/unicopia/datagen/providers/UModelProvider.java +++ b/src/main/java/com/minelittlepony/unicopia/datagen/providers/UModelProvider.java @@ -36,15 +36,22 @@ public class UModelProvider extends FabricModelProvider { ); private final DataCollector seasonsModels; + private final DataCollector indirectBlockStatesDefinitions; public UModelProvider(FabricDataOutput output) { super(output); seasonsModels = new DataCollector(output.getResolver(DataOutput.OutputType.RESOURCE_PACK, "seasons/models")); + indirectBlockStatesDefinitions = new DataCollector(output.getResolver(DataOutput.OutputType.RESOURCE_PACK, "blockstates")); } @Override public void generateBlockStateModels(BlockStateModelGenerator modelGenerator0) { UBlockStateModelGenerator.create(modelGenerator0).register(); + new UExternalBlockStateModelGenerator(modelGenerator0, indirectBlockStatesDefinitions.prime((states, consumer) -> { + if (states instanceof DataCollector.Identifiable i) { + consumer.accept(i.getId(), states); + } + })).register(); new SeasonsModelGenerator(modelGenerator0, seasonsModels.prime()).register(); } @@ -52,6 +59,7 @@ public class UModelProvider extends FabricModelProvider { public CompletableFuture run(DataWriter writer) { return CompletableFuture.allOf( super.run(writer), + indirectBlockStatesDefinitions.upload(writer), seasonsModels.upload(writer) ); } diff --git a/src/main/java/com/minelittlepony/unicopia/datagen/providers/UPaintingVariantProvider.java b/src/main/java/com/minelittlepony/unicopia/datagen/providers/UPaintingVariantProvider.java index c76312df..1d4c3f2f 100644 --- a/src/main/java/com/minelittlepony/unicopia/datagen/providers/UPaintingVariantProvider.java +++ b/src/main/java/com/minelittlepony/unicopia/datagen/providers/UPaintingVariantProvider.java @@ -1,60 +1,49 @@ package com.minelittlepony.unicopia.datagen.providers; -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.CompletableFuture; - import com.minelittlepony.unicopia.Unicopia; +import com.minelittlepony.unicopia.datagen.DataGenRegistryProvider; -import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput; -import net.fabricmc.fabric.api.datagen.v1.provider.FabricDynamicRegistryProvider; import net.minecraft.entity.decoration.painting.PaintingVariant; +import net.minecraft.registry.Registerable; import net.minecraft.registry.RegistryKey; import net.minecraft.registry.RegistryKeys; import net.minecraft.registry.RegistryWrapper.WrapperLookup; +import net.minecraft.registry.tag.PaintingVariantTags; -public class UPaintingVariantProvider extends FabricDynamicRegistryProvider { - - private final List> keys = new ArrayList<>(); - - public UPaintingVariantProvider(FabricDataOutput output, CompletableFuture registriesFuture) { - super(output, registriesFuture); +public class UPaintingVariantProvider extends DataGenRegistryProvider { + public UPaintingVariantProvider() { + super(RegistryKeys.PAINTING_VARIANT); } @Override - public String getName() { - return "Painting Variants"; + public void run(Registerable registerable) { + register(registerable, "bloom", 2, 1); + register(registerable, "chicken", 2, 1); + register(registerable, "bells", 2, 1); + + register(registerable, "crystal", 3, 3); + register(registerable, "harmony", 3, 3); + + register(registerable, "equality", 2, 4); + register(registerable, "solar", 2, 4); + register(registerable, "lunar", 2, 4); + register(registerable, "platinum", 2, 4); + register(registerable, "hurricane", 2, 4); + register(registerable, "pudding", 2, 4); + register(registerable, "terra", 2, 4); + register(registerable, "equestria", 2, 4); + + register(registerable, "blossom", 2, 3); + register(registerable, "shadow", 2, 3); } - public List> getKeys() { - return keys; - } - - @Override - protected void configure(WrapperLookup registries, Entries entries) { - register(entries, "bloom", 2, 1); - register(entries, "chicken", 2, 1); - register(entries, "bells", 2, 1); - - register(entries, "crystal", 3, 3); - register(entries, "harmony", 3, 3); - - register(entries, "equality", 2, 4); - register(entries, "solar", 2, 4); - register(entries, "lunar", 2, 4); - register(entries, "platinum", 2, 4); - register(entries, "hurricane", 2, 4); - register(entries, "pudding", 2, 4); - register(entries, "terra", 2, 4); - register(entries, "equestria", 2, 4); - - register(entries, "blossom", 2, 3); - register(entries, "shadow", 2, 3); - } - - private void register(Entries entries, String name, int width, int height) { + private void register(Registerable registerable, String name, int width, int height) { RegistryKey key = RegistryKey.of(RegistryKeys.PAINTING_VARIANT, Unicopia.id(name)); - keys.add(key); - entries.add(key, new PaintingVariant(width, height, key.getValue())); + registerable.register(key, new PaintingVariant(width, height, key.getValue())); + } + + @Override + protected void configureTags(TagProvider tagProvider, WrapperLookup lookup) { + tagProvider.getOrCreateTagBuilder(PaintingVariantTags.PLACEABLE).add(getKeys()); } } diff --git a/src/main/java/com/minelittlepony/unicopia/datagen/providers/loot/UBlockLootTableProvider.java b/src/main/java/com/minelittlepony/unicopia/datagen/providers/loot/UBlockLootTableProvider.java index 247ac2ad..42abac5b 100644 --- a/src/main/java/com/minelittlepony/unicopia/datagen/providers/loot/UBlockLootTableProvider.java +++ b/src/main/java/com/minelittlepony/unicopia/datagen/providers/loot/UBlockLootTableProvider.java @@ -2,7 +2,6 @@ package com.minelittlepony.unicopia.datagen.providers.loot; import java.util.List; import java.util.concurrent.CompletableFuture; - import com.minelittlepony.unicopia.Unicopia; import com.minelittlepony.unicopia.block.EdibleBlock; import com.minelittlepony.unicopia.block.EnchantedFruitBlock; @@ -12,7 +11,6 @@ import com.minelittlepony.unicopia.block.SegmentedCropBlock; import com.minelittlepony.unicopia.block.ShellsBlock; import com.minelittlepony.unicopia.block.SlimePustuleBlock; import com.minelittlepony.unicopia.block.UBlocks; -import com.minelittlepony.unicopia.datagen.Datagen; import com.minelittlepony.unicopia.datagen.providers.UModelProvider; import com.minelittlepony.unicopia.item.UItems; import com.minelittlepony.unicopia.server.world.Tree; @@ -234,9 +232,10 @@ public class UBlockLootTableProvider extends FabricBlockLootTableProvider { addDrop(UBlocks.SCALLOP_SHELL, shellDrops(UBlocks.SCALLOP_SHELL, UItems.SCALLOP_SHELL)); addDrop(UBlocks.TURRET_SHELL, shellDrops(UBlocks.TURRET_SHELL, UItems.TURRET_SHELL)); - var farmersDelightGenerator = withConditions(ResourceConditions.allModsLoaded("farmersdelight")); - farmersDelightGenerator.addDrop(Datagen.getOrCreateBaleBlock(Unicopia.id("rice_block")), b -> edibleBlockDrops(b, Datagen.getOrCreateItem(Identifier.of("farmersdelight", "rice_panicle")))); - farmersDelightGenerator.addDrop(Datagen.getOrCreateBaleBlock(Unicopia.id("straw_block")), b -> edibleBlockDrops(b, Datagen.getOrCreateItem(Identifier.of("farmersdelight", "straw")))); + var farmersDelightGenerator = new UExternalBlockLootTableProvider(lootTables, ResourceConditions.allModsLoaded("farmersdelight")); + + farmersDelightGenerator.addDrop(Unicopia.id("rice_block"), b -> UExternalBlockLootTableProvider.edibleBlockDrops(b, Identifier.of("farmersdelight", "rice_panicle"))); + farmersDelightGenerator.addDrop(Unicopia.id("straw_block"), b -> UExternalBlockLootTableProvider.edibleBlockDrops(b, Identifier.of("farmersdelight", "straw"))); } private void addTallCropDrops(SegmentedCropBlock baseCrop, ItemConvertible crop) { diff --git a/src/main/java/com/minelittlepony/unicopia/datagen/providers/loot/UExternalBlockLootTableProvider.java b/src/main/java/com/minelittlepony/unicopia/datagen/providers/loot/UExternalBlockLootTableProvider.java new file mode 100644 index 00000000..7387ffcc --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/datagen/providers/loot/UExternalBlockLootTableProvider.java @@ -0,0 +1,62 @@ +package com.minelittlepony.unicopia.datagen.providers.loot; + +import java.util.Map; +import java.util.function.Function; + +import com.minelittlepony.unicopia.block.EdibleBlock; +import com.minelittlepony.unicopia.block.UBlocks; +import com.minelittlepony.unicopia.datagen.IndirectionUtils; + +import net.fabricmc.fabric.api.resource.conditions.v1.ResourceCondition; +import net.fabricmc.fabric.impl.datagen.FabricDataGenHelper; +import net.minecraft.block.Block; +import net.minecraft.loot.LootPool; +import net.minecraft.loot.LootTable; +import net.minecraft.loot.condition.BlockStatePropertyLootCondition; +import net.minecraft.loot.condition.LootConditionConsumingBuilder; +import net.minecraft.loot.condition.SurvivesExplosionLootCondition; +import net.minecraft.loot.entry.DynamicEntry; +import net.minecraft.predicate.StatePredicate; +import net.minecraft.registry.RegistryKey; +import net.minecraft.registry.RegistryKeys; +import net.minecraft.registry.entry.RegistryEntry; +import net.minecraft.state.property.BooleanProperty; +import net.minecraft.util.Identifier; + +public class UExternalBlockLootTableProvider { + private final Map, LootTable.Builder> lootTables; + private final ResourceCondition[] conditions; + + protected UExternalBlockLootTableProvider(Map, LootTable.Builder> lootTables, ResourceCondition...conditions) { + this.lootTables = lootTables; + this.conditions = conditions; + } + + public void addDrop(Identifier block, Function drop) { + RegistryKey key = RegistryKey.of(RegistryKeys.LOOT_TABLE, block.withPrefixedPath("blocks/")); + LootTable.Builder table = drop.apply(block); + FabricDataGenHelper.addConditions(table, conditions); + lootTables.put(key, table); + } + + public static LootTable.Builder edibleBlockDrops(Identifier block, Identifier drop) { + LootTable.Builder builder = LootTable.builder(); + for (BooleanProperty segment : EdibleBlock.SEGMENTS) { + builder + .pool(LootPool.builder() + .rolls(UBlockLootTableProvider.exactly(1)) + .with(applyStateCondition(block, segment, true, DynamicEntry.builder(drop))) + .conditionally(SurvivesExplosionLootCondition.builder())); + } + return builder; + } + + public static > T applyStateCondition(Identifier block, + BooleanProperty property, boolean value, LootConditionConsumingBuilder builder) { + RegistryEntry entry = IndirectionUtils.entryOf(RegistryKeys.BLOCK, block, UBlocks.HAY_BLOCK); + return builder.conditionally(() -> new BlockStatePropertyLootCondition( + entry, + StatePredicate.Builder.create().exactMatch(property, value).build()) + ); + } +} diff --git a/src/main/java/com/minelittlepony/unicopia/datagen/providers/tag/UPaintingVariantTagProvider.java b/src/main/java/com/minelittlepony/unicopia/datagen/providers/tag/UPaintingVariantTagProvider.java deleted file mode 100644 index ede22609..00000000 --- a/src/main/java/com/minelittlepony/unicopia/datagen/providers/tag/UPaintingVariantTagProvider.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.minelittlepony.unicopia.datagen.providers.tag; - -import java.util.concurrent.CompletableFuture; - -import com.minelittlepony.unicopia.datagen.providers.UPaintingVariantProvider; - -import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput; -import net.fabricmc.fabric.api.datagen.v1.provider.FabricTagProvider; -import net.minecraft.entity.decoration.painting.PaintingVariant; -import net.minecraft.registry.RegistryKeys; -import net.minecraft.registry.RegistryWrapper.WrapperLookup; -import net.minecraft.registry.tag.PaintingVariantTags; - -public class UPaintingVariantTagProvider extends FabricTagProvider { - - private final UPaintingVariantProvider provider; - - public UPaintingVariantTagProvider(FabricDataOutput output, CompletableFuture registriesFuture, UPaintingVariantProvider provider) { - super(output, RegistryKeys.PAINTING_VARIANT, registriesFuture); - this.provider = provider; - } - - @Override - protected void configure(WrapperLookup lookup) { - getOrCreateTagBuilder(PaintingVariantTags.PLACEABLE).add(provider.getKeys()); - } -} diff --git a/src/main/java/com/minelittlepony/unicopia/item/enchantment/UEnchantments.java b/src/main/java/com/minelittlepony/unicopia/item/enchantment/UEnchantments.java index 897a18bc..762b01d8 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/enchantment/UEnchantments.java +++ b/src/main/java/com/minelittlepony/unicopia/item/enchantment/UEnchantments.java @@ -2,26 +2,11 @@ package com.minelittlepony.unicopia.item.enchantment; import java.util.ArrayList; import java.util.List; -import java.util.Optional; - -import com.minelittlepony.unicopia.UTags; import com.minelittlepony.unicopia.Unicopia; -import com.minelittlepony.unicopia.entity.mob.UEntityAttributes; -import net.fabricmc.fabric.api.event.registry.DynamicRegistrySetupCallback; -import net.minecraft.component.EnchantmentEffectComponentTypes; -import net.minecraft.component.type.AttributeModifierSlot; import net.minecraft.enchantment.Enchantment; -import net.minecraft.enchantment.EnchantmentLevelBasedValue; -import net.minecraft.enchantment.effect.AttributeEnchantmentEffect; -import net.minecraft.entity.attribute.EntityAttributeModifier; -import net.minecraft.entity.attribute.EntityAttributes; -import net.minecraft.entity.attribute.EntityAttributeModifier.Operation; -import net.minecraft.item.Item; import net.minecraft.registry.Registry; import net.minecraft.registry.RegistryKey; import net.minecraft.registry.RegistryKeys; -import net.minecraft.registry.tag.EnchantmentTags; -import net.minecraft.registry.tag.ItemTags; public interface UEnchantments { List> REGISTRY = new ArrayList<>(); @@ -142,145 +127,5 @@ public interface UEnchantments { static void bootstrap() { UEnchantmentEffects.bootstrap(); - // Options.table -> EnchantmentTags.IN_ENCHANTING_TABLE - // Optiona.curse -> EnchantmentTags.CURSE - // Options.traded -> EnchantmentTags.TRADEABLE - - DynamicRegistrySetupCallback.EVENT.register(registries -> { - registries.getOptional(RegistryKeys.ENCHANTMENT).ifPresent(registry -> { - Registry items = registries.getOptional(RegistryKeys.ITEM).orElseThrow(); - - register(registry, GEM_FINDER, Enchantment.builder(Enchantment.definition( - items.getEntryList(ItemTags.MINING_ENCHANTABLE).orElseThrow(), - Rarity.RARE, - 3, - Enchantment.constantCost(1), Enchantment.constantCost(41), - 4, - AttributeModifierSlot.HAND - ))); - - register(registry, PADDED, Enchantment.builder(Enchantment.definition( - items.getEntryList(ItemTags.HEAD_ARMOR_ENCHANTABLE).orElseThrow(), - Rarity.UNCOMMON, - 3, - Enchantment.constantCost(1), Enchantment.constantCost(41), - 4, - AttributeModifierSlot.ARMOR - ))); - register(registry, FEATHER_TOUCH, Enchantment.builder(Enchantment.definition( - items.getEntryList(ItemTags.MINING_ENCHANTABLE).orElseThrow(), - Rarity.UNCOMMON, - 1, - Enchantment.constantCost(1), Enchantment.constantCost(31), - 3, - AttributeModifierSlot.HAND - ))); - register(registry, HEAVY, Enchantment.builder( - Enchantment.definition( - items.getEntryList(ItemTags.ARMOR_ENCHANTABLE).orElseThrow(), - Rarity.RARE, - 4, - Enchantment.constantCost(7), Enchantment.constantCost(23), - 2, - AttributeModifierSlot.ARMOR - ) - ).exclusiveSet(registry.getEntryList(EnchantmentTags.ARMOR_EXCLUSIVE_SET).orElseThrow()) - .addEffect(EnchantmentEffectComponentTypes.ATTRIBUTES, new AttributeEnchantmentEffect( - Unicopia.id("enchantment.heaviness"), - EntityAttributes.GENERIC_MOVEMENT_SPEED, - EnchantmentLevelBasedValue.linear(-0.1F, -0.1F), - EntityAttributeModifier.Operation.ADD_MULTIPLIED_TOTAL - ) - )); - register(registry, HERDS, Enchantment.builder( - Enchantment.definition( - items.getEntryList(ItemTags.WEAPON_ENCHANTABLE).orElseThrow(), - Rarity.RARE, - 3, - Enchantment.constantCost(8), Enchantment.constantCost(20), - 1, - AttributeModifierSlot.MAINHAND - ) - ).addEffect(EnchantmentEffectComponentTypes.TICK, new GroupBasedAttributeEnchantmentEffect(new AttributeEnchantmentEffect( - Unicopia.id("enchantment.team.strength"), - EntityAttributes.GENERIC_ATTACK_DAMAGE, - EnchantmentLevelBasedValue.linear(0, 1), - Operation.ADD_VALUE - ), EnchantmentLevelBasedValue.linear(2, 2)))); - - register(registry, REPULSION, Enchantment.builder( - Enchantment.definition( - items.getEntryList(ItemTags.FOOT_ARMOR_ENCHANTABLE).orElseThrow(), - Rarity.VERY_RARE, - 3, - Enchantment.constantCost(9), Enchantment.constantCost(28), - 3, - AttributeModifierSlot.FEET - ) - ).exclusiveSet(registry.getEntryList(EnchantmentTags.ARMOR_EXCLUSIVE_SET).orElseThrow()) - .addEffect(EnchantmentEffectComponentTypes.ATTRIBUTES, new AttributeEnchantmentEffect( - Unicopia.id("enchantment.repulsion"), - UEntityAttributes.ENTITY_GRAVITY_MODIFIER, - EnchantmentLevelBasedValue.linear(-0.5F, -0.375F), - EntityAttributeModifier.Operation.ADD_MULTIPLIED_TOTAL - ) - )); - - register(registry, WANT_IT_NEED_IT, Enchantment.builder(Enchantment.definition( - items.getEntryList(ItemTags.VANISHING_ENCHANTABLE).orElseThrow(), - Rarity.VERY_RARE, - 1, - Enchantment.constantCost(2), Enchantment.constantCost(10), - 4, - AttributeModifierSlot.ANY - )).addEffect(EnchantmentEffectComponentTypes.TICK, new ParticleTrailEnchantmentEntityEffect(Optional.empty(), 0.2F, 1, 10))); - - register(registry, POISONED_JOKE, Enchantment.builder(Enchantment.definition( - items.getEntryList(ItemTags.VANISHING_ENCHANTABLE).orElseThrow(), - Rarity.VERY_RARE, - 1, - Enchantment.constantCost(2), Enchantment.constantCost(10), - 4, - AttributeModifierSlot.ANY - )).addEffect(EnchantmentEffectComponentTypes.TICK, new AmbientSoundsEnchantmentEffect(Unicopia.id("poisoned_joke_level"), UTags.Sounds.POISON_JOKE_EVENTS))); - - register(registry, CLINGY, Enchantment.builder(Enchantment.definition( - items.getEntryList(ItemTags.VANISHING_ENCHANTABLE).orElseThrow(), - Rarity.VERY_RARE, - 3, - Enchantment.constantCost(2), Enchantment.constantCost(12), - 4, - AttributeModifierSlot.ANY - )).addEffect(EnchantmentEffectComponentTypes.TICK, DangerSensingEnchantmentEffect.INSTANCE)); - - register(registry, CLINGY, Enchantment.builder(Enchantment.definition( - items.getEntryList(ItemTags.EQUIPPABLE_ENCHANTABLE).orElseThrow(), - Rarity.VERY_RARE, - 6, - Enchantment.constantCost(2), Enchantment.constantCost(12), - 1, - AttributeModifierSlot.ANY - ))); - - register(registry, HEART_BOUND, Enchantment.builder(Enchantment.definition( - items.getEntryList(ItemTags.VANISHING_ENCHANTABLE).orElseThrow(), - Rarity.UNCOMMON, - 5, - Enchantment.constantCost(6), Enchantment.constantCost(41), - 3, - AttributeModifierSlot.ANY - ))); - - register(registry, CONSUMPTION, Enchantment.builder(Enchantment.definition( - items.getEntryList(ItemTags.MINING_ENCHANTABLE).orElseThrow(), - Rarity.VERY_RARE, - 1, - Enchantment.constantCost(10), Enchantment.constantCost(71), - 5, - AttributeModifierSlot.MAINHAND - ))); - }); - }); } - } diff --git a/src/main/java/com/minelittlepony/unicopia/mixin/MixinItemStack.java b/src/main/java/com/minelittlepony/unicopia/mixin/MixinItemStack.java index a0b3669b..12818c52 100644 --- a/src/main/java/com/minelittlepony/unicopia/mixin/MixinItemStack.java +++ b/src/main/java/com/minelittlepony/unicopia/mixin/MixinItemStack.java @@ -11,6 +11,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import com.google.common.base.Suppliers; +import com.llamalad7.mixinextras.injector.ModifyReturnValue; import com.minelittlepony.unicopia.entity.effect.FoodPoisoningStatusEffect; import com.minelittlepony.unicopia.item.DamageChecker; import com.minelittlepony.unicopia.item.ItemStackDuck; @@ -68,38 +69,30 @@ abstract class MixinItemStack implements ItemStackDuck { getTransientComponents().setCarrier(null); } - @Inject(method = "takesDamageFrom", at = @At("HEAD")) - private void onTakesDamageFrom(DamageSource source, CallbackInfoReturnable info) { + @ModifyReturnValue(method = "takesDamageFrom", at = @At("RETURN")) + private boolean onTakesDamageFrom(boolean takesDamage, DamageSource source) { ItemStack self = (ItemStack)(Object)this; - if (self.getItem() instanceof DamageChecker checker) { - info.setReturnValue(checker.takesDamageFrom(source)); - } + return self.getItem() instanceof DamageChecker checker ? checker.takesDamageFrom(source) : takesDamage; } } @Mixin(ComponentHolder.class) interface MixinComponentHolder { - @Inject(method = "get", at = @At("RETURN")) - default void unicopia_onGet(ComponentType type, CallbackInfoReturnable info) { + @ModifyReturnValue(method = "get", at = @At("RETURN")) + default T unicopia_onGet(T value, ComponentType type) { Object o = this; - if (o instanceof ItemStack stack) { - info.setReturnValue(ItemStackDuck.of(stack).getTransientComponents().get(type, stack, info.getReturnValue())); - } + return o instanceof ItemStack stack ? ItemStackDuck.of(stack).getTransientComponents().get(type, stack, value) : value; } - @Inject(method = "getOrDefault", at = @At("RETURN")) - default void unicopia_onGetOrDefault(ComponentType type, T fallback, CallbackInfoReturnable info) { + @ModifyReturnValue(method = "getOrDefault", at = @At("RETURN")) + default T unicopia_onGetOrDefault(T value, ComponentType type, T fallback) { Object o = this; - if (o instanceof ItemStack stack) { - info.setReturnValue(ItemStackDuck.of(stack).getTransientComponents().get(type, stack, info.getReturnValue())); - } + return o instanceof ItemStack stack ? ItemStackDuck.of(stack).getTransientComponents().get(type, stack, value) : value; } - @Inject(method = "contains", at = @At("RETURN")) - default void unicopia_onContains(ComponentType type, CallbackInfoReturnable info) { + @ModifyReturnValue(method = "contains", at = @At("RETURN")) + default boolean unicopia_onContains(boolean z, ComponentType type) { Object o = this; - if (o instanceof ItemStack stack && ItemStackDuck.of(stack).getTransientComponents().get(type, stack, null) != null) { - info.setReturnValue(true); - } + return z || (o instanceof ItemStack stack && ItemStackDuck.of(stack).getTransientComponents().get(type, stack, null) != null); } } diff --git a/src/main/java/com/minelittlepony/unicopia/recipe/URecipes.java b/src/main/java/com/minelittlepony/unicopia/recipe/URecipes.java index 401f17e8..cb976a12 100644 --- a/src/main/java/com/minelittlepony/unicopia/recipe/URecipes.java +++ b/src/main/java/com/minelittlepony/unicopia/recipe/URecipes.java @@ -2,11 +2,13 @@ package com.minelittlepony.unicopia.recipe; import com.minelittlepony.unicopia.Unicopia; import com.minelittlepony.unicopia.ability.magic.spell.crafting.*; +import com.minelittlepony.unicopia.datagen.providers.recipe.CuttingBoardRecipeJsonBuilder; import com.minelittlepony.unicopia.server.world.gen.ULootTableEntryType; import com.mojang.serialization.Codec; import com.mojang.serialization.DataResult; import com.mojang.serialization.MapCodec; +import net.fabricmc.loader.api.FabricLoader; import net.minecraft.network.RegistryByteBuf; import net.minecraft.network.codec.PacketCodec; import net.minecraft.recipe.CuttingRecipe; @@ -18,6 +20,7 @@ import net.minecraft.recipe.SpecialRecipeSerializer; import net.minecraft.recipe.StonecuttingRecipe; import net.minecraft.registry.Registries; import net.minecraft.registry.Registry; +import net.minecraft.util.Identifier; import net.minecraft.util.collection.DefaultedList; public interface URecipes { @@ -32,9 +35,9 @@ public interface URecipes { return DataResult.success(DefaultedList.copyOf(Ingredient.EMPTY, ingredients2)); }, DataResult::success); - RecipeType SPELLBOOK = RecipeType.register("unicopia:spellbook"); - RecipeType CLOUD_SHAPING = RecipeType.register("unicopia:cloud_shaping"); - RecipeType GROWING = RecipeType.register("unicopia:growing"); + RecipeType SPELLBOOK = register("spellbook"); + RecipeType CLOUD_SHAPING = register("cloud_shaping"); + RecipeType GROWING = register("growing"); RecipeSerializer ZAP_APPLE_SERIALIZER = register("crafting_zap_apple", ZapAppleRecipe.CODEC, ZapAppleRecipe.PACKET_CODEC); RecipeSerializer GLOWING_SERIALIZER = register("crafting_glowing", new SpecialRecipeSerializer<>(GlowingRecipe::new)); @@ -47,6 +50,16 @@ public interface URecipes { RecipeSerializer CLOUD_SHAPING_SERIALIZER = register("cloud_shaping", new CuttingRecipe.Serializer<>(CloudShapingRecipe::new) {}); RecipeSerializer TRANSFORM_CROP_SERIALIZER = register("transform_crop", TransformCropsRecipe.CODEC, TransformCropsRecipe.PACKET_CODEC); + static > RecipeType register(String name) { + Identifier id = Unicopia.id(name); + return Registry.register(Registries.RECIPE_TYPE, id, new RecipeType() { + @Override + public String toString() { + return id.toString(); + } + }); + } + static > RecipeSerializer register(String name, MapCodec codec, PacketCodec packetCodec) { return register(name, new RecipeSerializer<>() { @Override @@ -66,6 +79,9 @@ public interface URecipes { } static void bootstrap() { + if (FabricLoader.getInstance().isDevelopmentEnvironment()) { + CuttingBoardRecipeJsonBuilder.CuttingBoardRecipe.bootstrap(); + } ULootTableEntryType.bootstrap(); } } \ No newline at end of file