1.19.2 -> 1.19.3 (1.20) [part 2]

This commit is contained in:
Sollace 2022-12-18 23:12:49 +00:00
parent c9c463d6c9
commit 68df426f37
19 changed files with 264 additions and 191 deletions

View file

@ -9,7 +9,7 @@ import org.spongepowered.include.com.google.common.base.Objects;
import com.google.common.base.Strings; import com.google.common.base.Strings;
import com.minelittlepony.unicopia.ability.magic.Affine; import com.minelittlepony.unicopia.ability.magic.Affine;
import com.minelittlepony.unicopia.util.Registries; import com.minelittlepony.unicopia.util.RegistryUtils;
import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.exceptions.DynamicCommandExceptionType; import com.mojang.brigadier.exceptions.DynamicCommandExceptionType;
@ -24,7 +24,7 @@ import net.minecraft.registry.RegistryKey;
public final class Race implements Affine { public final class Race implements Affine {
public static final String DEFAULT_ID = "unicopia:human"; public static final String DEFAULT_ID = "unicopia:human";
public static final Registry<Race> REGISTRY = Registries.createDefaulted(Unicopia.id("race"), DEFAULT_ID); public static final Registry<Race> REGISTRY = RegistryUtils.createDefaulted(Unicopia.id("race"), DEFAULT_ID);
public static final RegistryKey<? extends Registry<Race>> REGISTRY_KEY = REGISTRY.getKey(); public static final RegistryKey<? extends Registry<Race>> REGISTRY_KEY = REGISTRY.getKey();
private static final DynamicCommandExceptionType UNKNOWN_RACE_EXCEPTION = new DynamicCommandExceptionType(id -> Text.translatable("race.unknown", id)); private static final DynamicCommandExceptionType UNKNOWN_RACE_EXCEPTION = new DynamicCommandExceptionType(id -> Text.translatable("race.unknown", id));

View file

@ -9,13 +9,13 @@ import java.util.function.BiFunction;
import com.minelittlepony.unicopia.Race; import com.minelittlepony.unicopia.Race;
import com.minelittlepony.unicopia.Unicopia; import com.minelittlepony.unicopia.Unicopia;
import com.minelittlepony.unicopia.util.Registries; import com.minelittlepony.unicopia.util.RegistryUtils;
import net.minecraft.util.*; import net.minecraft.util.*;
import net.minecraft.registry.Registry; import net.minecraft.registry.Registry;
public interface Abilities { public interface Abilities {
Registry<Ability<?>> REGISTRY = Registries.createSimple(Unicopia.id("abilities")); Registry<Ability<?>> REGISTRY = RegistryUtils.createSimple(Unicopia.id("abilities"));
Map<AbilitySlot, Set<Ability<?>>> BY_SLOT = new EnumMap<>(AbilitySlot.class); Map<AbilitySlot, Set<Ability<?>>> BY_SLOT = new EnumMap<>(AbilitySlot.class);
BiFunction<AbilitySlot, Race.Composite, List<Ability<?>>> BY_SLOT_AND_COMPOSITE_RACE = Util.memoize((slot, race) -> { BiFunction<AbilitySlot, Race.Composite, List<Ability<?>>> BY_SLOT_AND_COMPOSITE_RACE = Util.memoize((slot, race) -> {
return BY_SLOT.computeIfAbsent(slot, s -> new LinkedHashSet<>()) return BY_SLOT.computeIfAbsent(slot, s -> new LinkedHashSet<>())

View file

@ -19,7 +19,7 @@ import com.minelittlepony.unicopia.ability.magic.spell.ThrowableSpell;
import com.minelittlepony.unicopia.ability.magic.spell.trait.SpellTraits; import com.minelittlepony.unicopia.ability.magic.spell.trait.SpellTraits;
import com.minelittlepony.unicopia.item.GemstoneItem; import com.minelittlepony.unicopia.item.GemstoneItem;
import com.minelittlepony.unicopia.item.UItems; import com.minelittlepony.unicopia.item.UItems;
import com.minelittlepony.unicopia.util.Registries; import com.minelittlepony.unicopia.util.RegistryUtils;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtCompound;
@ -33,8 +33,8 @@ public final class SpellType<T extends Spell> implements Affine, SpellPredicate<
public static final Identifier EMPTY_ID = Unicopia.id("none"); public static final Identifier EMPTY_ID = Unicopia.id("none");
public static final SpellType<?> EMPTY_KEY = new SpellType<>(EMPTY_ID, Affinity.NEUTRAL, 0xFFFFFF, false, SpellTraits.EMPTY, t -> null); public static final SpellType<?> EMPTY_KEY = new SpellType<>(EMPTY_ID, Affinity.NEUTRAL, 0xFFFFFF, false, SpellTraits.EMPTY, t -> null);
public static final Registry<SpellType<?>> REGISTRY = Registries.createSimple(Unicopia.id("spells")); public static final Registry<SpellType<?>> REGISTRY = RegistryUtils.createSimple(Unicopia.id("spells"));
private static final Map<Affinity, Set<SpellType<?>>> BY_AFFINITY = new EnumMap<>(Affinity.class); public static final Map<Affinity, Set<SpellType<?>>> BY_AFFINITY = new EnumMap<>(Affinity.class);
public static final SpellType<PlaceableSpell> PLACED_SPELL = register("placed", Affinity.NEUTRAL, 0, false, SpellTraits.EMPTY, PlaceableSpell::new); public static final SpellType<PlaceableSpell> PLACED_SPELL = register("placed", Affinity.NEUTRAL, 0, false, SpellTraits.EMPTY, PlaceableSpell::new);
public static final SpellType<ThrowableSpell> THROWN_SPELL = register("thrown", Affinity.NEUTRAL, 0, false, SpellTraits.EMPTY, ThrowableSpell::new); public static final SpellType<ThrowableSpell> THROWN_SPELL = register("thrown", Affinity.NEUTRAL, 0, false, SpellTraits.EMPTY, ThrowableSpell::new);

View file

@ -13,7 +13,7 @@ import com.minelittlepony.unicopia.entity.UEntities;
import com.minelittlepony.unicopia.particle.ParticleUtils; import com.minelittlepony.unicopia.particle.ParticleUtils;
import com.minelittlepony.unicopia.projectile.MagicProjectileEntity; import com.minelittlepony.unicopia.projectile.MagicProjectileEntity;
import com.minelittlepony.unicopia.projectile.ProjectileDelegate; import com.minelittlepony.unicopia.projectile.ProjectileDelegate;
import com.minelittlepony.unicopia.util.Registries; import com.minelittlepony.unicopia.util.RegistryUtils;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType; import net.minecraft.entity.EntityType;
@ -66,7 +66,7 @@ public class TransformationSpell extends AbstractSpell implements ProjectileDele
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private <T extends MobEntity> Optional<EntityType<T>> pickType(EntityType<?> except, World world) { private <T extends MobEntity> Optional<EntityType<T>> pickType(EntityType<?> except, World world) {
Set<EntityType<?>> options = Registries.valuesForTag(world, UTags.TRANSFORMABLE_ENTITIES).collect(Collectors.toSet()); Set<EntityType<?>> options = RegistryUtils.valuesForTag(world, UTags.TRANSFORMABLE_ENTITIES).collect(Collectors.toSet());
if (except.getSpawnGroup() == SpawnGroup.MONSTER) { if (except.getSpawnGroup() == SpawnGroup.MONSTER) {
options.removeIf(t -> t.getSpawnGroup() == SpawnGroup.MONSTER); options.removeIf(t -> t.getSpawnGroup() == SpawnGroup.MONSTER);
} else { } else {

View file

@ -5,6 +5,7 @@ import java.util.function.Predicate;
import java.util.function.Supplier; import java.util.function.Supplier;
import net.fabricmc.fabric.api.biome.v1.*; import net.fabricmc.fabric.api.biome.v1.*;
import net.fabricmc.fabric.api.event.registry.DynamicRegistrySetupCallback;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.block.*; import net.minecraft.block.*;
import net.minecraft.block.sapling.SaplingGenerator; import net.minecraft.block.sapling.SaplingGenerator;
@ -13,7 +14,6 @@ import net.minecraft.util.Identifier;
import net.minecraft.util.math.random.Random; import net.minecraft.util.math.random.Random;
import net.minecraft.registry.*; import net.minecraft.registry.*;
import net.minecraft.registry.tag.BiomeTags; import net.minecraft.registry.tag.BiomeTags;
import net.minecraft.registry.entry.*;
import net.minecraft.world.gen.GenerationStep; import net.minecraft.world.gen.GenerationStep;
import net.minecraft.world.gen.feature.*; import net.minecraft.world.gen.feature.*;
import net.minecraft.world.gen.feature.size.TwoLayersFeatureSize; import net.minecraft.world.gen.feature.size.TwoLayersFeatureSize;
@ -23,12 +23,36 @@ import net.minecraft.world.gen.stateprovider.BlockStateProvider;
import net.minecraft.world.gen.trunk.TrunkPlacer; import net.minecraft.world.gen.trunk.TrunkPlacer;
public record Tree ( public record Tree (
RegistryEntry<ConfiguredFeature<TreeFeatureConfig, ?>> configuredFeature, Identifier id,
Optional<RegistryEntry<PlacedFeature>> placedFeature, TreeFeatureConfig.Builder config,
Optional<Block> sapling RegistryKey<ConfiguredFeature<?, ?>> configuredFeatureId,
Optional<RegistryKey<PlacedFeature>> placedFeatureId,
Optional<Block> sapling,
Optional<PlacementModifier> placement
) { ) {
public static final List<Tree> REGISTRY = new ArrayList<>(); public static final List<Tree> REGISTRY = new ArrayList<>();
private static void bootstrap() {
DynamicRegistrySetupCallback.EVENT.register(registries -> {
registries.getOptional(RegistryKeys.CONFIGURED_FEATURE).ifPresent(registry -> {
REGISTRY.forEach(tree -> {
Registry.register(registry, tree.id(), new ConfiguredFeature<>(Feature.TREE, tree.config.build()));
});
});
registries.getOptional(RegistryKeys.PLACED_FEATURE).ifPresent(registry -> {
var reg = registries.asDynamicRegistryManager().createRegistryLookup().getOrThrow(RegistryKeys.CONFIGURED_FEATURE);
REGISTRY.stream().filter(tree -> tree.placedFeatureId().isPresent()).forEach(tree -> {
var placedFeature = new PlacedFeature(reg.getOrThrow(tree.configuredFeatureId()),
VegetationPlacedFeatures.modifiersWithWouldSurvive(tree.placement().orElseThrow(), tree.sapling().orElse(Blocks.OAK_SAPLING))
);
Registry.register(registry, tree.id, placedFeature);
});
});
});
}
public static class Builder { public static class Builder {
public static final Predicate<BiomeSelectionContext> IS_FOREST = BiomeSelectors.foundInOverworld().and(BiomeSelectors.tag(BiomeTags.IS_FOREST)); public static final Predicate<BiomeSelectionContext> IS_FOREST = BiomeSelectors.foundInOverworld().and(BiomeSelectors.tag(BiomeTags.IS_FOREST));
@ -92,31 +116,28 @@ public record Tree (
} }
public Tree build() { public Tree build() {
RegistryEntry<ConfiguredFeature<TreeFeatureConfig, ?>> configuredFeature = ConfiguredFeatures.register(id.toString(), Feature.TREE, configSupplier.map(Supplier::get) RegistryKey<ConfiguredFeature<?, ?>> configuredFeatureId = RegistryKey.of(RegistryKeys.CONFIGURED_FEATURE, id);
Tree tree = new Tree(id, configSupplier.map(Supplier::get)
.orElseGet(() -> new TreeFeatureConfig.Builder( .orElseGet(() -> new TreeFeatureConfig.Builder(
BlockStateProvider.of(logType), BlockStateProvider.of(logType),
trunkPlacer, trunkPlacer,
BlockStateProvider.of(leavesType), BlockStateProvider.of(leavesType),
foliagePlacer, foliagePlacer,
size.get() size.get()
).forceDirt()).build()); ).forceDirt()), configuredFeatureId, selector.map(selector -> {
RegistryKey<PlacedFeature> i = RegistryKey.of(RegistryKeys.PLACED_FEATURE, id);
Optional<Block> sapling = saplingId.map(id -> UBlocks.register(id, new SaplingBlock(new SaplingGenerator() { BiomeModifications.addFeature(selector, GenerationStep.Feature.VEGETAL_DECORATION, i);
return i;
}), saplingId.map(id -> UBlocks.register(id, new SaplingBlock(new SaplingGenerator() {
@Override @Override
protected RegistryEntry<? extends ConfiguredFeature<?, ?>> getTreeFeature(Random rng, boolean flowersNearby) { protected RegistryKey<ConfiguredFeature<?, ?>> getTreeFeature(Random rng, boolean flowersNearby) {
return configuredFeature; return configuredFeatureId;
} }
}, FabricBlockSettings.copy(Blocks.OAK_SAPLING)), ItemGroup.DECORATIONS)); }, FabricBlockSettings.copy(Blocks.OAK_SAPLING)), ItemGroups.NATURAL)), countModifier);
Optional<RegistryEntry<PlacedFeature>> placedFeature = selector.map(selector -> { if (REGISTRY.isEmpty()) {
var pf = PlacedFeatures.register(id.toString() + "_checked", configuredFeature, bootstrap();
VegetationPlacedFeatures.modifiersWithWouldSurvive(countModifier.orElseThrow(), sapling.orElse(Blocks.OAK_SAPLING)) }
);
BiomeModifications.addFeature(selector, GenerationStep.Feature.VEGETAL_DECORATION, pf.getKey().get());
return pf;
});
Tree tree = new Tree(configuredFeature, placedFeature, sapling);
REGISTRY.add(tree); REGISTRY.add(tree);
return tree; return tree;

View file

@ -5,6 +5,7 @@ import java.util.List;
import com.minelittlepony.unicopia.Unicopia; import com.minelittlepony.unicopia.Unicopia;
import com.minelittlepony.unicopia.item.UItems; import com.minelittlepony.unicopia.item.UItems;
import com.minelittlepony.unicopia.item.group.ItemGroupRegistry;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricMaterialBuilder; import net.fabricmc.fabric.api.object.builder.v1.block.FabricMaterialBuilder;
@ -33,23 +34,23 @@ public interface UBlocks {
Block FROSTED_OBSIDIAN = register("frosted_obsidian", new FrostedObsidianBlock(FabricBlockSettings.copy(Blocks.OBSIDIAN).ticksRandomly())); Block FROSTED_OBSIDIAN = register("frosted_obsidian", new FrostedObsidianBlock(FabricBlockSettings.copy(Blocks.OBSIDIAN).ticksRandomly()));
Block ZAP_LOG = register("zap_log", new ZapAppleLogBlock(Blocks.OAK_LOG, MapColor.GRAY, MapColor.DEEPSLATE_GRAY), ItemGroup.MATERIALS); Block ZAP_LOG = register("zap_log", new ZapAppleLogBlock(Blocks.OAK_LOG, MapColor.GRAY, MapColor.DEEPSLATE_GRAY), ItemGroups.BUILDING_BLOCKS);
Block ZAP_WOOD = register("zap_wood", new ZapAppleLogBlock(Blocks.OAK_WOOD, MapColor.DEEPSLATE_GRAY, MapColor.DEEPSLATE_GRAY), ItemGroup.MATERIALS); Block ZAP_WOOD = register("zap_wood", new ZapAppleLogBlock(Blocks.OAK_WOOD, MapColor.DEEPSLATE_GRAY, MapColor.DEEPSLATE_GRAY), ItemGroups.BUILDING_BLOCKS);
Block STRIPPED_ZAP_LOG = register("stripped_zap_log", new ZapAppleLogBlock(Blocks.STRIPPED_OAK_LOG, MapColor.LIGHT_GRAY, MapColor.GRAY), ItemGroup.MATERIALS); Block STRIPPED_ZAP_LOG = register("stripped_zap_log", new ZapAppleLogBlock(Blocks.STRIPPED_OAK_LOG, MapColor.LIGHT_GRAY, MapColor.GRAY), ItemGroups.BUILDING_BLOCKS);
Block STRIPPED_ZAP_WOOD = register("stripped_zap_wood", new ZapAppleLogBlock(Blocks.STRIPPED_OAK_WOOD, MapColor.GRAY, MapColor.GRAY), ItemGroup.MATERIALS); Block STRIPPED_ZAP_WOOD = register("stripped_zap_wood", new ZapAppleLogBlock(Blocks.STRIPPED_OAK_WOOD, MapColor.GRAY, MapColor.GRAY), ItemGroups.BUILDING_BLOCKS);
Block ZAP_LEAVES = register("zap_leaves", new ZapAppleLeavesBlock(), ItemGroup.DECORATIONS); Block ZAP_LEAVES = register("zap_leaves", new ZapAppleLeavesBlock(), ItemGroups.NATURAL);
Block ZAP_BULB = register("zap_bulb", new FruitBlock(FabricBlockSettings.of(Material.GOURD, MapColor.GRAY).strength(500, 1200).sounds(BlockSoundGroup.AZALEA_LEAVES), Direction.DOWN, ZAP_LEAVES, FruitBlock.DEFAULT_SHAPE, false)); Block ZAP_BULB = register("zap_bulb", new FruitBlock(FabricBlockSettings.of(Material.GOURD, MapColor.GRAY).strength(500, 1200).sounds(BlockSoundGroup.AZALEA_LEAVES), Direction.DOWN, ZAP_LEAVES, FruitBlock.DEFAULT_SHAPE, false));
Block ZAP_APPLE = register("zap_apple", new FruitBlock(FabricBlockSettings.of(Material.GOURD, MapColor.GRAY).sounds(BlockSoundGroup.AZALEA_LEAVES), Direction.DOWN, ZAP_LEAVES, FruitBlock.DEFAULT_SHAPE, false)); Block ZAP_APPLE = register("zap_apple", new FruitBlock(FabricBlockSettings.of(Material.GOURD, MapColor.GRAY).sounds(BlockSoundGroup.AZALEA_LEAVES), Direction.DOWN, ZAP_LEAVES, FruitBlock.DEFAULT_SHAPE, false));
Block WEATHER_VANE = register("weather_vane", new WeatherVaneBlock(FabricBlockSettings.of(Material.METAL, MapColor.BLACK).requiresTool().strength(3.0f, 6.0f).sounds(BlockSoundGroup.METAL).nonOpaque()), ItemGroup.DECORATIONS); Block WEATHER_VANE = register("weather_vane", new WeatherVaneBlock(FabricBlockSettings.of(Material.METAL, MapColor.BLACK).requiresTool().strength(3.0f, 6.0f).sounds(BlockSoundGroup.METAL).nonOpaque()), ItemGroups.TOOLS);
Block GREEN_APPLE_LEAVES = register("green_apple_leaves", new FruitBearingBlock(FabricBlockSettings.copy(Blocks.OAK_LEAVES), Block GREEN_APPLE_LEAVES = register("green_apple_leaves", new FruitBearingBlock(FabricBlockSettings.copy(Blocks.OAK_LEAVES),
0xE5FFFF88, 0xE5FFFF88,
() -> UBlocks.GREEN_APPLE, () -> UBlocks.GREEN_APPLE,
() -> UItems.GREEN_APPLE.getDefaultStack() () -> UItems.GREEN_APPLE.getDefaultStack()
), ItemGroup.DECORATIONS); ), ItemGroups.NATURAL);
Block GREEN_APPLE = register("green_apple", new FruitBlock(FabricBlockSettings.of(Material.GOURD, MapColor.GREEN).sounds(BlockSoundGroup.WOOD), Direction.DOWN, GREEN_APPLE_LEAVES, FruitBlock.DEFAULT_SHAPE)); Block GREEN_APPLE = register("green_apple", new FruitBlock(FabricBlockSettings.of(Material.GOURD, MapColor.GREEN).sounds(BlockSoundGroup.WOOD), Direction.DOWN, GREEN_APPLE_LEAVES, FruitBlock.DEFAULT_SHAPE));
Block GREEN_APPLE_SPROUT = register("green_apple_sprout", new SproutBlock(0xE5FFFF88, () -> UItems.GREEN_APPLE_SEEDS, () -> UTreeGen.GREEN_APPLE_TREE.sapling().map(Block::getDefaultState).get())); Block GREEN_APPLE_SPROUT = register("green_apple_sprout", new SproutBlock(0xE5FFFF88, () -> UItems.GREEN_APPLE_SEEDS, () -> UTreeGen.GREEN_APPLE_TREE.sapling().map(Block::getDefaultState).get()));
@ -57,7 +58,7 @@ public interface UBlocks {
0xE5FFCC88, 0xE5FFCC88,
() -> UBlocks.SWEET_APPLE, () -> UBlocks.SWEET_APPLE,
() -> UItems.SWEET_APPLE.getDefaultStack() () -> UItems.SWEET_APPLE.getDefaultStack()
), ItemGroup.DECORATIONS); ), ItemGroups.NATURAL);
Block SWEET_APPLE = register("sweet_apple", new FruitBlock(FabricBlockSettings.of(Material.GOURD, MapColor.GREEN).sounds(BlockSoundGroup.WOOD), Direction.DOWN, SWEET_APPLE_LEAVES, FruitBlock.DEFAULT_SHAPE)); Block SWEET_APPLE = register("sweet_apple", new FruitBlock(FabricBlockSettings.of(Material.GOURD, MapColor.GREEN).sounds(BlockSoundGroup.WOOD), Direction.DOWN, SWEET_APPLE_LEAVES, FruitBlock.DEFAULT_SHAPE));
Block SWEET_APPLE_SPROUT = register("sweet_apple_sprout", new SproutBlock(0xE5FFCC88, () -> UItems.SWEET_APPLE_SEEDS, () -> UTreeGen.SWEET_APPLE_TREE.sapling().map(Block::getDefaultState).get())); Block SWEET_APPLE_SPROUT = register("sweet_apple_sprout", new SproutBlock(0xE5FFCC88, () -> UItems.SWEET_APPLE_SEEDS, () -> UTreeGen.SWEET_APPLE_TREE.sapling().map(Block::getDefaultState).get()));
@ -65,7 +66,7 @@ public interface UBlocks {
0xE5FFCCCC, 0xE5FFCCCC,
() -> UBlocks.SOUR_APPLE, () -> UBlocks.SOUR_APPLE,
() -> UItems.SOUR_APPLE.getDefaultStack() () -> UItems.SOUR_APPLE.getDefaultStack()
), ItemGroup.DECORATIONS); ), ItemGroups.NATURAL);
Block SOUR_APPLE = register("sour_apple", new FruitBlock(FabricBlockSettings.of(Material.GOURD, MapColor.GREEN).sounds(BlockSoundGroup.WOOD), Direction.DOWN, SOUR_APPLE_LEAVES, FruitBlock.DEFAULT_SHAPE)); Block SOUR_APPLE = register("sour_apple", new FruitBlock(FabricBlockSettings.of(Material.GOURD, MapColor.GREEN).sounds(BlockSoundGroup.WOOD), Direction.DOWN, SOUR_APPLE_LEAVES, FruitBlock.DEFAULT_SHAPE));
Block SOUR_APPLE_SPROUT = register("sour_apple_sprout", new SproutBlock(0xE5FFCC88, () -> UItems.SOUR_APPLE_SEEDS, () -> UTreeGen.SOUR_APPLE_TREE.sapling().map(Block::getDefaultState).get())); Block SOUR_APPLE_SPROUT = register("sour_apple_sprout", new SproutBlock(0xE5FFCC88, () -> UItems.SOUR_APPLE_SEEDS, () -> UTreeGen.SOUR_APPLE_TREE.sapling().map(Block::getDefaultState).get()));
@ -84,7 +85,7 @@ public interface UBlocks {
} }
static <T extends Block> T register(Identifier id, T block, ItemGroup group) { static <T extends Block> T register(Identifier id, T block, ItemGroup group) {
UItems.register(id, new BlockItem(block, new Item.Settings().group(group))); UItems.register(id, ItemGroupRegistry.register(new BlockItem(block, new Item.Settings()), group));
return register(id, block); return register(id, block);
} }
@ -95,7 +96,7 @@ public interface UBlocks {
if (block instanceof SaplingBlock || block instanceof SproutBlock || block instanceof FruitBlock || block instanceof CropBlock) { if (block instanceof SaplingBlock || block instanceof SproutBlock || block instanceof FruitBlock || block instanceof CropBlock) {
TRANSLUCENT_BLOCKS.add(block); TRANSLUCENT_BLOCKS.add(block);
} }
return Registry.register(Registry.BLOCK, id, block); return Registry.register(Registries.BLOCK, id, block);
} }
static void bootstrap() { static void bootstrap() {

View file

@ -19,7 +19,6 @@ import net.minecraft.util.JsonHelper;
import net.minecraft.registry.Registries; import net.minecraft.registry.Registries;
import net.minecraft.registry.RegistryKeys; import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.entry.RegistryEntry; import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.registry.tag.FluidTags;
import net.minecraft.registry.tag.TagKey; import net.minecraft.registry.tag.TagKey;
import net.minecraft.world.World; import net.minecraft.world.World;

View file

@ -12,6 +12,7 @@ import com.minelittlepony.unicopia.client.gui.spellbook.SpellbookChapterList.Cha
import com.minelittlepony.unicopia.client.gui.spellbook.SpellbookScreen.ImageButton; import com.minelittlepony.unicopia.client.gui.spellbook.SpellbookScreen.ImageButton;
import com.minelittlepony.unicopia.container.SpellbookState; import com.minelittlepony.unicopia.container.SpellbookState;
import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.entity.player.Pony;
import com.minelittlepony.unicopia.item.group.ItemGroupRegistry;
import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
@ -22,10 +23,8 @@ import net.minecraft.sound.SoundEvents;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.minecraft.util.Util; import net.minecraft.util.Util;
import net.minecraft.util.collection.DefaultedList;
public class SpellbookTraitDexPageContent extends DrawableHelper implements SpellbookChapterList.Content, SpellbookScreen.RecipesChangedListener { public class SpellbookTraitDexPageContent extends DrawableHelper implements SpellbookChapterList.Content, SpellbookScreen.RecipesChangedListener {
private final Trait[] traits = Trait.values(); private final Trait[] traits = Trait.values();
private SpellbookState.PageState state = new SpellbookState.PageState(); private SpellbookState.PageState state = new SpellbookState.PageState();
@ -127,8 +126,7 @@ public class SpellbookTraitDexPageContent extends DrawableHelper implements Spel
SpellTraits.getItems(trait) SpellTraits.getItems(trait)
.sorted(Comparator.comparing(u -> knownItems.contains(u) ? 0 : 1)) .sorted(Comparator.comparing(u -> knownItems.contains(u) ? 0 : 1))
.forEach(i -> { .forEach(i -> {
DefaultedList<ItemStack> stacks = DefaultedList.of(); List<ItemStack> stacks = ItemGroupRegistry.getVariations(i);
i.appendStacks(ItemGroups.SEARCH, stacks);
if (knownItems.contains(i)) { if (knownItems.contains(i)) {
tree.input(stacks); tree.input(stacks);
} else { } else {

View file

@ -6,7 +6,7 @@ import com.minelittlepony.unicopia.UTags;
import com.minelittlepony.unicopia.ability.magic.spell.effect.SpellType; import com.minelittlepony.unicopia.ability.magic.spell.effect.SpellType;
import com.minelittlepony.unicopia.item.GemstoneItem; import com.minelittlepony.unicopia.item.GemstoneItem;
import com.minelittlepony.unicopia.item.UItems; import com.minelittlepony.unicopia.item.UItems;
import com.minelittlepony.unicopia.util.Registries; import com.minelittlepony.unicopia.util.RegistryUtils;
import net.fabricmc.fabric.api.object.builder.v1.trade.TradeOfferHelper; import net.fabricmc.fabric.api.object.builder.v1.trade.TradeOfferHelper;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
@ -80,7 +80,7 @@ public interface UTradeOffers {
} }
private static Item random(Entity e, TagKey<Item> item, Random rng) { private static Item random(Entity e, TagKey<Item> item, Random rng) {
return Registries.entriesForTag(e.world, item).getRandom(rng).get().value(); return RegistryUtils.entriesForTag(e.world, item).getRandom(rng).get().value();
} }
static class JarredItemTradeOfferFactory implements TradeOffers.Factory { static class JarredItemTradeOfferFactory implements TradeOffers.Factory {

View file

@ -10,7 +10,7 @@ import com.minelittlepony.unicopia.ability.magic.Caster;
import com.minelittlepony.unicopia.entity.duck.LivingEntityDuck; import com.minelittlepony.unicopia.entity.duck.LivingEntityDuck;
import com.minelittlepony.unicopia.entity.duck.EntityDuck; import com.minelittlepony.unicopia.entity.duck.EntityDuck;
import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.entity.player.Pony;
import com.minelittlepony.unicopia.util.Registries; import com.minelittlepony.unicopia.util.RegistryUtils;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.Entity.RemovalReason; import net.minecraft.entity.Entity.RemovalReason;
@ -38,7 +38,7 @@ import net.minecraft.registry.Registry;
public class EntityBehaviour<T extends Entity> { public class EntityBehaviour<T extends Entity> {
private static final EntityBehaviour<Entity> DEFAULT = new EntityBehaviour<>(); private static final EntityBehaviour<Entity> DEFAULT = new EntityBehaviour<>();
private static final Registry<EntityBehaviour<?>> REGISTRY = Registries.createSimple(Unicopia.id("entity_behaviour")); private static final Registry<EntityBehaviour<?>> REGISTRY = RegistryUtils.createSimple(Unicopia.id("entity_behaviour"));
/** /**
* Equivalent of the entity#tick method. Called every tick to update th logic for a disguise. * Equivalent of the entity#tick method. Called every tick to update th logic for a disguise.

View file

@ -1,5 +1,6 @@
package com.minelittlepony.unicopia.item; package com.minelittlepony.unicopia.item;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.function.Predicate; import java.util.function.Predicate;
@ -14,11 +15,11 @@ import com.minelittlepony.unicopia.ability.magic.spell.trait.SpellTraits;
import com.minelittlepony.unicopia.client.FlowingText; import com.minelittlepony.unicopia.client.FlowingText;
import com.minelittlepony.unicopia.entity.player.PlayerCharmTracker; import com.minelittlepony.unicopia.entity.player.PlayerCharmTracker;
import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.entity.player.Pony;
import com.minelittlepony.unicopia.item.group.MultiItem;
import net.minecraft.client.item.TooltipContext; import net.minecraft.client.item.TooltipContext;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.text.MutableText; import net.minecraft.text.MutableText;
import net.minecraft.text.Text; import net.minecraft.text.Text;
@ -26,10 +27,9 @@ import net.minecraft.util.Formatting;
import net.minecraft.util.Hand; import net.minecraft.util.Hand;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.minecraft.util.TypedActionResult; import net.minecraft.util.TypedActionResult;
import net.minecraft.util.collection.DefaultedList;
import net.minecraft.world.World; import net.minecraft.world.World;
public class GemstoneItem extends Item { public class GemstoneItem extends Item implements MultiItem {
public GemstoneItem(Settings settings) { public GemstoneItem(Settings settings) {
super(settings); super(settings);
@ -90,17 +90,13 @@ public class GemstoneItem extends Item {
} }
@Override @Override
public void appendStacks(ItemGroup tab, DefaultedList<ItemStack> items) { public List<ItemStack> getDefaultStacks() {
super.appendStacks(tab, items); return Arrays.stream(Affinity.VALUES)
if (isIn(tab)) { .flatMap(i -> SpellType.byAffinity(i).stream()
for (Affinity i : Affinity.VALUES) { .filter(type -> type.isObtainable())
SpellType.byAffinity(i).forEach(type -> { .map(type -> enchant(getDefaultStack(), type, i))
if (type.isObtainable()) { )
items.add(enchant(getDefaultStack(), type, i)); .toList();
}
});
}
}
} }
@Override @Override

View file

@ -1,52 +1,29 @@
package com.minelittlepony.unicopia.item; package com.minelittlepony.unicopia.item;
import java.util.function.Supplier;
import java.util.stream.Stream; import java.util.stream.Stream;
import com.minelittlepony.unicopia.UTags; import com.minelittlepony.unicopia.item.group.ItemGroupRegistry;
import com.minelittlepony.unicopia.Unicopia;
import com.minelittlepony.unicopia.item.toxin.Toxic; import com.minelittlepony.unicopia.item.toxin.Toxic;
import com.minelittlepony.unicopia.item.toxin.ToxicHolder; import com.minelittlepony.unicopia.item.toxin.ToxicHolder;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup; import net.minecraft.item.*;
import net.minecraft.item.ItemStack; import net.minecraft.registry.Registries;
import net.minecraft.item.Items;
import net.minecraft.tag.TagKey;
import net.fabricmc.fabric.api.client.itemgroup.FabricItemGroupBuilder;
import net.minecraft.util.collection.DefaultedList;
import net.minecraft.util.registry.Registry;
public interface UItemGroups { public interface UItemGroups {
ItemGroup ALL_ITEMS = create("items", UItems.EMPTY_JAR::getDefaultStack, () -> { ItemGroup ALL_ITEMS = ItemGroupRegistry.createDynamic("items", UItems.EMPTY_JAR::getDefaultStack, () -> {
return Stream.concat(Stream.of(Items.APPLE), UItems.ITEMS.stream().filter(item -> !(item instanceof ChameleonItem) || ((ChameleonItem)item).isFullyDisguised())); return Stream.concat(Stream.of(Items.APPLE), UItems.ITEMS.stream().filter(item -> !(item instanceof ChameleonItem) || ((ChameleonItem)item).isFullyDisguised()));
}); });
ItemGroup HORSE_FEED = create("horsefeed", UItems.ZAP_APPLE::getDefaultStack, () -> { ItemGroup HORSE_FEED = ItemGroupRegistry.createDynamic("horsefeed", UItems.ZAP_APPLE::getDefaultStack, () -> {
return Registry.ITEM.stream().filter(item -> ((ToxicHolder)item).getToxic(item.getDefaultStack()) != Toxic.EMPTY); return Registries.ITEM.stream().filter(item -> ((ToxicHolder)item).getToxic(item.getDefaultStack()) != Toxic.EMPTY);
}); });
ItemGroup EARTH_PONY_ITEMS = forTag("earth_pony", UItems.APPLE_PIE::getDefaultStack); ItemGroup EARTH_PONY_ITEMS = ItemGroupRegistry.createGroupFromTag("earth_pony", UItems.APPLE_PIE::getDefaultStack);
ItemGroup UNICORN_ITEMS = forTag("unicorn", UItems.SPELLBOOK::getDefaultStack); ItemGroup UNICORN_ITEMS = ItemGroupRegistry.createGroupFromTag("unicorn", UItems.SPELLBOOK::getDefaultStack);
ItemGroup PEGASUS_ITEMS = forTag("pegasus", UItems.PEGASUS_FEATHER::getDefaultStack); ItemGroup PEGASUS_ITEMS = ItemGroupRegistry.createGroupFromTag("pegasus", UItems.PEGASUS_FEATHER::getDefaultStack);
ItemGroup BAT_PONY_ITEMS = forTag("bat_pony", UItems.SUNGLASSES::getDefaultStack); ItemGroup BAT_PONY_ITEMS = ItemGroupRegistry.createGroupFromTag("bat_pony", UItems.SUNGLASSES::getDefaultStack);
ItemGroup CHANGELING_ITEMS = forTag("changeling", UItems.LOVE_BOTTLE::getDefaultStack); ItemGroup CHANGELING_ITEMS = ItemGroupRegistry.createGroupFromTag("changeling", UItems.LOVE_BOTTLE::getDefaultStack);
static ItemGroup forTag(String name, Supplier<ItemStack> icon) { static void bootstrap() {
TagKey<Item> key = UTags.item("groups/" + name); UItems.bootstrap();
return create(name, icon, () -> {
return Registry.ITEM.getEntryList(key)
.stream()
.flatMap(named -> named.stream())
.map(entry -> entry.value());
});
} }
static ItemGroup create(String name, Supplier<ItemStack> icon, Supplier<Stream<Item>> items) {
return FabricItemGroupBuilder.create(Unicopia.id(name)).appendItems(list -> {
DefaultedList<ItemStack> defs = DefaultedList.of();
items.get().forEach(item -> item.appendStacks(ItemGroup.SEARCH, defs));
list.addAll(defs);
}).icon(icon).build();
}
static void bootstrap() {}
} }

View file

@ -7,6 +7,7 @@ import com.minelittlepony.unicopia.*;
import com.minelittlepony.unicopia.block.UBlocks; import com.minelittlepony.unicopia.block.UBlocks;
import com.minelittlepony.unicopia.entity.UEntities; import com.minelittlepony.unicopia.entity.UEntities;
import com.minelittlepony.unicopia.item.enchantment.UEnchantments; import com.minelittlepony.unicopia.item.enchantment.UEnchantments;
import com.minelittlepony.unicopia.item.group.ItemGroupRegistry;
import com.minelittlepony.unicopia.item.toxin.UFoodComponents; import com.minelittlepony.unicopia.item.toxin.UFoodComponents;
import net.minecraft.item.*; import net.minecraft.item.*;
@ -24,15 +25,15 @@ public interface UItems {
List<Item> ITEMS = new ArrayList<>(); List<Item> ITEMS = new ArrayList<>();
Item GREEN_APPLE = register("green_apple", AppleItem.registerTickCallback(new Item(new Item.Settings().group(ItemGroup.FOOD).food(FoodComponents.APPLE)))); Item GREEN_APPLE = register("green_apple", AppleItem.registerTickCallback(new Item(new Item.Settings().food(FoodComponents.APPLE))), ItemGroups.FOOD_AND_DRINK);
Item SWEET_APPLE = register("sweet_apple", AppleItem.registerTickCallback(new Item(new Item.Settings().group(ItemGroup.FOOD).food(FoodComponents.APPLE)))); Item SWEET_APPLE = register("sweet_apple", AppleItem.registerTickCallback(new Item(new Item.Settings().food(FoodComponents.APPLE))), ItemGroups.FOOD_AND_DRINK);
Item SOUR_APPLE = register("sour_apple", AppleItem.registerTickCallback(new Item(new Item.Settings().group(ItemGroup.FOOD).food(FoodComponents.APPLE)))); Item SOUR_APPLE = register("sour_apple", AppleItem.registerTickCallback(new Item(new Item.Settings().food(FoodComponents.APPLE))), ItemGroups.FOOD_AND_DRINK);
ZapAppleItem ZAP_APPLE = register("zap_apple", AppleItem.registerTickCallback(new ZapAppleItem(new Item.Settings().group(ItemGroup.FOOD).food(UFoodComponents.ZAP_APPLE)))); ZapAppleItem ZAP_APPLE = register("zap_apple", AppleItem.registerTickCallback(new ZapAppleItem(new Item.Settings().food(UFoodComponents.ZAP_APPLE))), ItemGroups.FOOD_AND_DRINK);
Item ZAP_BULB = register("zap_bulb", new Item(new Item.Settings().group(ItemGroup.FOOD).food(UFoodComponents.ZAP_BULB))); Item ZAP_BULB = register("zap_bulb", new Item(new Item.Settings().food(UFoodComponents.ZAP_BULB)), ItemGroups.FOOD_AND_DRINK);
Item ROTTEN_APPLE = register("rotten_apple", new RottenAppleItem(new Item.Settings().group(ItemGroup.FOOD).food(FoodComponents.APPLE))); Item ROTTEN_APPLE = register("rotten_apple", new RottenAppleItem(new Item.Settings().food(FoodComponents.APPLE)), ItemGroups.FOOD_AND_DRINK);
Item COOKED_ZAP_APPLE = register("cooked_zap_apple", new Item(new Item.Settings().group(ItemGroup.FOOD).food(FoodComponents.APPLE))); Item COOKED_ZAP_APPLE = register("cooked_zap_apple", new Item(new Item.Settings().food(FoodComponents.APPLE)), ItemGroups.FOOD_AND_DRINK);
Item MUSIC_DISC_CRUSADE = register("music_disc_crusade", USounds.RECORD_CRUSADE, 181); Item MUSIC_DISC_CRUSADE = register("music_disc_crusade", USounds.RECORD_CRUSADE, 181);
Item MUSIC_DISC_PET = register("music_disc_pet", USounds.RECORD_PET, 221); Item MUSIC_DISC_PET = register("music_disc_pet", USounds.RECORD_PET, 221);
@ -42,89 +43,91 @@ public interface UItems {
FriendshipBraceletItem FRIENDSHIP_BRACELET = register("friendship_bracelet", new FriendshipBraceletItem( FriendshipBraceletItem FRIENDSHIP_BRACELET = register("friendship_bracelet", new FriendshipBraceletItem(
new FabricItemSettings() new FabricItemSettings()
.rarity(Rarity.UNCOMMON) .rarity(Rarity.UNCOMMON)
.group(ItemGroup.TOOLS) ), ItemGroups.TOOLS);
));
Item EMPTY_JAR = register("empty_jar", new JarItem(new Item.Settings().group(ItemGroup.DECORATIONS).maxCount(16).fireproof(), false, false, false)); Item EMPTY_JAR = register("empty_jar", new JarItem(new Item.Settings().maxCount(16).fireproof(), false, false, false), ItemGroups.FUNCTIONAL);
FilledJarItem FILLED_JAR = register("filled_jar", new FilledJarItem(new Item.Settings().maxCount(1))); FilledJarItem FILLED_JAR = register("filled_jar", new FilledJarItem(new Item.Settings().maxCount(1)));
Item RAIN_CLOUD_JAR = register("rain_cloud_jar", new JarItem(new Item.Settings().group(ItemGroup.DECORATIONS).maxCount(1).fireproof(), true, false, false)); Item RAIN_CLOUD_JAR = register("rain_cloud_jar", new JarItem(new Item.Settings().maxCount(1).fireproof(), true, false, false), ItemGroups.FUNCTIONAL);
Item STORM_CLOUD_JAR = register("storm_cloud_jar", new JarItem(new Item.Settings().group(ItemGroup.DECORATIONS).maxCount(1).fireproof(), true, true, false)); Item STORM_CLOUD_JAR = register("storm_cloud_jar", new JarItem(new Item.Settings().maxCount(1).fireproof(), true, true, false), ItemGroups.FUNCTIONAL);
Item LIGHTNING_JAR = register("lightning_jar", new JarItem(new Item.Settings().group(ItemGroup.DECORATIONS).maxCount(1).fireproof(), false, false, true)); Item LIGHTNING_JAR = register("lightning_jar", new JarItem(new Item.Settings().maxCount(1).fireproof(), false, false, true), ItemGroups.FUNCTIONAL);
Item ZAP_APPLE_JAM_JAR = register("zap_apple_jam_jar", new JarItem(new Item.Settings().group(ItemGroup.DECORATIONS).maxCount(1).fireproof(), false, false, true)); Item ZAP_APPLE_JAM_JAR = register("zap_apple_jam_jar", new JarItem(new Item.Settings().maxCount(1).fireproof(), false, false, true), ItemGroups.FUNCTIONAL);
Item CRYSTAL_HEART = register("crystal_heart", new CrystalHeartItem(new Item.Settings().group(ItemGroup.DECORATIONS).maxCount(1))); Item CRYSTAL_HEART = register("crystal_heart", new CrystalHeartItem(new Item.Settings().maxCount(1)), ItemGroups.TOOLS);
Item CRYSTAL_SHARD = register("crystal_shard", new Item(new Item.Settings().group(ItemGroup.MATERIALS))); Item CRYSTAL_SHARD = register("crystal_shard", new Item(new Item.Settings()), ItemGroups.NATURAL);
Item GEMSTONE = register("gemstone", new GemstoneItem(new Item.Settings().group(ItemGroup.MATERIALS))); Item GEMSTONE = register("gemstone", new GemstoneItem(new Item.Settings()), ItemGroups.NATURAL);
Item BOTCHED_GEM = register("botched_gem", new Item(new Item.Settings().group(ItemGroup.MATERIALS))); Item BOTCHED_GEM = register("botched_gem", new Item(new Item.Settings()), ItemGroups.NATURAL);
Item PEGASUS_FEATHER = register("pegasus_feather", new Item(new Item.Settings().group(ItemGroup.MATERIALS))); Item PEGASUS_FEATHER = register("pegasus_feather", new Item(new Item.Settings()), ItemGroups.NATURAL);
Item GRYPHON_FEATHER = register("gryphon_feather", new Item(new Item.Settings().group(ItemGroup.MATERIALS))); Item GRYPHON_FEATHER = register("gryphon_feather", new Item(new Item.Settings()), ItemGroups.NATURAL);
Item OAT_SEEDS = register("oat_seeds", new AliasedBlockItem(UBlocks.OATS, new Item.Settings().group(ItemGroup.MATERIALS))); Item OAT_SEEDS = register("oat_seeds", new AliasedBlockItem(UBlocks.OATS, new Item.Settings()), ItemGroups.NATURAL);
Item OATS = register("oats", new Item(new Item.Settings().group(ItemGroup.FOOD).food(UFoodComponents.OATS))); Item OATS = register("oats", new Item(new Item.Settings().food(UFoodComponents.OATS)), ItemGroups.FOOD_AND_DRINK);
Item IMPORTED_OATS = register("imported_oats", new Item(new Item.Settings().group(ItemGroup.FOOD).food(UFoodComponents.IMPORTED_OATS))); Item IMPORTED_OATS = register("imported_oats", new Item(new Item.Settings().food(UFoodComponents.IMPORTED_OATS)), ItemGroups.FOOD_AND_DRINK);
Item OATMEAL = register("oatmeal", new OatmealItem(new Item.Settings().recipeRemainder(Items.BOWL).maxCount(1).group(ItemGroup.FOOD).food(UFoodComponents.OATMEAL))); Item OATMEAL = register("oatmeal", new OatmealItem(new Item.Settings().recipeRemainder(Items.BOWL).maxCount(1).food(UFoodComponents.OATMEAL)), ItemGroups.FOOD_AND_DRINK);
Item DAFFODIL_DAISY_SANDWICH = register("daffodil_daisy_sandwich", new Item(new Item.Settings().group(ItemGroup.FOOD).food(UFoodComponents.DAFODIL_DAISY_SANDWICH))); Item DAFFODIL_DAISY_SANDWICH = register("daffodil_daisy_sandwich", new Item(new Item.Settings().food(UFoodComponents.DAFODIL_DAISY_SANDWICH)), ItemGroups.FOOD_AND_DRINK);
Item HAY_BURGER = register("hay_burger", new Item(new Item.Settings().group(ItemGroup.FOOD).maxCount(1).food(UFoodComponents.HAY_BURGER))); Item HAY_BURGER = register("hay_burger", new Item(new Item.Settings().maxCount(1).food(UFoodComponents.HAY_BURGER)), ItemGroups.FOOD_AND_DRINK);
Item HAY_FRIES = register("hay_fries", new Item(new Item.Settings().group(ItemGroup.FOOD).maxCount(16).food(UFoodComponents.HAY_FRIES))); Item HAY_FRIES = register("hay_fries", new Item(new Item.Settings().maxCount(16).food(UFoodComponents.HAY_FRIES)), ItemGroups.FOOD_AND_DRINK);
Item WHEAT_WORMS = register("wheat_worms", new Item(new Item.Settings().group(ItemGroup.MISC).maxCount(16).food(UFoodComponents.INSECTS))); Item WHEAT_WORMS = register("wheat_worms", new Item(new Item.Settings().maxCount(16).food(UFoodComponents.INSECTS)), ItemGroups.NATURAL);
Item MUFFIN = register("muffin", new MuffinItem(new Item.Settings().group(ItemGroup.FOOD).maxCount(32).food(FoodComponents.BREAD), 0)); Item MUFFIN = register("muffin", new MuffinItem(new Item.Settings().maxCount(32).food(FoodComponents.BREAD), 0), ItemGroups.FOOD_AND_DRINK);
Item PINECONE = register("pinecone", new Item(new Item.Settings().group(ItemGroup.FOOD).food(UFoodComponents.PINECONE).maxCount(3))); Item PINECONE = register("pinecone", new Item(new Item.Settings().food(UFoodComponents.PINECONE).maxCount(3)), ItemGroups.FOOD_AND_DRINK);
Item ACORN = register("acorn", new Item(new Item.Settings().group(ItemGroup.FOOD).food(UFoodComponents.ACORN).maxCount(16))); Item ACORN = register("acorn", new Item(new Item.Settings().food(UFoodComponents.ACORN).maxCount(16)), ItemGroups.FOOD_AND_DRINK);
Item PEBBLES = register("pebbles", new RacePredicatedAliasedBlockItem(UBlocks.ROCKS, new Item.Settings().group(ItemGroup.MATERIALS), Race::canUseEarth)); Item PEBBLES = register("pebbles", new RacePredicatedAliasedBlockItem(UBlocks.ROCKS, new Item.Settings(), Race::canUseEarth), ItemGroups.NATURAL);
Item ROCK = register("rock", new HeavyProjectileItem(new Item.Settings().group(ItemGroup.MATERIALS), 3)); Item ROCK = register("rock", new HeavyProjectileItem(new Item.Settings(), 3), ItemGroups.NATURAL);
Item WEIRD_ROCK = register("weird_rock", new Item(new Item.Settings().group(ItemGroup.MATERIALS))); Item WEIRD_ROCK = register("weird_rock", new Item(new Item.Settings()), ItemGroups.NATURAL);
Item ROCK_STEW = register("rock_stew", new Item(new Item.Settings().group(ItemGroup.FOOD).food(FoodComponents.MUSHROOM_STEW))); Item ROCK_STEW = register("rock_stew", new Item(new Item.Settings().food(FoodComponents.MUSHROOM_STEW)), ItemGroups.FOOD_AND_DRINK);
Item GREEN_APPLE_SEEDS = register("green_apple_seeds", new AliasedBlockItem(UBlocks.GREEN_APPLE_SPROUT, new Item.Settings().group(ItemGroup.MATERIALS))); Item GREEN_APPLE_SEEDS = register("green_apple_seeds", new AliasedBlockItem(UBlocks.GREEN_APPLE_SPROUT, new Item.Settings()), ItemGroups.NATURAL);
Item SWEET_APPLE_SEEDS = register("sweet_apple_seeds", new AliasedBlockItem(UBlocks.SWEET_APPLE_SPROUT, new Item.Settings().group(ItemGroup.MATERIALS))); Item SWEET_APPLE_SEEDS = register("sweet_apple_seeds", new AliasedBlockItem(UBlocks.SWEET_APPLE_SPROUT, new Item.Settings()), ItemGroups.NATURAL);
Item SOUR_APPLE_SEEDS = register("sour_apple_seeds", new AliasedBlockItem(UBlocks.SOUR_APPLE_SPROUT, new Item.Settings().group(ItemGroup.MATERIALS))); Item SOUR_APPLE_SEEDS = register("sour_apple_seeds", new AliasedBlockItem(UBlocks.SOUR_APPLE_SPROUT, new Item.Settings()), ItemGroups.NATURAL);
Item MUG = register("mug", new Item(new Settings().group(ItemGroup.MATERIALS).maxCount(16))); Item MUG = register("mug", new Item(new Settings().maxCount(16)), ItemGroups.TOOLS);
Item CIDER = register("cider", new DrinkableItem(new Item.Settings().group(ItemGroup.FOOD).food(UFoodComponents.CIDER).maxCount(1).recipeRemainder(MUG))); Item CIDER = register("cider", new DrinkableItem(new Item.Settings().food(UFoodComponents.CIDER).maxCount(1).recipeRemainder(MUG)), ItemGroups.FOOD_AND_DRINK);
Item JUICE = register("juice", new DrinkableItem(new Item.Settings().group(ItemGroup.FOOD).recipeRemainder(Items.GLASS_BOTTLE).maxCount(1).food(UFoodComponents.JUICE))); Item JUICE = register("juice", new DrinkableItem(new Item.Settings().recipeRemainder(Items.GLASS_BOTTLE).maxCount(1).food(UFoodComponents.JUICE)), ItemGroups.FOOD_AND_DRINK);
Item BURNED_JUICE = register("burned_juice", new DrinkableItem(new Item.Settings().group(ItemGroup.FOOD).recipeRemainder(Items.GLASS_BOTTLE).maxCount(1).food(UFoodComponents.BURNED_JUICE))); Item BURNED_JUICE = register("burned_juice", new DrinkableItem(new Item.Settings().recipeRemainder(Items.GLASS_BOTTLE).maxCount(1).food(UFoodComponents.BURNED_JUICE)), ItemGroups.FOOD_AND_DRINK);
Item APPLE_PIE = register("apple_pie", new BlockItem(UBlocks.APPLE_PIE, new Item.Settings().group(ItemGroup.FOOD).maxCount(1))); Item APPLE_PIE = register("apple_pie", new BlockItem(UBlocks.APPLE_PIE, new Item.Settings().maxCount(1)), ItemGroups.FOOD_AND_DRINK);
Item APPLE_PIE_SLICE = register("apple_pie_slice", new Item(new Item.Settings().group(ItemGroup.FOOD).maxCount(16).food(UFoodComponents.PIE))); Item APPLE_PIE_SLICE = register("apple_pie_slice", new Item(new Item.Settings().maxCount(16).food(UFoodComponents.PIE)), ItemGroups.FOOD_AND_DRINK);
Item LOVE_BOTTLE = register("love_bottle", new DrinkableItem(new Item.Settings().group(ItemGroup.FOOD).food(UFoodComponents.LOVE_BOTTLE).maxCount(1).recipeRemainder(Items.GLASS_BOTTLE))); Item LOVE_BOTTLE = register("love_bottle", new DrinkableItem(new Item.Settings().food(UFoodComponents.LOVE_BOTTLE).maxCount(1).recipeRemainder(Items.GLASS_BOTTLE)), ItemGroups.FOOD_AND_DRINK);
Item LOVE_BUCKET = register("love_bucket", new DrinkableItem(new Item.Settings().group(ItemGroup.FOOD).food(UFoodComponents.LOVE_BUCKET).recipeRemainder(Items.BUCKET))); Item LOVE_BUCKET = register("love_bucket", new DrinkableItem(new Item.Settings().food(UFoodComponents.LOVE_BUCKET).recipeRemainder(Items.BUCKET)), ItemGroups.FOOD_AND_DRINK);
Item LOVE_MUG = register("love_mug", new DrinkableItem(new Item.Settings().group(ItemGroup.FOOD).food(UFoodComponents.LOVE_MUG).recipeRemainder(MUG))); Item LOVE_MUG = register("love_mug", new DrinkableItem(new Item.Settings().food(UFoodComponents.LOVE_MUG).recipeRemainder(MUG)), ItemGroups.FOOD_AND_DRINK);
Item GOLDEN_FEATHER = register("golden_feather", new Item(new Item.Settings().rarity(Rarity.UNCOMMON).group(ItemGroup.MATERIALS))); Item GOLDEN_FEATHER = register("golden_feather", new Item(new Item.Settings().rarity(Rarity.UNCOMMON)), ItemGroups.NATURAL);
Item GOLDEN_WING = register("golden_wing", new Item(new Item.Settings().rarity(Rarity.UNCOMMON).group(ItemGroup.MATERIALS))); Item GOLDEN_WING = register("golden_wing", new Item(new Item.Settings().rarity(Rarity.UNCOMMON)), ItemGroups.NATURAL);
Item DRAGON_BREATH_SCROLL = register("dragon_breath_scroll", new DragonBreathScrollItem(new Item.Settings().rarity(Rarity.UNCOMMON).group(ItemGroup.TOOLS))); Item DRAGON_BREATH_SCROLL = register("dragon_breath_scroll", new DragonBreathScrollItem(new Item.Settings().rarity(Rarity.UNCOMMON)), ItemGroups.TOOLS);
Item WOODEN_POLEARM = register("wooden_polearm", new PolearmItem(ToolMaterials.WOOD, 2, -3.6F, 2, new Item.Settings().group(ItemGroup.COMBAT))); Item WOODEN_POLEARM = register("wooden_polearm", new PolearmItem(ToolMaterials.WOOD, 2, -3.6F, 2, new Item.Settings()), ItemGroups.COMBAT);
Item STONE_POLEARM = register("stone_polearm", new PolearmItem(ToolMaterials.STONE, 2, -3.6F, 2, new Item.Settings().group(ItemGroup.COMBAT))); Item STONE_POLEARM = register("stone_polearm", new PolearmItem(ToolMaterials.STONE, 2, -3.6F, 2, new Item.Settings()), ItemGroups.COMBAT);
Item IRON_POLEARM = register("iron_polearm", new PolearmItem(ToolMaterials.IRON, 2, -3.6F, 3, new Item.Settings().group(ItemGroup.COMBAT))); Item IRON_POLEARM = register("iron_polearm", new PolearmItem(ToolMaterials.IRON, 2, -3.6F, 3, new Item.Settings()), ItemGroups.COMBAT);
Item GOLDEN_POLEARM = register("golden_polearm", new PolearmItem(ToolMaterials.GOLD, 2, -3.6F, 4, new Item.Settings().group(ItemGroup.COMBAT))); Item GOLDEN_POLEARM = register("golden_polearm", new PolearmItem(ToolMaterials.GOLD, 2, -3.6F, 4, new Item.Settings()), ItemGroups.COMBAT);
Item DIAMOND_POLEARM = register("diamond_polearm", new PolearmItem(ToolMaterials.DIAMOND, 2, -3.6F, 5, new Item.Settings().group(ItemGroup.COMBAT))); Item DIAMOND_POLEARM = register("diamond_polearm", new PolearmItem(ToolMaterials.DIAMOND, 2, -3.6F, 5, new Item.Settings()), ItemGroups.COMBAT);
Item NETHERITE_POLEARM = register("netherite_polearm", new PolearmItem(ToolMaterials.NETHERITE, 2, -3.6F, 5, new Item.Settings().group(ItemGroup.COMBAT).fireproof())); Item NETHERITE_POLEARM = register("netherite_polearm", new PolearmItem(ToolMaterials.NETHERITE, 2, -3.6F, 5, new Item.Settings().fireproof()), ItemGroups.COMBAT);
Item BUTTERFLY_SPAWN_EGG = register("butterfly_spawn_egg", new SpawnEggItem(UEntities.BUTTERFLY, 0x222200, 0xaaeeff, new Item.Settings().group(ItemGroup.MISC))); Item BUTTERFLY_SPAWN_EGG = register("butterfly_spawn_egg", new SpawnEggItem(UEntities.BUTTERFLY, 0x222200, 0xaaeeff, new Item.Settings()), ItemGroups.SPAWN_EGGS);
Item BUTTERFLY = register("butterfly", new Item(new Item.Settings().group(ItemGroup.FOOD).food(UFoodComponents.INSECTS))); Item BUTTERFLY = register("butterfly", new Item(new Item.Settings().food(UFoodComponents.INSECTS)), ItemGroups.FOOD_AND_DRINK);
Item SPELLBOOK = register("spellbook", new SpellbookItem(new Item.Settings().maxCount(1).rarity(Rarity.UNCOMMON).group(ItemGroup.TOOLS))); Item SPELLBOOK = register("spellbook", new SpellbookItem(new Item.Settings().maxCount(1).rarity(Rarity.UNCOMMON)), ItemGroups.TOOLS);
AmuletItem PEGASUS_AMULET = register("pegasus_amulet", new PegasusAmuletItem(new FabricItemSettings() AmuletItem PEGASUS_AMULET = register("pegasus_amulet", new PegasusAmuletItem(new FabricItemSettings()
.maxCount(1) .maxCount(1)
.maxDamage(890) .maxDamage(890)
.rarity(Rarity.UNCOMMON) .rarity(Rarity.UNCOMMON), 900), ItemGroups.TOOLS);
.group(ItemGroup.DECORATIONS), 900));
AlicornAmuletItem ALICORN_AMULET = register("alicorn_amulet", new AlicornAmuletItem(new FabricItemSettings() AlicornAmuletItem ALICORN_AMULET = register("alicorn_amulet", new AlicornAmuletItem(new FabricItemSettings()
.maxCount(1) .maxCount(1)
.maxDamage(1000) .maxDamage(1000)
.rarity(Rarity.RARE) .rarity(Rarity.RARE)), ItemGroups.TOOLS);
.group(ItemGroup.DECORATIONS)));
GlassesItem SUNGLASSES = register("sunglasses", new GlassesItem(new FabricItemSettings().maxCount(1).group(ItemGroup.COMBAT))); GlassesItem SUNGLASSES = register("sunglasses", new GlassesItem(new FabricItemSettings().maxCount(1)), ItemGroups.COMBAT);
GlassesItem BROKEN_SUNGLASSES = register("broken_sunglasses", new GlassesItem(new FabricItemSettings().maxCount(1).group(ItemGroup.COMBAT))); GlassesItem BROKEN_SUNGLASSES = register("broken_sunglasses", new GlassesItem(new FabricItemSettings().maxCount(1)), ItemGroups.COMBAT);
static <T extends Item> T register(String name, T item, ItemGroup group) {
return ItemGroupRegistry.register(register(name, item), group);
}
@Deprecated
static <T extends Item> T register(String name, T item) { static <T extends Item> T register(String name, T item) {
return register(Unicopia.id(name), item); return register(Unicopia.id(name), item);
} }
@ -134,15 +137,14 @@ public interface UItems {
if (item instanceof BlockItem) { if (item instanceof BlockItem) {
((BlockItem)item).appendBlocks(Item.BLOCK_ITEMS, item); ((BlockItem)item).appendBlocks(Item.BLOCK_ITEMS, item);
} }
return Registry.register(Registry.ITEM, id, item); return Registry.register(Registries.ITEM, id, item);
} }
static MusicDiscItem register(String name, SoundEvent sound, int seconds) { static MusicDiscItem register(String name, SoundEvent sound, int seconds) {
return register(name, new MusicDiscItem(1, sound, new Settings() return register(name, new MusicDiscItem(1, sound, new Settings()
.maxCount(1) .maxCount(1)
.group(ItemGroup.MISC)
.rarity(Rarity.RARE), seconds .rarity(Rarity.RARE), seconds
) {}); ) {}, ItemGroups.TOOLS);
} }
static void bootstrap() { static void bootstrap() {

View file

@ -1,15 +1,18 @@
package com.minelittlepony.unicopia.item; package com.minelittlepony.unicopia.item;
import java.util.List;
import com.minelittlepony.unicopia.UTags; import com.minelittlepony.unicopia.UTags;
import com.minelittlepony.unicopia.Unicopia; import com.minelittlepony.unicopia.Unicopia;
import com.minelittlepony.unicopia.advancement.UCriteria; import com.minelittlepony.unicopia.advancement.UCriteria;
import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.entity.player.Pony;
import com.minelittlepony.unicopia.item.group.MultiItem;
import com.minelittlepony.unicopia.item.toxin.*; import com.minelittlepony.unicopia.item.toxin.*;
import com.minelittlepony.unicopia.particle.ParticleUtils; import com.minelittlepony.unicopia.particle.ParticleUtils;
import com.minelittlepony.unicopia.particle.UParticles; import com.minelittlepony.unicopia.particle.UParticles;
import com.minelittlepony.unicopia.util.MagicalDamageSource; import com.minelittlepony.unicopia.util.MagicalDamageSource;
import com.minelittlepony.unicopia.util.TraceHelper; import com.minelittlepony.unicopia.util.TraceHelper;
import com.minelittlepony.unicopia.util.Registries; import com.minelittlepony.unicopia.util.RegistryUtils;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType; import net.minecraft.entity.EntityType;
@ -24,7 +27,6 @@ import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld; import net.minecraft.server.world.ServerWorld;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import net.minecraft.util.ActionResult; import net.minecraft.util.ActionResult;
import net.minecraft.util.collection.DefaultedList;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
import net.minecraft.util.Hand; import net.minecraft.util.Hand;
import net.minecraft.util.Rarity; import net.minecraft.util.Rarity;
@ -33,7 +35,7 @@ import net.minecraft.registry.Registries;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraft.world.event.GameEvent; import net.minecraft.world.event.GameEvent;
public class ZapAppleItem extends Item implements ChameleonItem, ToxicHolder { public class ZapAppleItem extends Item implements ChameleonItem, ToxicHolder, MultiItem {
public ZapAppleItem(Settings settings) { public ZapAppleItem(Settings settings) {
super(settings); super(settings);
} }
@ -98,18 +100,15 @@ public class ZapAppleItem extends Item implements ChameleonItem, ToxicHolder {
} }
@Override @Override
public void appendStacks(ItemGroup tab, DefaultedList<ItemStack> items) { public List<ItemStack> getDefaultStacks() {
super.appendStacks(tab, items); return Unicopia.SIDE.getPony().map(Pony::getReferenceWorld)
if (tab.contains(getDefaultStack())) {
Unicopia.SIDE.getPony().map(Pony::getReferenceWorld)
.stream() .stream()
.flatMap(world -> Registries.valuesForTag(world, UTags.APPLES)) .flatMap(world -> RegistryUtils.valuesForTag(world, UTags.APPLES))
.filter(a -> a != this).forEach(item -> { .filter(a -> a != this).map(item -> {
ItemStack stack = new ItemStack(this); ItemStack stack = new ItemStack(this);
stack.getOrCreateNbt().putString("appearance", Registries.ITEM.getId(item).toString()); stack.getOrCreateNbt().putString("appearance", Registries.ITEM.getId(item).toString());
items.add(stack); return stack;
}); }).toList();
}
} }
@Override @Override

View file

@ -0,0 +1,70 @@
package com.minelittlepony.unicopia.item.group;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;
import java.util.stream.Stream;
import com.google.common.cache.*;
import com.minelittlepony.unicopia.UTags;
import com.minelittlepony.unicopia.Unicopia;
import net.fabricmc.fabric.api.itemgroup.v1.FabricItemGroup;
import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents;
import net.minecraft.item.*;
import net.minecraft.registry.Registries;
import net.minecraft.registry.tag.TagKey;
public interface ItemGroupRegistry {
LoadingCache<Item, List<ItemStack>> STACK_VARIANCES_CACHE = CacheBuilder.newBuilder()
.expireAfterAccess(30, TimeUnit.SECONDS)
.build(CacheLoader.from(i -> {
if (i instanceof MultiItem m) {
return m.getDefaultStacks();
}
return ItemGroups.SEARCH.getSearchTabStacks().stream().filter(s -> s.getItem() == i).toList();
}));
static List<ItemStack> getVariations(Item item) {
return STACK_VARIANCES_CACHE.getUnchecked(item);
}
Map<ItemGroup, Set<Item>> REGISTRY = new HashMap<>();
static <T extends Item> T register(T item, ItemGroup group) {
REGISTRY.computeIfAbsent(group, g -> new HashSet<>()).add(item);
return item;
}
static ItemGroup createDynamic(String name, Supplier<ItemStack> icon, Supplier<Stream<Item>> items) {
boolean[] reloading = new boolean[1];
return FabricItemGroup.builder(Unicopia.id(name)).entries((features, list, k) -> {
if (reloading[0]) {
return;
}
reloading[0] = true;
items.get().forEach(item -> {
list.addAll(ItemGroupRegistry.getVariations(item));
});
reloading[0] = false;
}).icon(icon).build();
}
static ItemGroup createGroupFromTag(String name, Supplier<ItemStack> icon) {
TagKey<Item> key = UTags.item("groups/" + name);
return createDynamic(name, icon, () -> {
return Registries.ITEM.getEntryList(key)
.stream()
.flatMap(named -> named.stream())
.map(entry -> entry.value());
});
}
static void bootstrap() {
REGISTRY.forEach((group, items) -> {
ItemGroupEvents.modifyEntriesEvent(group).register(event -> {
event.addAll(items.stream().map(Item::getDefaultStack).toList());
});
});
}
}

View file

@ -0,0 +1,9 @@
package com.minelittlepony.unicopia.item.group;
import java.util.List;
import net.minecraft.item.ItemStack;
public interface MultiItem {
List<ItemStack> getDefaultStacks();
}

View file

@ -0,0 +1 @@
package com.minelittlepony.unicopia.item.group;

View file

@ -1,7 +1,7 @@
package com.minelittlepony.unicopia.item.toxin; package com.minelittlepony.unicopia.item.toxin;
import com.minelittlepony.unicopia.*; import com.minelittlepony.unicopia.*;
import com.minelittlepony.unicopia.util.Registries; import com.minelittlepony.unicopia.util.RegistryUtils;
import net.minecraft.registry.Registry; import net.minecraft.registry.Registry;
@ -10,7 +10,7 @@ import static com.minelittlepony.unicopia.item.toxin.Ailment.*;
import static com.minelittlepony.unicopia.item.toxin.Toxin.*; import static com.minelittlepony.unicopia.item.toxin.Toxin.*;
public interface Toxics { public interface Toxics {
Registry<ToxicRegistryEntry> REGISTRY = Registries.createSimple(Unicopia.id("toxic")); Registry<ToxicRegistryEntry> REGISTRY = RegistryUtils.createSimple(Unicopia.id("toxic"));
Toxic SEVERE_INNERT = Toxic.innert(Toxicity.SEVERE); Toxic SEVERE_INNERT = Toxic.innert(Toxicity.SEVERE);

View file

@ -12,7 +12,7 @@ import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.registry.entry.RegistryEntryList; import net.minecraft.registry.entry.RegistryEntryList;
import net.minecraft.world.World; import net.minecraft.world.World;
public interface Registries { public interface RegistryUtils {
static <T> Registry<T> createSimple(Identifier id) { static <T> Registry<T> createSimple(Identifier id) {
return FabricRegistryBuilder.from(new SimpleRegistry<T>(RegistryKey.ofRegistry(id), Lifecycle.stable())).buildAndRegister(); return FabricRegistryBuilder.from(new SimpleRegistry<T>(RegistryKey.ofRegistry(id), Lifecycle.stable())).buildAndRegister();
} }