mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-27 15:17:59 +01:00
Datagen is working! \0/
This commit is contained in:
parent
236cc9a921
commit
2c626b4376
15 changed files with 641 additions and 309 deletions
|
@ -3,6 +3,7 @@ package com.minelittlepony.unicopia.datagen;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
|
import java.util.function.Consumer;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
|
@ -26,6 +27,11 @@ public class DataCollector {
|
||||||
return values.containsKey(id);
|
return values.containsKey(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public <T extends Supplier<JsonElement>> Consumer<T> prime(BiConsumer<T, BiConsumer<Identifier, Supplier<JsonElement>>> converter) {
|
||||||
|
var consumer = prime();
|
||||||
|
return element -> converter.accept(element, consumer);
|
||||||
|
}
|
||||||
|
|
||||||
public BiConsumer<Identifier, Supplier<JsonElement>> prime() {
|
public BiConsumer<Identifier, Supplier<JsonElement>> prime() {
|
||||||
values.clear();
|
values.clear();
|
||||||
return (Identifier id, Supplier<JsonElement> value) ->
|
return (Identifier id, Supplier<JsonElement> value) ->
|
||||||
|
@ -39,4 +45,8 @@ public class DataCollector {
|
||||||
.toArray(CompletableFuture[]::new)
|
.toArray(CompletableFuture[]::new)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public interface Identifiable {
|
||||||
|
Identifier getId();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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<T> implements BootstrapFunction<T> {
|
||||||
|
|
||||||
|
private final RegistryKey<Registry<T>> registryRef;
|
||||||
|
private final List<RegistryKey<T>> keys = new ArrayList<>();
|
||||||
|
|
||||||
|
public DataGenRegistryProvider(RegistryKey<Registry<T>> registryRef) {
|
||||||
|
this.registryRef = registryRef;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final void addToPack(Pack pack) {
|
||||||
|
pack.addProvider(this::createDataGenerator);
|
||||||
|
pack.addProvider(this::createTagProvider);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected List<RegistryKey<T>> getKeys() {
|
||||||
|
return keys;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract void configureTags(TagProvider tagProvider, WrapperLookup lookup);
|
||||||
|
|
||||||
|
public FabricDynamicRegistryProvider createDataGenerator(FabricDataOutput output, CompletableFuture<WrapperLookup> 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<T>() {
|
||||||
|
@Override
|
||||||
|
public Reference<T> register(RegistryKey<T> key, T value, Lifecycle lifecycle) {
|
||||||
|
keys.add(key);
|
||||||
|
entries.add(key, value);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <S> RegistryEntryLookup<S> getRegistryLookup(RegistryKey<? extends Registry<? extends S>> registryRef) {
|
||||||
|
return registries.getWrapperOrThrow(registryRef);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public FabricTagProvider<T> createTagProvider(FabricDataOutput output, CompletableFuture<WrapperLookup> registriesFuture) {
|
||||||
|
return new TagProvider(output, registriesFuture);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected class TagProvider extends FabricTagProvider<T> {
|
||||||
|
public TagProvider(FabricDataOutput output, CompletableFuture<WrapperLookup> registriesFuture) {
|
||||||
|
super(output, DataGenRegistryProvider.this.registryRef, registriesFuture);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FabricTagBuilder getOrCreateTagBuilder(TagKey<T> tag) {
|
||||||
|
return super.getOrCreateTagBuilder(tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void configure(WrapperLookup lookup) {
|
||||||
|
DataGenRegistryProvider.this.configureTags(this, lookup);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,10 +3,10 @@ package com.minelittlepony.unicopia.datagen;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
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.DietsProvider;
|
||||||
import com.minelittlepony.unicopia.datagen.providers.SeasonsGrowthRatesProvider;
|
import com.minelittlepony.unicopia.datagen.providers.SeasonsGrowthRatesProvider;
|
||||||
import com.minelittlepony.unicopia.datagen.providers.UAdvancementsProvider;
|
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.UJukeboxSongProvider;
|
||||||
import com.minelittlepony.unicopia.datagen.providers.UModelProvider;
|
import com.minelittlepony.unicopia.datagen.providers.UModelProvider;
|
||||||
import com.minelittlepony.unicopia.datagen.providers.UPaintingVariantProvider;
|
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.UChestLootTableProvider;
|
||||||
import com.minelittlepony.unicopia.datagen.providers.loot.UEntityAdditionsLootTableProvider;
|
import com.minelittlepony.unicopia.datagen.providers.loot.UEntityAdditionsLootTableProvider;
|
||||||
import com.minelittlepony.unicopia.datagen.providers.loot.UEntityLootTableProvider;
|
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.recipe.URecipeProvider;
|
||||||
import com.minelittlepony.unicopia.datagen.providers.tag.UBlockTagProvider;
|
import com.minelittlepony.unicopia.datagen.providers.tag.UBlockTagProvider;
|
||||||
import com.minelittlepony.unicopia.datagen.providers.tag.UDamageTypeProvider;
|
import com.minelittlepony.unicopia.datagen.providers.tag.UDamageTypeProvider;
|
||||||
import com.minelittlepony.unicopia.datagen.providers.tag.UDimensionTypeTagProvider;
|
import com.minelittlepony.unicopia.datagen.providers.tag.UDimensionTypeTagProvider;
|
||||||
import com.minelittlepony.unicopia.datagen.providers.tag.UEntityTypeTagProvider;
|
import com.minelittlepony.unicopia.datagen.providers.tag.UEntityTypeTagProvider;
|
||||||
import com.minelittlepony.unicopia.datagen.providers.tag.UItemTagProvider;
|
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.datagen.providers.tag.UStatusEffectTagProvider;
|
||||||
import com.minelittlepony.unicopia.entity.damage.UDamageTypes;
|
import com.minelittlepony.unicopia.entity.damage.UDamageTypes;
|
||||||
import com.minelittlepony.unicopia.server.world.UWorldGen;
|
import com.minelittlepony.unicopia.server.world.UWorldGen;
|
||||||
|
|
||||||
import net.fabricmc.fabric.api.datagen.v1.DataGeneratorEntrypoint;
|
import net.fabricmc.fabric.api.datagen.v1.DataGeneratorEntrypoint;
|
||||||
import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator;
|
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.RegistryBuilder;
|
||||||
import net.minecraft.registry.RegistryKeys;
|
import net.minecraft.registry.RegistryKeys;
|
||||||
import net.minecraft.util.Identifier;
|
|
||||||
|
|
||||||
public class Datagen implements DataGeneratorEntrypoint {
|
public class Datagen implements DataGeneratorEntrypoint {
|
||||||
public static final Logger LOGGER = LogManager.getLogger();
|
public static final Logger LOGGER = LogManager.getLogger();
|
||||||
|
|
||||||
public static Block getOrCreateBaleBlock(Identifier id) {
|
private final UPaintingVariantProvider paintingVariants = new UPaintingVariantProvider();
|
||||||
return Registries.BLOCK.getOrEmpty(id).orElseGet(() -> {
|
private final UEnchantmentProvider enchantments = new UEnchantmentProvider();
|
||||||
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()));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onInitializeDataGenerator(FabricDataGenerator fabricDataGenerator) {
|
public void onInitializeDataGenerator(FabricDataGenerator fabricDataGenerator) {
|
||||||
|
@ -64,8 +48,8 @@ public class Datagen implements DataGeneratorEntrypoint {
|
||||||
pack.addProvider(UStatusEffectTagProvider::new);
|
pack.addProvider(UStatusEffectTagProvider::new);
|
||||||
pack.addProvider(UDimensionTypeTagProvider::new);
|
pack.addProvider(UDimensionTypeTagProvider::new);
|
||||||
|
|
||||||
final var paintingVariantProvider = pack.addProvider(UPaintingVariantProvider::new);
|
paintingVariants.addToPack(pack);
|
||||||
pack.addProvider((output, registries) -> new UPaintingVariantTagProvider(output, registries, paintingVariantProvider));
|
enchantments.addToPack(pack);
|
||||||
|
|
||||||
pack.addProvider(UJukeboxSongProvider::new);
|
pack.addProvider(UJukeboxSongProvider::new);
|
||||||
pack.addProvider(UModelProvider::new);
|
pack.addProvider(UModelProvider::new);
|
||||||
|
@ -82,8 +66,9 @@ public class Datagen implements DataGeneratorEntrypoint {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void buildRegistry(RegistryBuilder builder) {
|
public void buildRegistry(RegistryBuilder builder) {
|
||||||
CuttingBoardRecipeJsonBuilder.CuttingBoardRecipe.bootstrap();
|
|
||||||
builder.addRegistry(RegistryKeys.BIOME, UWorldGen.REGISTRY);
|
builder.addRegistry(RegistryKeys.BIOME, UWorldGen.REGISTRY);
|
||||||
builder.addRegistry(RegistryKeys.DAMAGE_TYPE, UDamageTypes.REGISTRY);
|
builder.addRegistry(RegistryKeys.DAMAGE_TYPE, UDamageTypes.REGISTRY);
|
||||||
|
builder.addRegistry(RegistryKeys.PAINTING_VARIANT, paintingVariants);
|
||||||
|
builder.addRegistry(RegistryKeys.ENCHANTMENT, enchantments);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 <T> RegistryEntry<T> entryOf(RegistryKey<Registry<T>> registry, Identifier value, T dummyValue) {
|
||||||
|
final Registry<T> registryRef = Untyped.cast(Registries.REGISTRIES.get(registry.getValue()));
|
||||||
|
class Entry extends RegistryEntry.Reference<T> {
|
||||||
|
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<IndirectMultipartBlockStateSupplier.Multipart> 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<BlockStateVariant> 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<BlockStateVariant> 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<BlockStateVariant> 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<JsonElement> {
|
||||||
|
private final List<BlockStateVariant> variants;
|
||||||
|
|
||||||
|
Multipart(List<BlockStateVariant> 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -8,7 +8,6 @@ import java.util.function.Supplier;
|
||||||
|
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
import com.minelittlepony.unicopia.Unicopia;
|
import com.minelittlepony.unicopia.Unicopia;
|
||||||
import com.minelittlepony.unicopia.block.EdibleBlock;
|
|
||||||
import com.minelittlepony.unicopia.block.FruitBearingBlock;
|
import com.minelittlepony.unicopia.block.FruitBearingBlock;
|
||||||
import com.minelittlepony.unicopia.block.PieBlock;
|
import com.minelittlepony.unicopia.block.PieBlock;
|
||||||
import com.minelittlepony.unicopia.block.PileBlock;
|
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.SlimePustuleBlock;
|
||||||
import com.minelittlepony.unicopia.block.UBlocks;
|
import com.minelittlepony.unicopia.block.UBlocks;
|
||||||
import com.minelittlepony.unicopia.block.zap.ZapAppleLeavesBlock;
|
import com.minelittlepony.unicopia.block.zap.ZapAppleLeavesBlock;
|
||||||
import com.minelittlepony.unicopia.datagen.Datagen;
|
|
||||||
import com.minelittlepony.unicopia.datagen.UBlockFamilies;
|
import com.minelittlepony.unicopia.datagen.UBlockFamilies;
|
||||||
import com.minelittlepony.unicopia.server.world.Tree;
|
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.Properties;
|
||||||
import net.minecraft.state.property.Property;
|
import net.minecraft.state.property.Property;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
import net.minecraft.util.Pair;
|
|
||||||
import net.minecraft.util.StringIdentifiable;
|
import net.minecraft.util.StringIdentifiable;
|
||||||
import net.minecraft.util.math.Direction;
|
import net.minecraft.util.math.Direction;
|
||||||
|
|
||||||
|
@ -164,12 +161,6 @@ public class UBlockStateModelGenerator extends BlockStateModelGenerator {
|
||||||
// fruit
|
// fruit
|
||||||
UModelProvider.FRUITS.forEach((block, item) -> registerSingleton(block, TextureMap.cross(ModelIds.getItemModelId(item)), BlockModels.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
|
// shells
|
||||||
registerAll(UBlockStateModelGenerator::registerShell, UBlocks.CLAM_SHELL, UBlocks.TURRET_SHELL, UBlocks.SCALLOP_SHELL);
|
registerAll(UBlockStateModelGenerator::registerShell, UBlocks.CLAM_SHELL, UBlocks.TURRET_SHELL, UBlocks.SCALLOP_SHELL);
|
||||||
// other
|
// 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);
|
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<Integer, Identifier> 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<Integer> ageProperty, BlockModels.Factory modelFactory, int ... stages) {
|
public void registerWithStages(Block crop, Property<Integer> ageProperty, BlockModels.Factory modelFactory, int ... stages) {
|
||||||
if (ageProperty.getValues().size() != stages.length) {
|
if (ageProperty.getValues().size() != stages.length) {
|
||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException();
|
||||||
|
|
|
@ -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<Enchantment> {
|
||||||
|
public UEnchantmentProvider() {
|
||||||
|
super(RegistryKeys.ENCHANTMENT);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run(Registerable<Enchantment> 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<Enchantment> registry, RegistryKey<Enchantment> 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
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -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<BlockStateSupplier> 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<Integer, Identifier> 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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -36,15 +36,22 @@ public class UModelProvider extends FabricModelProvider {
|
||||||
);
|
);
|
||||||
|
|
||||||
private final DataCollector seasonsModels;
|
private final DataCollector seasonsModels;
|
||||||
|
private final DataCollector indirectBlockStatesDefinitions;
|
||||||
|
|
||||||
public UModelProvider(FabricDataOutput output) {
|
public UModelProvider(FabricDataOutput output) {
|
||||||
super(output);
|
super(output);
|
||||||
seasonsModels = new DataCollector(output.getResolver(DataOutput.OutputType.RESOURCE_PACK, "seasons/models"));
|
seasonsModels = new DataCollector(output.getResolver(DataOutput.OutputType.RESOURCE_PACK, "seasons/models"));
|
||||||
|
indirectBlockStatesDefinitions = new DataCollector(output.getResolver(DataOutput.OutputType.RESOURCE_PACK, "blockstates"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void generateBlockStateModels(BlockStateModelGenerator modelGenerator0) {
|
public void generateBlockStateModels(BlockStateModelGenerator modelGenerator0) {
|
||||||
UBlockStateModelGenerator.create(modelGenerator0).register();
|
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();
|
new SeasonsModelGenerator(modelGenerator0, seasonsModels.prime()).register();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,6 +59,7 @@ public class UModelProvider extends FabricModelProvider {
|
||||||
public CompletableFuture<?> run(DataWriter writer) {
|
public CompletableFuture<?> run(DataWriter writer) {
|
||||||
return CompletableFuture.allOf(
|
return CompletableFuture.allOf(
|
||||||
super.run(writer),
|
super.run(writer),
|
||||||
|
indirectBlockStatesDefinitions.upload(writer),
|
||||||
seasonsModels.upload(writer)
|
seasonsModels.upload(writer)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,60 +1,49 @@
|
||||||
package com.minelittlepony.unicopia.datagen.providers;
|
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.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.entity.decoration.painting.PaintingVariant;
|
||||||
|
import net.minecraft.registry.Registerable;
|
||||||
import net.minecraft.registry.RegistryKey;
|
import net.minecraft.registry.RegistryKey;
|
||||||
import net.minecraft.registry.RegistryKeys;
|
import net.minecraft.registry.RegistryKeys;
|
||||||
import net.minecraft.registry.RegistryWrapper.WrapperLookup;
|
import net.minecraft.registry.RegistryWrapper.WrapperLookup;
|
||||||
|
import net.minecraft.registry.tag.PaintingVariantTags;
|
||||||
|
|
||||||
public class UPaintingVariantProvider extends FabricDynamicRegistryProvider {
|
public class UPaintingVariantProvider extends DataGenRegistryProvider<PaintingVariant> {
|
||||||
|
public UPaintingVariantProvider() {
|
||||||
private final List<RegistryKey<PaintingVariant>> keys = new ArrayList<>();
|
super(RegistryKeys.PAINTING_VARIANT);
|
||||||
|
|
||||||
public UPaintingVariantProvider(FabricDataOutput output, CompletableFuture<WrapperLookup> registriesFuture) {
|
|
||||||
super(output, registriesFuture);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public void run(Registerable<PaintingVariant> registerable) {
|
||||||
return "Painting Variants";
|
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<RegistryKey<PaintingVariant>> getKeys() {
|
private void register(Registerable<PaintingVariant> registerable, String name, int width, int height) {
|
||||||
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) {
|
|
||||||
RegistryKey<PaintingVariant> key = RegistryKey.of(RegistryKeys.PAINTING_VARIANT, Unicopia.id(name));
|
RegistryKey<PaintingVariant> key = RegistryKey.of(RegistryKeys.PAINTING_VARIANT, Unicopia.id(name));
|
||||||
keys.add(key);
|
registerable.register(key, new PaintingVariant(width, height, key.getValue()));
|
||||||
entries.add(key, new PaintingVariant(width, height, key.getValue()));
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void configureTags(TagProvider tagProvider, WrapperLookup lookup) {
|
||||||
|
tagProvider.getOrCreateTagBuilder(PaintingVariantTags.PLACEABLE).add(getKeys());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@ package com.minelittlepony.unicopia.datagen.providers.loot;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
import com.minelittlepony.unicopia.Unicopia;
|
import com.minelittlepony.unicopia.Unicopia;
|
||||||
import com.minelittlepony.unicopia.block.EdibleBlock;
|
import com.minelittlepony.unicopia.block.EdibleBlock;
|
||||||
import com.minelittlepony.unicopia.block.EnchantedFruitBlock;
|
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.ShellsBlock;
|
||||||
import com.minelittlepony.unicopia.block.SlimePustuleBlock;
|
import com.minelittlepony.unicopia.block.SlimePustuleBlock;
|
||||||
import com.minelittlepony.unicopia.block.UBlocks;
|
import com.minelittlepony.unicopia.block.UBlocks;
|
||||||
import com.minelittlepony.unicopia.datagen.Datagen;
|
|
||||||
import com.minelittlepony.unicopia.datagen.providers.UModelProvider;
|
import com.minelittlepony.unicopia.datagen.providers.UModelProvider;
|
||||||
import com.minelittlepony.unicopia.item.UItems;
|
import com.minelittlepony.unicopia.item.UItems;
|
||||||
import com.minelittlepony.unicopia.server.world.Tree;
|
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.SCALLOP_SHELL, shellDrops(UBlocks.SCALLOP_SHELL, UItems.SCALLOP_SHELL));
|
||||||
addDrop(UBlocks.TURRET_SHELL, shellDrops(UBlocks.TURRET_SHELL, UItems.TURRET_SHELL));
|
addDrop(UBlocks.TURRET_SHELL, shellDrops(UBlocks.TURRET_SHELL, UItems.TURRET_SHELL));
|
||||||
|
|
||||||
var farmersDelightGenerator = withConditions(ResourceConditions.allModsLoaded("farmersdelight"));
|
var farmersDelightGenerator = new UExternalBlockLootTableProvider(lootTables, 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"))));
|
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) {
|
private void addTallCropDrops(SegmentedCropBlock baseCrop, ItemConvertible crop) {
|
||||||
|
|
|
@ -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<RegistryKey<LootTable>, LootTable.Builder> lootTables;
|
||||||
|
private final ResourceCondition[] conditions;
|
||||||
|
|
||||||
|
protected UExternalBlockLootTableProvider(Map<RegistryKey<LootTable>, LootTable.Builder> lootTables, ResourceCondition...conditions) {
|
||||||
|
this.lootTables = lootTables;
|
||||||
|
this.conditions = conditions;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addDrop(Identifier block, Function<Identifier, LootTable.Builder> drop) {
|
||||||
|
RegistryKey<LootTable> 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 extends LootConditionConsumingBuilder<T>> T applyStateCondition(Identifier block,
|
||||||
|
BooleanProperty property, boolean value, LootConditionConsumingBuilder<T> builder) {
|
||||||
|
RegistryEntry<Block> entry = IndirectionUtils.entryOf(RegistryKeys.BLOCK, block, UBlocks.HAY_BLOCK);
|
||||||
|
return builder.conditionally(() -> new BlockStatePropertyLootCondition(
|
||||||
|
entry,
|
||||||
|
StatePredicate.Builder.create().exactMatch(property, value).build())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -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<PaintingVariant> {
|
|
||||||
|
|
||||||
private final UPaintingVariantProvider provider;
|
|
||||||
|
|
||||||
public UPaintingVariantTagProvider(FabricDataOutput output, CompletableFuture<WrapperLookup> registriesFuture, UPaintingVariantProvider provider) {
|
|
||||||
super(output, RegistryKeys.PAINTING_VARIANT, registriesFuture);
|
|
||||||
this.provider = provider;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void configure(WrapperLookup lookup) {
|
|
||||||
getOrCreateTagBuilder(PaintingVariantTags.PLACEABLE).add(provider.getKeys());
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -2,26 +2,11 @@ package com.minelittlepony.unicopia.item.enchantment;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
import com.minelittlepony.unicopia.UTags;
|
|
||||||
import com.minelittlepony.unicopia.Unicopia;
|
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.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.Registry;
|
||||||
import net.minecraft.registry.RegistryKey;
|
import net.minecraft.registry.RegistryKey;
|
||||||
import net.minecraft.registry.RegistryKeys;
|
import net.minecraft.registry.RegistryKeys;
|
||||||
import net.minecraft.registry.tag.EnchantmentTags;
|
|
||||||
import net.minecraft.registry.tag.ItemTags;
|
|
||||||
|
|
||||||
public interface UEnchantments {
|
public interface UEnchantments {
|
||||||
List<RegistryKey<Enchantment>> REGISTRY = new ArrayList<>();
|
List<RegistryKey<Enchantment>> REGISTRY = new ArrayList<>();
|
||||||
|
@ -142,145 +127,5 @@ public interface UEnchantments {
|
||||||
|
|
||||||
static void bootstrap() {
|
static void bootstrap() {
|
||||||
UEnchantmentEffects.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<Item> 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
|
|
||||||
)));
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
|
|
||||||
import com.google.common.base.Suppliers;
|
import com.google.common.base.Suppliers;
|
||||||
|
import com.llamalad7.mixinextras.injector.ModifyReturnValue;
|
||||||
import com.minelittlepony.unicopia.entity.effect.FoodPoisoningStatusEffect;
|
import com.minelittlepony.unicopia.entity.effect.FoodPoisoningStatusEffect;
|
||||||
import com.minelittlepony.unicopia.item.DamageChecker;
|
import com.minelittlepony.unicopia.item.DamageChecker;
|
||||||
import com.minelittlepony.unicopia.item.ItemStackDuck;
|
import com.minelittlepony.unicopia.item.ItemStackDuck;
|
||||||
|
@ -68,38 +69,30 @@ abstract class MixinItemStack implements ItemStackDuck {
|
||||||
getTransientComponents().setCarrier(null);
|
getTransientComponents().setCarrier(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject(method = "takesDamageFrom", at = @At("HEAD"))
|
@ModifyReturnValue(method = "takesDamageFrom", at = @At("RETURN"))
|
||||||
private void onTakesDamageFrom(DamageSource source, CallbackInfoReturnable<Boolean> info) {
|
private boolean onTakesDamageFrom(boolean takesDamage, DamageSource source) {
|
||||||
ItemStack self = (ItemStack)(Object)this;
|
ItemStack self = (ItemStack)(Object)this;
|
||||||
if (self.getItem() instanceof DamageChecker checker) {
|
return self.getItem() instanceof DamageChecker checker ? checker.takesDamageFrom(source) : takesDamage;
|
||||||
info.setReturnValue(checker.takesDamageFrom(source));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Mixin(ComponentHolder.class)
|
@Mixin(ComponentHolder.class)
|
||||||
interface MixinComponentHolder {
|
interface MixinComponentHolder {
|
||||||
@Inject(method = "get", at = @At("RETURN"))
|
@ModifyReturnValue(method = "get", at = @At("RETURN"))
|
||||||
default <T> void unicopia_onGet(ComponentType<? extends T> type, CallbackInfoReturnable<T> info) {
|
default <T> T unicopia_onGet(T value, ComponentType<? extends T> type) {
|
||||||
Object o = this;
|
Object o = this;
|
||||||
if (o instanceof ItemStack stack) {
|
return o instanceof ItemStack stack ? ItemStackDuck.of(stack).getTransientComponents().get(type, stack, value) : value;
|
||||||
info.setReturnValue(ItemStackDuck.of(stack).getTransientComponents().get(type, stack, info.getReturnValue()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject(method = "getOrDefault", at = @At("RETURN"))
|
@ModifyReturnValue(method = "getOrDefault", at = @At("RETURN"))
|
||||||
default <T> void unicopia_onGetOrDefault(ComponentType<? extends T> type, T fallback, CallbackInfoReturnable<T> info) {
|
default <T> T unicopia_onGetOrDefault(T value, ComponentType<? extends T> type, T fallback) {
|
||||||
Object o = this;
|
Object o = this;
|
||||||
if (o instanceof ItemStack stack) {
|
return o instanceof ItemStack stack ? ItemStackDuck.of(stack).getTransientComponents().get(type, stack, value) : value;
|
||||||
info.setReturnValue(ItemStackDuck.of(stack).getTransientComponents().get(type, stack, info.getReturnValue()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject(method = "contains", at = @At("RETURN"))
|
@ModifyReturnValue(method = "contains", at = @At("RETURN"))
|
||||||
default void unicopia_onContains(ComponentType<?> type, CallbackInfoReturnable<Boolean> info) {
|
default boolean unicopia_onContains(boolean z, ComponentType<?> type) {
|
||||||
Object o = this;
|
Object o = this;
|
||||||
if (o instanceof ItemStack stack && ItemStackDuck.of(stack).getTransientComponents().get(type, stack, null) != null) {
|
return z || (o instanceof ItemStack stack && ItemStackDuck.of(stack).getTransientComponents().get(type, stack, null) != null);
|
||||||
info.setReturnValue(true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,11 +2,13 @@ package com.minelittlepony.unicopia.recipe;
|
||||||
|
|
||||||
import com.minelittlepony.unicopia.Unicopia;
|
import com.minelittlepony.unicopia.Unicopia;
|
||||||
import com.minelittlepony.unicopia.ability.magic.spell.crafting.*;
|
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.minelittlepony.unicopia.server.world.gen.ULootTableEntryType;
|
||||||
import com.mojang.serialization.Codec;
|
import com.mojang.serialization.Codec;
|
||||||
import com.mojang.serialization.DataResult;
|
import com.mojang.serialization.DataResult;
|
||||||
import com.mojang.serialization.MapCodec;
|
import com.mojang.serialization.MapCodec;
|
||||||
|
|
||||||
|
import net.fabricmc.loader.api.FabricLoader;
|
||||||
import net.minecraft.network.RegistryByteBuf;
|
import net.minecraft.network.RegistryByteBuf;
|
||||||
import net.minecraft.network.codec.PacketCodec;
|
import net.minecraft.network.codec.PacketCodec;
|
||||||
import net.minecraft.recipe.CuttingRecipe;
|
import net.minecraft.recipe.CuttingRecipe;
|
||||||
|
@ -18,6 +20,7 @@ import net.minecraft.recipe.SpecialRecipeSerializer;
|
||||||
import net.minecraft.recipe.StonecuttingRecipe;
|
import net.minecraft.recipe.StonecuttingRecipe;
|
||||||
import net.minecraft.registry.Registries;
|
import net.minecraft.registry.Registries;
|
||||||
import net.minecraft.registry.Registry;
|
import net.minecraft.registry.Registry;
|
||||||
|
import net.minecraft.util.Identifier;
|
||||||
import net.minecraft.util.collection.DefaultedList;
|
import net.minecraft.util.collection.DefaultedList;
|
||||||
|
|
||||||
public interface URecipes {
|
public interface URecipes {
|
||||||
|
@ -32,9 +35,9 @@ public interface URecipes {
|
||||||
return DataResult.success(DefaultedList.copyOf(Ingredient.EMPTY, ingredients2));
|
return DataResult.success(DefaultedList.copyOf(Ingredient.EMPTY, ingredients2));
|
||||||
}, DataResult::success);
|
}, DataResult::success);
|
||||||
|
|
||||||
RecipeType<SpellbookRecipe> SPELLBOOK = RecipeType.register("unicopia:spellbook");
|
RecipeType<SpellbookRecipe> SPELLBOOK = register("spellbook");
|
||||||
RecipeType<StonecuttingRecipe> CLOUD_SHAPING = RecipeType.register("unicopia:cloud_shaping");
|
RecipeType<StonecuttingRecipe> CLOUD_SHAPING = register("cloud_shaping");
|
||||||
RecipeType<TransformCropsRecipe> GROWING = RecipeType.register("unicopia:growing");
|
RecipeType<TransformCropsRecipe> GROWING = register("growing");
|
||||||
|
|
||||||
RecipeSerializer<ZapAppleRecipe> ZAP_APPLE_SERIALIZER = register("crafting_zap_apple", ZapAppleRecipe.CODEC, ZapAppleRecipe.PACKET_CODEC);
|
RecipeSerializer<ZapAppleRecipe> ZAP_APPLE_SERIALIZER = register("crafting_zap_apple", ZapAppleRecipe.CODEC, ZapAppleRecipe.PACKET_CODEC);
|
||||||
RecipeSerializer<GlowingRecipe> GLOWING_SERIALIZER = register("crafting_glowing", new SpecialRecipeSerializer<>(GlowingRecipe::new));
|
RecipeSerializer<GlowingRecipe> GLOWING_SERIALIZER = register("crafting_glowing", new SpecialRecipeSerializer<>(GlowingRecipe::new));
|
||||||
|
@ -47,6 +50,16 @@ public interface URecipes {
|
||||||
RecipeSerializer<CloudShapingRecipe> CLOUD_SHAPING_SERIALIZER = register("cloud_shaping", new CuttingRecipe.Serializer<>(CloudShapingRecipe::new) {});
|
RecipeSerializer<CloudShapingRecipe> CLOUD_SHAPING_SERIALIZER = register("cloud_shaping", new CuttingRecipe.Serializer<>(CloudShapingRecipe::new) {});
|
||||||
RecipeSerializer<TransformCropsRecipe> TRANSFORM_CROP_SERIALIZER = register("transform_crop", TransformCropsRecipe.CODEC, TransformCropsRecipe.PACKET_CODEC);
|
RecipeSerializer<TransformCropsRecipe> TRANSFORM_CROP_SERIALIZER = register("transform_crop", TransformCropsRecipe.CODEC, TransformCropsRecipe.PACKET_CODEC);
|
||||||
|
|
||||||
|
static <T extends Recipe<?>> RecipeType<T> register(String name) {
|
||||||
|
Identifier id = Unicopia.id(name);
|
||||||
|
return Registry.register(Registries.RECIPE_TYPE, id, new RecipeType<T>() {
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return id.toString();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
static <T extends Recipe<?>> RecipeSerializer<T> register(String name, MapCodec<T> codec, PacketCodec<RegistryByteBuf, T> packetCodec) {
|
static <T extends Recipe<?>> RecipeSerializer<T> register(String name, MapCodec<T> codec, PacketCodec<RegistryByteBuf, T> packetCodec) {
|
||||||
return register(name, new RecipeSerializer<>() {
|
return register(name, new RecipeSerializer<>() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -66,6 +79,9 @@ public interface URecipes {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void bootstrap() {
|
static void bootstrap() {
|
||||||
|
if (FabricLoader.getInstance().isDevelopmentEnvironment()) {
|
||||||
|
CuttingBoardRecipeJsonBuilder.CuttingBoardRecipe.bootstrap();
|
||||||
|
}
|
||||||
ULootTableEntryType.bootstrap();
|
ULootTableEntryType.bootstrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue