diff --git a/src/main/java/com/minelittlepony/unicopia/client/DiscoveryToast.java b/src/main/java/com/minelittlepony/unicopia/client/DiscoveryToast.java index e1484d4e..d5cab177 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/DiscoveryToast.java +++ b/src/main/java/com/minelittlepony/unicopia/client/DiscoveryToast.java @@ -17,7 +17,7 @@ import net.minecraft.util.Identifier; public class DiscoveryToast implements Toast { private static final long MAX_AGE = 5000L; - private static final Identifier TEXTURE = new Identifier("toast/advancement"); + private static final Identifier TEXTURE = Identifier.ofVanilla("toast/advancement"); private static final Text TITLE = Text.translatable("unicopia.toast.discoveries.title"); private static final Text DESCRIPTION = Text.translatable("unicopia.toast.discoveries.description"); diff --git a/src/main/java/com/minelittlepony/unicopia/client/FirstPersonRendererOverrides.java b/src/main/java/com/minelittlepony/unicopia/client/FirstPersonRendererOverrides.java index b3b00c53..0c742d7b 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/FirstPersonRendererOverrides.java +++ b/src/main/java/com/minelittlepony/unicopia/client/FirstPersonRendererOverrides.java @@ -31,7 +31,7 @@ public class FirstPersonRendererOverrides { } if (Pony.of(player).getAnimation().renderBothArms()) { - float swingProgress = player.getHandSwingProgress(MinecraftClient.getInstance().getTickDelta()); + float swingProgress = player.getHandSwingProgress(MinecraftClient.getInstance().getRenderTickCounter().getTickDelta(false)); Hand hand = MoreObjects.firstNonNull(player.preferredHand, Hand.MAIN_HAND); diff --git a/src/main/java/com/minelittlepony/unicopia/client/ModifierTooltipRenderer.java b/src/main/java/com/minelittlepony/unicopia/client/ModifierTooltipRenderer.java index cc034d96..a58c5bd3 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/ModifierTooltipRenderer.java +++ b/src/main/java/com/minelittlepony/unicopia/client/ModifierTooltipRenderer.java @@ -1,49 +1,25 @@ package com.minelittlepony.unicopia.client; -import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.stream.Stream; - -import org.jetbrains.annotations.Nullable; - -import com.google.common.collect.Multimap; -import com.minelittlepony.unicopia.entity.Equine; -import com.minelittlepony.unicopia.entity.mob.UEntityAttributes; import com.minelittlepony.unicopia.entity.player.Pony; -import com.minelittlepony.unicopia.item.enchantment.AttributedEnchantment; import net.fabricmc.fabric.api.client.item.v1.ItemTooltipCallback; import net.minecraft.client.MinecraftClient; -import net.minecraft.enchantment.Enchantment; -import net.minecraft.entity.EquipmentSlot; -import net.minecraft.entity.attribute.EntityAttribute; -import net.minecraft.entity.attribute.EntityAttributeModifier; -import net.minecraft.entity.attribute.EntityAttributes; -import net.minecraft.entity.attribute.EntityAttributeModifier.Operation; -import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.item.tooltip.TooltipType; -import net.minecraft.nbt.NbtCompound; -import net.minecraft.screen.ScreenTexts; import net.minecraft.text.Text; -import net.minecraft.util.Formatting; -import net.minecraft.util.Identifier; -import net.minecraft.util.Pair; -import net.minecraft.registry.Registries; -import net.minecraft.registry.entry.RegistryEntry; public class ModifierTooltipRenderer implements ItemTooltipCallback { @Override public void getTooltip(ItemStack stack, Item.TooltipContext tooltipContext, TooltipType tooltipType, List lines) { - int flags = stack.hasNbt() && stack.getNbt().contains("HideFlags", 99) ? stack.getNbt().getInt("HideFlags") : 0; + // TODO: Evaluate if we still need this + /*int flags = stack.hasNbt() && stack.getNbt().contains("HideFlags", 99) ? stack.getNbt().getInt("HideFlags") : 0; if (isShowing(flags, ItemStack.TooltipSection.MODIFIERS)) { + Enchantment s; Map> modifiers = new HashMap<>(); Equine.of(MinecraftClient.getInstance().player).ifPresent(eq -> { @@ -72,13 +48,13 @@ public class ModifierTooltipRenderer implements ItemTooltipCallback { } } }); - } + }*/ if (MinecraftClient.getInstance().player != null) { Pony.of(MinecraftClient.getInstance().player).getDiscoveries().appendTooltip(stack, MinecraftClient.getInstance().world, lines); } } - +/* private int getInsertPosition(ItemStack stack, Text category, int flags, List lines, boolean advanced) { int insertPosition = lines.indexOf(category); @@ -166,5 +142,5 @@ public class ModifierTooltipRenderer implements ItemTooltipCallback { return Stream.empty(); } - +*/ } diff --git a/src/main/java/com/minelittlepony/unicopia/client/URenderers.java b/src/main/java/com/minelittlepony/unicopia/client/URenderers.java index 617041bd..0236ee39 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/URenderers.java +++ b/src/main/java/com/minelittlepony/unicopia/client/URenderers.java @@ -48,7 +48,6 @@ import net.minecraft.block.BlockState; import net.minecraft.block.entity.BlockEntity; import net.minecraft.client.MinecraftClient; import net.minecraft.client.color.world.BiomeColors; -import net.minecraft.client.color.world.FoliageColors; import net.minecraft.client.item.ClampedModelPredicateProvider; import net.minecraft.client.item.ModelPredicateProviderRegistry; import net.minecraft.client.particle.Particle; @@ -61,14 +60,17 @@ import net.minecraft.client.render.item.ItemRenderer; import net.minecraft.client.render.model.json.ModelTransformationMode; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.client.world.ClientWorld; +import net.minecraft.component.type.DyedColorComponent; import net.minecraft.entity.Entity; import net.minecraft.entity.LivingEntity; import net.minecraft.fluid.Fluids; import net.minecraft.item.*; import net.minecraft.particle.ParticleEffect; +import net.minecraft.util.Colors; import net.minecraft.util.Identifier; import net.minecraft.util.math.BlockPos; import net.minecraft.world.BlockRenderView; +import net.minecraft.world.biome.FoliageColors; public interface URenderers { BlockEntity CHEST_RENDER_ENTITY = new CloudChestBlock.TileData(BlockPos.ORIGIN, UBlocks.CLOUD_CHEST.getDefaultState()); @@ -126,10 +128,10 @@ public interface URenderers { register(URenderers::renderBedItem, UItems.CLOTH_BED, UItems.CLOUD_BED); register(URenderers::renderChestItem, UBlocks.CLOUD_CHEST.asItem()); PolearmRenderer.register(UItems.WOODEN_POLEARM, UItems.STONE_POLEARM, UItems.IRON_POLEARM, UItems.GOLDEN_POLEARM, UItems.DIAMOND_POLEARM, UItems.NETHERITE_POLEARM); - ModelPredicateProviderRegistry.register(UItems.GEMSTONE, new Identifier("affinity"), (stack, world, entity, seed) -> EnchantableItem.getSpellKey(stack).getAffinity().getAlignment()); - ModelPredicateProviderRegistry.register(UItems.GEMSTONE, new Identifier("shape"), (stack, world, entity, seed) -> EnchantableItem.getSpellKey(stack).getGemShape().getId()); - ModelPredicateProviderRegistry.register(UItems.ROCK_CANDY, new Identifier("count"), (stack, world, entity, seed) -> stack.getCount() / (float)stack.getMaxCount()); - ModelPredicateProviderRegistry.register(UItems.BUTTERFLY, new Identifier("variant"), (stack, world, entity, seed) -> (float)ButterflyItem.getVariant(stack).ordinal() / ButterflyEntity.Variant.VALUES.length); + ModelPredicateProviderRegistry.register(UItems.GEMSTONE, Identifier.ofVanilla("affinity"), (stack, world, entity, seed) -> EnchantableItem.getSpellKey(stack).getAffinity().getAlignment()); + ModelPredicateProviderRegistry.register(UItems.GEMSTONE, Identifier.ofVanilla("shape"), (stack, world, entity, seed) -> EnchantableItem.getSpellKey(stack).getGemShape().getId()); + ModelPredicateProviderRegistry.register(UItems.ROCK_CANDY, Identifier.ofVanilla("count"), (stack, world, entity, seed) -> stack.getCount() / (float)stack.getMaxCount()); + ModelPredicateProviderRegistry.register(UItems.BUTTERFLY, Identifier.ofVanilla("variant"), (stack, world, entity, seed) -> (float)ButterflyItem.getVariant(stack).ordinal() / ButterflyEntity.Variant.VALUES.length); ModelPredicateProviderRegistry.register(Unicopia.id("zap_cycle"), new ClampedModelPredicateProvider() { private double targetAngle; private double lastAngle; @@ -159,7 +161,7 @@ public interface URenderers { ColorProviderRegistry.BLOCK.register(URenderers::getTintedBlockColor, TintedBlock.REGISTRY.stream().toArray(Block[]::new)); ColorProviderRegistry.ITEM.register((stack, i) -> getTintedBlockColor(Block.getBlockFromItem(stack.getItem()).getDefaultState(), null, null, i), TintedBlock.REGISTRY.stream().map(Block::asItem).filter(i -> i != Items.AIR).toArray(Item[]::new)); - ColorProviderRegistry.ITEM.register((stack, i) -> i > 0 ? -1 : ((DyeableItem)stack.getItem()).getColor(stack), UItems.FRIENDSHIP_BRACELET); + ColorProviderRegistry.ITEM.register((stack, i) -> i > 0 ? -1 : DyedColorComponent.getColor(stack, Colors.WHITE), UItems.FRIENDSHIP_BRACELET); ColorProviderRegistry.ITEM.register((stack, i) -> i > 0 || !EnchantableItem.isEnchanted(stack) ? -1 : EnchantableItem.getSpellKey(stack).getColor(), UItems.GEMSTONE); ColorProviderRegistry.ITEM.register((stack, i) -> i == 1 && EnchantableItem.isEnchanted(stack) ? EnchantableItem.getSpellKey(stack).getColor() : -1, UItems.MAGIC_STAFF); @@ -240,11 +242,7 @@ public interface URenderers { } private static int getTintedBlockColor(BlockState state, @Nullable BlockRenderView view, @Nullable BlockPos pos, int color) { - if (view == null || pos == null) { - color = FoliageColors.getDefaultColor(); - } else { - color = BiomeColors.getFoliageColor(view, pos); - } + color = view == null || pos == null ? FoliageColors.getDefaultColor() : BiomeColors.getFoliageColor(view, pos); if (state.getBlock() instanceof TintedBlock block) { return block.getTint(state, view, pos, color); diff --git a/src/main/java/com/minelittlepony/unicopia/client/particle/CloudsEscapingParticle.java b/src/main/java/com/minelittlepony/unicopia/client/particle/CloudsEscapingParticle.java index 32ff15f7..673d3fcf 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/particle/CloudsEscapingParticle.java +++ b/src/main/java/com/minelittlepony/unicopia/client/particle/CloudsEscapingParticle.java @@ -4,13 +4,13 @@ import com.minelittlepony.unicopia.particle.ParticleUtils; import com.minelittlepony.unicopia.util.shape.Sphere; import net.minecraft.client.world.ClientWorld; -import net.minecraft.particle.DefaultParticleType; import net.minecraft.particle.ParticleTypes; +import net.minecraft.particle.SimpleParticleType; import net.minecraft.util.math.Vec3d; public class CloudsEscapingParticle extends GroundPoundParticle { - public CloudsEscapingParticle(DefaultParticleType effect, ClientWorld world, double x, double y, double z, double dX, double dY, double dZ) { + public CloudsEscapingParticle(SimpleParticleType effect, ClientWorld world, double x, double y, double z, double dX, double dY, double dZ) { super(effect, world, x, y, z, dX, dY, dZ); maxAge = 200; collidesWithWorld = false; diff --git a/src/main/java/com/minelittlepony/unicopia/client/particle/GroundPoundParticle.java b/src/main/java/com/minelittlepony/unicopia/client/particle/GroundPoundParticle.java index 5287b7f0..ca7fdaef 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/particle/GroundPoundParticle.java +++ b/src/main/java/com/minelittlepony/unicopia/client/particle/GroundPoundParticle.java @@ -11,14 +11,14 @@ import net.minecraft.client.render.Camera; import net.minecraft.client.render.VertexConsumer; import net.minecraft.client.world.ClientWorld; import net.minecraft.particle.BlockStateParticleEffect; -import net.minecraft.particle.DefaultParticleType; import net.minecraft.particle.ParticleTypes; +import net.minecraft.particle.SimpleParticleType; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; public class GroundPoundParticle extends Particle { - public GroundPoundParticle(DefaultParticleType effect, ClientWorld world, double x, double y, double z, double dX, double dY, double dZ) { + public GroundPoundParticle(SimpleParticleType effect, ClientWorld world, double x, double y, double z, double dX, double dY, double dZ) { super(world, x, y, z, dX, dY, dZ); maxAge = 10; } diff --git a/src/main/java/com/minelittlepony/unicopia/client/particle/ShockwaveParticle.java b/src/main/java/com/minelittlepony/unicopia/client/particle/ShockwaveParticle.java index 878333ba..75cc73f6 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/particle/ShockwaveParticle.java +++ b/src/main/java/com/minelittlepony/unicopia/client/particle/ShockwaveParticle.java @@ -9,7 +9,7 @@ import net.minecraft.client.render.LightmapTextureManager; import net.minecraft.client.render.Tessellator; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.client.world.ClientWorld; -import net.minecraft.particle.DefaultParticleType; +import net.minecraft.particle.SimpleParticleType; import net.minecraft.sound.SoundCategory; import net.minecraft.util.Identifier; import net.minecraft.util.math.BlockPos; @@ -19,7 +19,7 @@ import net.minecraft.util.math.RotationAxis; public class ShockwaveParticle extends AbstractBillboardParticle { private static final Identifier TEXTURE = Unicopia.id("textures/particles/shockwave.png"); - public ShockwaveParticle(DefaultParticleType effect, ClientWorld world, double x, double y, double z, double velocityX, double velocityY, + public ShockwaveParticle(SimpleParticleType effect, ClientWorld world, double x, double y, double z, double velocityX, double velocityY, double velocityZ) { super(world, x, y, z, 0, 0, 0); maxAge = 20; diff --git a/src/main/java/com/minelittlepony/unicopia/datagen/providers/loot/UBlockAdditionsLootTableProvider.java b/src/main/java/com/minelittlepony/unicopia/datagen/providers/loot/UBlockAdditionsLootTableProvider.java index cd374e14..d49646c5 100644 --- a/src/main/java/com/minelittlepony/unicopia/datagen/providers/loot/UBlockAdditionsLootTableProvider.java +++ b/src/main/java/com/minelittlepony/unicopia/datagen/providers/loot/UBlockAdditionsLootTableProvider.java @@ -1,5 +1,6 @@ package com.minelittlepony.unicopia.datagen.providers.loot; +import java.util.List; import java.util.concurrent.CompletableFuture; import java.util.function.Function; @@ -31,25 +32,42 @@ import net.minecraft.loot.provider.number.UniformLootNumberProvider; import net.minecraft.predicate.NumberRange; import net.minecraft.predicate.entity.LocationPredicate; import net.minecraft.predicate.item.EnchantmentPredicate; +import net.minecraft.predicate.item.EnchantmentsPredicate; import net.minecraft.predicate.item.ItemPredicate; +import net.minecraft.predicate.item.ItemSubPredicateTypes; +import net.minecraft.registry.RegistryKey; +import net.minecraft.registry.RegistryKeys; import net.minecraft.registry.RegistryWrapper; +import net.minecraft.registry.entry.RegistryEntry; import net.minecraft.util.Identifier; import net.minecraft.world.biome.BiomeKeys; public class UBlockAdditionsLootTableProvider extends FabricBlockLootTableProvider { - public static final LootCondition.Builder WITH_GEM_FINDER = MatchToolLootCondition.builder(ItemPredicate.Builder.create().enchantment(new EnchantmentPredicate(UEnchantments.GEM_FINDER, NumberRange.IntRange.atLeast(1)))); - - public static final LootCondition.Builder WITHOUT_SILK_TOUCH_AND_GEM_FINDER = WITHOUT_SILK_TOUCH.and(WITH_GEM_FINDER); public static final float[] GEMSTONES_FORTUNE_CHANCE = { 0.1F, 0.14285715F, 0.25F, 1F }; - public static final LootCondition.Builder NEEDS_OCEAN_OR_BEACH_BIOME = - LocationCheckLootCondition.builder(LocationPredicate.Builder.create().biome(BiomeKeys.OCEAN)) - .or(LocationCheckLootCondition.builder(LocationPredicate.Builder.create().biome(BiomeKeys.BEACH))); - public UBlockAdditionsLootTableProvider(FabricDataOutput dataOutput, CompletableFuture registryLookup) { super(dataOutput, registryLookup); } + public LootCondition.Builder createNeedsOceanOrBeachCondition() { + return LocationCheckLootCondition.builder(LocationPredicate.Builder.createBiome(entryOf(BiomeKeys.OCEAN))) + .or(LocationCheckLootCondition.builder(LocationPredicate.Builder.createBiome(entryOf(BiomeKeys.BEACH)))); + } + + public LootCondition.Builder createWithoutSilkTouchOrGemFinderCondition() { + return createWithoutSilkTouchCondition().and(createWithGemFinderCondition()); + } + + public LootCondition.Builder createWithGemFinderCondition() { + return MatchToolLootCondition.builder(ItemPredicate.Builder.create().subPredicate(ItemSubPredicateTypes.ENCHANTMENTS, EnchantmentsPredicate.enchantments(List.of( + new EnchantmentPredicate(UEnchantments.GEM_FINDER, NumberRange.IntRange.atLeast(1)) + )))); + } + + public RegistryEntry entryOf(RegistryKey key) { + return registryLookup.getWrapperOrThrow(key.getRegistryRef()).getOrThrow(key); + } + @Override public String getName() { return "Block Loot Table Additions"; @@ -73,17 +91,17 @@ public class UBlockAdditionsLootTableProvider extends FabricBlockLootTableProvid } private void addVanillaDrop(Block block, Function lootTableFunction) { - lootTables.put(new Identifier("unicopiamc", block.getLootTableId().getPath()), lootTableFunction.apply(block)); + lootTables.put(RegistryKey.of(RegistryKeys.LOOT_TABLE, Identifier.of("unicopiamc", block.getLootTableKey().getValue().getPath())), lootTableFunction.apply(block)); } public LootTable.Builder shellDrops(Block block) { return LootTable.builder().pool(LootPool.builder() .rolls(ConstantLootNumberProvider.create(1)) - .conditionally(WITHOUT_SILK_TOUCH.and(NEEDS_OCEAN_OR_BEACH_BIOME)) + .conditionally(createWithoutSilkTouchCondition().and(createNeedsOceanOrBeachCondition())) .with(applyExplosionDecay(block, TagEntry.builder(UTags.Items.SHELLS) .apply(SetCountLootFunction.builder(ConstantLootNumberProvider.create(1))) ) - .conditionally(TableBonusLootCondition.builder(Enchantments.FORTUNE, GEMSTONES_FORTUNE_CHANCE))) + .conditionally(TableBonusLootCondition.builder(entryOf(Enchantments.FORTUNE), GEMSTONES_FORTUNE_CHANCE))) ); } @@ -91,7 +109,7 @@ public class UBlockAdditionsLootTableProvider extends FabricBlockLootTableProvid return LootTable.builder() .pool(LootPool.builder() .rolls(ConstantLootNumberProvider.create(1)) - .conditionally(WITHOUT_SILK_TOUCH.and(WITH_SHEARS)) + .conditionally(createWithoutSilkTouchCondition().and(WITH_SHEARS)) .with(chanceDrops(block, drop, 1, chance)) ); } @@ -100,7 +118,7 @@ public class UBlockAdditionsLootTableProvider extends FabricBlockLootTableProvid return LootTable.builder() .pool(LootPool.builder() .rolls(ConstantLootNumberProvider.create(1)) - .conditionally(WITHOUT_SILK_TOUCH) + .conditionally(createWithoutSilkTouchCondition()) .with(chanceDrops(block, UItems.WHEAT_WORMS, max, chance)) ); } @@ -109,7 +127,7 @@ public class UBlockAdditionsLootTableProvider extends FabricBlockLootTableProvid return LootTable.builder() .pool(LootPool.builder() .rolls(ConstantLootNumberProvider.create(1)) - .conditionally(WITHOUT_SILK_TOUCH) + .conditionally(createWithoutSilkTouchCondition()) .with(gemstoneDrops(block, 0.1F)) .with(chanceDrops(block, UItems.WHEAT_WORMS, max, chance)) ); @@ -119,7 +137,7 @@ public class UBlockAdditionsLootTableProvider extends FabricBlockLootTableProvid return LootTable.builder() .pool(LootPool.builder() .rolls(ConstantLootNumberProvider.create(1)) - .conditionally(WITHOUT_SILK_TOUCH) + .conditionally(createWithoutSilkTouchCondition()) .with(gemstoneDrops(block, 0.1F)) ); } @@ -128,10 +146,10 @@ public class UBlockAdditionsLootTableProvider extends FabricBlockLootTableProvid return LootTable.builder() .pool(LootPool.builder() .rolls(ConstantLootNumberProvider.create(1)) - .conditionally(WITHOUT_SILK_TOUCH) + .conditionally(createWithoutSilkTouchCondition()) .with(applyExplosionDecay(block, ItemEntry.builder(UItems.CRYSTAL_SHARD) .apply(SetCountLootFunction.builder(UniformLootNumberProvider.create(1, 2))) - .apply(ApplyBonusLootFunction.oreDrops(Enchantments.FORTUNE)) + .apply(ApplyBonusLootFunction.oreDrops(entryOf(Enchantments.FORTUNE))) ) .conditionally(RandomChanceLootCondition.builder(0.25F)) ) @@ -142,19 +160,19 @@ public class UBlockAdditionsLootTableProvider extends FabricBlockLootTableProvid return applyExplosionDecay(block, ItemEntry.builder(UItems.GEMSTONE) .apply(SetCountLootFunction.builder(UniformLootNumberProvider.create(1, 2))) ) - .conditionally(WITH_GEM_FINDER) + .conditionally(createWithGemFinderCondition()) .conditionally(RandomChanceLootCondition.builder(0.1F)) - .conditionally(TableBonusLootCondition.builder(Enchantments.FORTUNE, GEMSTONES_FORTUNE_CHANCE)); + .conditionally(TableBonusLootCondition.builder(entryOf(Enchantments.FORTUNE), GEMSTONES_FORTUNE_CHANCE)); } public LootPoolEntry.Builder chanceDrops(Block block, ItemConvertible drop, int max, float...chance) { return applyExplosionDecay(block, ItemEntry.builder(drop) .apply(SetCountLootFunction.builder(UniformLootNumberProvider.create(1, max))) ) - .conditionally(TableBonusLootCondition.builder(Enchantments.FORTUNE, chance)); + .conditionally(TableBonusLootCondition.builder(entryOf(Enchantments.FORTUNE), chance)); } - public static LootTable.Builder dropsWithGemfinding(Block drop, LootPoolEntry.Builder child) { - return BlockLootTableGenerator.drops(drop, WITHOUT_SILK_TOUCH_AND_GEM_FINDER, child); + public LootTable.Builder dropsWithGemfinding(Block drop, LootPoolEntry.Builder child) { + return BlockLootTableGenerator.drops(drop, createWithoutSilkTouchOrGemFinderCondition(), child); } } diff --git a/src/main/java/com/minelittlepony/unicopia/datagen/providers/loot/UBlockLootTableProvider.java b/src/main/java/com/minelittlepony/unicopia/datagen/providers/loot/UBlockLootTableProvider.java index c39e781c..247ac2ad 100644 --- a/src/main/java/com/minelittlepony/unicopia/datagen/providers/loot/UBlockLootTableProvider.java +++ b/src/main/java/com/minelittlepony/unicopia/datagen/providers/loot/UBlockLootTableProvider.java @@ -1,6 +1,7 @@ package com.minelittlepony.unicopia.datagen.providers.loot; import java.util.List; +import java.util.concurrent.CompletableFuture; import com.minelittlepony.unicopia.Unicopia; import com.minelittlepony.unicopia.block.EdibleBlock; @@ -19,7 +20,7 @@ import com.minelittlepony.unicopia.server.world.UTreeGen; import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput; import net.fabricmc.fabric.api.datagen.v1.provider.FabricBlockLootTableProvider; -import net.fabricmc.fabric.api.resource.conditions.v1.DefaultResourceConditions; +import net.fabricmc.fabric.api.resource.conditions.v1.ResourceConditions; import net.minecraft.block.BedBlock; import net.minecraft.block.Block; import net.minecraft.block.Blocks; @@ -46,6 +47,9 @@ import net.minecraft.loot.provider.number.ConstantLootNumberProvider; import net.minecraft.loot.provider.number.LootNumberProvider; import net.minecraft.loot.provider.number.UniformLootNumberProvider; import net.minecraft.predicate.StatePredicate; +import net.minecraft.registry.RegistryKey; +import net.minecraft.registry.RegistryWrapper; +import net.minecraft.registry.entry.RegistryEntry; import net.minecraft.state.property.BooleanProperty; import net.minecraft.state.property.IntProperty; import net.minecraft.state.property.Properties; @@ -54,12 +58,23 @@ import net.minecraft.util.Identifier; import net.minecraft.util.StringIdentifiable; public class UBlockLootTableProvider extends FabricBlockLootTableProvider { + protected static final float[] SAPLING_DROP_CHANCE = new float[]{0.05F, 0.0625F, 0.083333336F, 0.1F}; + private static final float[] LEAVES_STICK_DROP_CHANCE = new float[]{0.02F, 0.022222223F, 0.025F, 0.033333335F, 0.1F}; - private static final ConditionalLootFunction.Builder BASE_PRESERVING_FORTUNE_BONUS = ApplyBonusLootFunction.binomialWithBonusCount(Enchantments.FORTUNE, 0.8714286F, 0); - private static final ConditionalLootFunction.Builder CROPS_FORTUNE_BONUS = ApplyBonusLootFunction.binomialWithBonusCount(Enchantments.FORTUNE, 0.5714286F, 3); + public UBlockLootTableProvider(FabricDataOutput output, CompletableFuture registryLookup) { + super(output, registryLookup); + } - public UBlockLootTableProvider(FabricDataOutput output) { - super(output); + public RegistryEntry entryOf(RegistryKey key) { + return registryLookup.getWrapperOrThrow(key.getRegistryRef()).getOrThrow(key); + } + + private ConditionalLootFunction.Builder createBasePreservingFortuneBonusCondition() { + return ApplyBonusLootFunction.binomialWithBonusCount(entryOf(Enchantments.FORTUNE), 0.8714286F, 0); + } + + private ConditionalLootFunction.Builder createCropsFortuneBonusCondition() { + return ApplyBonusLootFunction.binomialWithBonusCount(entryOf(Enchantments.FORTUNE), 0.5714286F, 3); } @Override @@ -109,8 +124,8 @@ public class UBlockLootTableProvider extends FabricBlockLootTableProvider { }); addDrop(UBlocks.GOLDEN_APPLE, LootTable.builder().pool(LootPool.builder() .rolls(exactly(1)) - .with(applyStateCondition(UBlocks.GOLDEN_APPLE, EnchantedFruitBlock.ENCHANTED, false, applyExplosionDecay(UBlocks.GOLDEN_APPLE, ItemEntry.builder(Items.GOLDEN_APPLE))).apply(BASE_PRESERVING_FORTUNE_BONUS)) - .with(applyStateCondition(UBlocks.GOLDEN_APPLE, EnchantedFruitBlock.ENCHANTED, true, applyExplosionDecay(UBlocks.GOLDEN_APPLE, ItemEntry.builder(Items.ENCHANTED_GOLDEN_APPLE))).apply(BASE_PRESERVING_FORTUNE_BONUS)) + .with(applyStateCondition(UBlocks.GOLDEN_APPLE, EnchantedFruitBlock.ENCHANTED, false, applyExplosionDecay(UBlocks.GOLDEN_APPLE, ItemEntry.builder(Items.GOLDEN_APPLE))).apply(createBasePreservingFortuneBonusCondition())) + .with(applyStateCondition(UBlocks.GOLDEN_APPLE, EnchantedFruitBlock.ENCHANTED, true, applyExplosionDecay(UBlocks.GOLDEN_APPLE, ItemEntry.builder(Items.ENCHANTED_GOLDEN_APPLE))).apply(createBasePreservingFortuneBonusCondition())) )); List.of(UBlocks.GREEN_APPLE_LEAVES, UBlocks.SOUR_APPLE_LEAVES, UBlocks.SWEET_APPLE_LEAVES, UBlocks.GOLDEN_OAK_LEAVES).forEach(block -> addDrop(block, this::fruitLeavesDrops)); addDrop(UBlocks.MANGO_LEAVES, block -> leavesDrops(block, UTreeGen.MANGO_TREE.sapling().get(), 0.025F, 0.027777778F, 0.03125F, 0.041666668F, 0.1F)); // same chance as jungle @@ -126,7 +141,7 @@ public class UBlockLootTableProvider extends FabricBlockLootTableProvider { // jars List.of( UBlocks.JAR, UBlocks.CLOUD_JAR, UBlocks.STORM_JAR, UBlocks.LIGHTNING_JAR, UBlocks.STORM_JAR - ).forEach(jar -> addDrop(jar, UBlockLootTableProvider::dropsWithSilkTouch)); + ).forEach(jar -> addDrop(jar, this::dropsWithSilkTouch)); // doors List.of( @@ -148,7 +163,7 @@ public class UBlockLootTableProvider extends FabricBlockLootTableProvider { .pool(applyStateCondition(UBlocks.SLIME_PUSTULE, SlimePustuleBlock.SHAPE, SlimePustuleBlock.Shape.POD, addSurvivesExplosionCondition(UBlocks.SLIME_PUSTULE, LootPool.builder() .rolls(exactly(1)) - .with(ItemEntry.builder(UBlocks.SLIME_PUSTULE)).conditionally(WITH_SILK_TOUCH_OR_SHEARS)) + .with(ItemEntry.builder(UBlocks.SLIME_PUSTULE)).conditionally(createWithShearsOrSilkTouchCondition())) ))); addDrop(UBlocks.MYSTERIOUS_EGG, LootTable.builder() .pool(addSurvivesExplosionCondition(UBlocks.MYSTERIOUS_EGG, LootPool.builder() @@ -178,13 +193,13 @@ public class UBlockLootTableProvider extends FabricBlockLootTableProvider { addDrop(UBlocks.BANANAS, LootTable.builder() .pool(addSurvivesExplosionCondition(UBlocks.BANANAS, LootPool.builder() .rolls(exactly(1)) - .with(item(UItems.BANANA, between(6, 12F)).apply(CROPS_FORTUNE_BONUS)) + .with(item(UItems.BANANA, between(6, 12F)).apply(createCropsFortuneBonusCondition())) ))); addDrop(UBlocks.PINEAPPLE, LootTable.builder() .pool(addSurvivesExplosionCondition(UBlocks.PINEAPPLE, LootPool.builder() .rolls(exactly(1)) .with(item(UItems.PINEAPPLE, between(6, 12F)) - .apply(BASE_PRESERVING_FORTUNE_BONUS) + .apply(createBasePreservingFortuneBonusCondition()) .conditionally(BlockStatePropertyLootCondition.builder(UBlocks.PINEAPPLE).properties(StatePredicate.Builder.create() .exactMatch(Properties.BLOCK_HALF, BlockHalf.TOP) .exactMatch(Properties.AGE_7, Properties.AGE_7_MAX)))) @@ -192,8 +207,8 @@ public class UBlockLootTableProvider extends FabricBlockLootTableProvider { addDrop(UBlocks.ROCKS, applyExplosionDecay(UBlocks.ROCKS, LootTable.builder() .pool(applyStateCondition(UBlocks.ROCKS, Properties.AGE_7, Properties.AGE_7_MAX, LootPool.builder() .rolls(exactly(1)) - .with(ItemEntry.builder(UItems.WEIRD_ROCK).conditionally(RandomChanceLootCondition.builder(0.25F)).apply(CROPS_FORTUNE_BONUS)) - .with(ItemEntry.builder(UItems.ROCK).apply(CROPS_FORTUNE_BONUS)))) + .with(ItemEntry.builder(UItems.WEIRD_ROCK).conditionally(RandomChanceLootCondition.builder(0.25F)).apply(createCropsFortuneBonusCondition())) + .with(ItemEntry.builder(UItems.ROCK).apply(createCropsFortuneBonusCondition())))) .pool(LootPool.builder() .rolls(exactly(1)) .with(ItemEntry.builder(UItems.PEBBLES))) @@ -201,7 +216,7 @@ public class UBlockLootTableProvider extends FabricBlockLootTableProvider { addDrop(UBlocks.GOLD_ROOT, applyExplosionDecay(UBlocks.GOLD_ROOT, LootTable.builder() .pool(LootPool.builder().with(ItemEntry.builder(Items.GOLDEN_CARROT))) .pool(applyStateCondition(UBlocks.GOLD_ROOT, CarrotsBlock.AGE, 7, LootPool.builder()) - .with(ItemEntry.builder(Items.GOLDEN_CARROT).apply(CROPS_FORTUNE_BONUS))))); + .with(ItemEntry.builder(Items.GOLDEN_CARROT).apply(createCropsFortuneBonusCondition()))))); /* addDrop(UBlocks.PLUNDER_VINE, applyExplosionDecay(UBlocks.PLUNDER_VINE, LootTable.builder() .pool(LootPool.builder().rolls(exactly(1)).conditionally(RandomChanceLootCondition.builder(0.25F)) @@ -219,9 +234,9 @@ public class UBlockLootTableProvider extends FabricBlockLootTableProvider { addDrop(UBlocks.SCALLOP_SHELL, shellDrops(UBlocks.SCALLOP_SHELL, UItems.SCALLOP_SHELL)); addDrop(UBlocks.TURRET_SHELL, shellDrops(UBlocks.TURRET_SHELL, UItems.TURRET_SHELL)); - var farmersDelightGenerator = withConditions(DefaultResourceConditions.allModsLoaded("farmersdelight")); - farmersDelightGenerator.addDrop(Datagen.getOrCreateBaleBlock(Unicopia.id("rice_block")), b -> edibleBlockDrops(b, Datagen.getOrCreateItem(new Identifier("farmersdelight", "rice_panicle")))); - farmersDelightGenerator.addDrop(Datagen.getOrCreateBaleBlock(Unicopia.id("straw_block")), b -> edibleBlockDrops(b, Datagen.getOrCreateItem(new Identifier("farmersdelight", "straw")))); + var farmersDelightGenerator = withConditions(ResourceConditions.allModsLoaded("farmersdelight")); + farmersDelightGenerator.addDrop(Datagen.getOrCreateBaleBlock(Unicopia.id("rice_block")), b -> edibleBlockDrops(b, Datagen.getOrCreateItem(Identifier.of("farmersdelight", "rice_panicle")))); + farmersDelightGenerator.addDrop(Datagen.getOrCreateBaleBlock(Unicopia.id("straw_block")), b -> edibleBlockDrops(b, Datagen.getOrCreateItem(Identifier.of("farmersdelight", "straw")))); } private void addTallCropDrops(SegmentedCropBlock baseCrop, ItemConvertible crop) { @@ -231,7 +246,7 @@ public class UBlockLootTableProvider extends FabricBlockLootTableProvider { .with(ItemEntry.builder(baseCrop.getSeedsItem())))) .pool(applyStateCondition(baseCrop, baseCrop.getAgeProperty(), baseCrop.getMaxAge(), LootPool.builder() .rolls(exactly(1)) - .with(ItemEntry.builder(baseCrop.getSeedsItem()).apply(CROPS_FORTUNE_BONUS))))); + .with(ItemEntry.builder(baseCrop.getSeedsItem()).apply(createCropsFortuneBonusCondition()))))); SegmentedCropBlock stage = baseCrop; while ((stage = stage.getNext()) != null) { @@ -254,20 +269,20 @@ public class UBlockLootTableProvider extends FabricBlockLootTableProvider { return LootTable.builder() .pool(LootPool.builder() .rolls(exactly(1)) - .with(ItemEntry.builder(leaves).conditionally(WITH_SILK_TOUCH_OR_SHEARS))) + .with(ItemEntry.builder(leaves).conditionally(createWithShearsOrSilkTouchCondition()))) .pool(applyExplosionDecay(leaves, LootPool.builder() .rolls(exactly(1)) - .conditionally(WITHOUT_SILK_TOUCH_NOR_SHEARS) - .with(item(Items.STICK, between(1, 2)).conditionally(TableBonusLootCondition.builder(Enchantments.FORTUNE, LEAVES_STICK_DROP_CHANCE))))); + .conditionally(createWithoutShearsOrSilkTouchCondition()) + .with(item(Items.STICK, between(1, 2)).conditionally(TableBonusLootCondition.builder(entryOf(Enchantments.FORTUNE), LEAVES_STICK_DROP_CHANCE))))); } private LootTable.Builder hullDrops(Block hull, ItemConvertible inner, ItemConvertible outer) { return LootTable.builder() .pool(addSurvivesExplosionCondition(hull, LootPool.builder() .rolls(exactly(1)) - .with(item(hull, exactly(2)).conditionally(WITHOUT_SILK_TOUCH)) - .with(item(inner, exactly(2)).conditionally(WITHOUT_SILK_TOUCH)) - .with(item(outer, exactly(2)).conditionally(WITH_SILK_TOUCH)))); + .with(item(hull, exactly(2)).conditionally(createWithoutSilkTouchCondition())) + .with(item(inner, exactly(2)).conditionally(createWithoutSilkTouchCondition())) + .with(item(outer, exactly(2)).conditionally(createSilkTouchCondition())))); } private LootTable.Builder edibleBlockDrops(Block block, ItemConvertible drop) { @@ -284,7 +299,7 @@ public class UBlockLootTableProvider extends FabricBlockLootTableProvider { private LootTable.Builder pieDrops(Block block, Item drop, Item stomped) { return LootTable.builder() .pool(applyExplosionDecay(block, LootPool.builder() - .rolls(exactly(1)).conditionally(WITH_SILK_TOUCH) + .rolls(exactly(1)).conditionally(createSilkTouchCondition()) .with(applyStateCondition(block, PieBlock.STOMPED, false, ItemEntry.builder(drop))) .with(applyStateCondition(block, PieBlock.STOMPED, true, ItemEntry.builder(stomped))))); } @@ -295,14 +310,14 @@ public class UBlockLootTableProvider extends FabricBlockLootTableProvider { .rolls(exactly(1)) .with(ItemEntry.builder(shell)) .apply(ShellsBlock.COUNT.getValues(), count -> applyStateCondition(block, ShellsBlock.COUNT, count, SetCountLootFunction.builder(exactly(count)))) - .apply(BASE_PRESERVING_FORTUNE_BONUS))); + .apply(createBasePreservingFortuneBonusCondition()))); } public LootTable.Builder fortuneBonusDrops(ItemConvertible drop) { return LootTable.builder().pool(addSurvivesExplosionCondition(drop, LootPool.builder() .rolls(exactly(1)) - .with(ItemEntry.builder(drop).apply(BASE_PRESERVING_FORTUNE_BONUS)))); + .with(ItemEntry.builder(drop).apply(createBasePreservingFortuneBonusCondition())))); } public static ConstantLootNumberProvider exactly(float n) { diff --git a/src/main/java/com/minelittlepony/unicopia/datagen/providers/loot/UChestAdditionsLootTableProvider.java b/src/main/java/com/minelittlepony/unicopia/datagen/providers/loot/UChestAdditionsLootTableProvider.java index 2c6b18bd..05108f44 100644 --- a/src/main/java/com/minelittlepony/unicopia/datagen/providers/loot/UChestAdditionsLootTableProvider.java +++ b/src/main/java/com/minelittlepony/unicopia/datagen/providers/loot/UChestAdditionsLootTableProvider.java @@ -1,5 +1,6 @@ package com.minelittlepony.unicopia.datagen.providers.loot; +import java.util.concurrent.CompletableFuture; import java.util.function.BiConsumer; import com.minelittlepony.unicopia.UConventionalTags; @@ -18,12 +19,15 @@ import net.minecraft.loot.entry.TagEntry; import net.minecraft.loot.function.SetCountLootFunction; import net.minecraft.loot.provider.number.ConstantLootNumberProvider; import net.minecraft.loot.provider.number.UniformLootNumberProvider; +import net.minecraft.registry.RegistryKey; +import net.minecraft.registry.RegistryKeys; +import net.minecraft.registry.RegistryWrapper; import net.minecraft.util.Identifier; public class UChestAdditionsLootTableProvider extends SimpleFabricLootTableProvider { - public UChestAdditionsLootTableProvider(FabricDataOutput dataOutput) { - super(dataOutput, LootContextTypes.CHEST); + public UChestAdditionsLootTableProvider(FabricDataOutput dataOutput, CompletableFuture registryLookup) { + super(dataOutput, registryLookup, LootContextTypes.CHEST); } @Override @@ -32,11 +36,11 @@ public class UChestAdditionsLootTableProvider extends SimpleFabricLootTableProvi } @Override - public void accept(BiConsumer exporter) { - acceptAdditions((id, builder) -> exporter.accept(new Identifier("unicopiamc", id.getPath()), builder)); + public void accept(BiConsumer, LootTable.Builder> exporter) { + acceptAdditions((id, builder) -> exporter.accept(RegistryKey.of(RegistryKeys.LOOT_TABLE, Identifier.of("unicopiamc", id.getValue().getPath())), builder)); } - public void acceptAdditions(BiConsumer exporter) { + public void acceptAdditions(BiConsumer, Builder> exporter) { exporter.accept(LootTables.ABANDONED_MINESHAFT_CHEST, LootTable.builder().pool(LootPool.builder() .rolls(UniformLootNumberProvider.create(2, 4)) .with(ItemEntry.builder(UItems.GRYPHON_FEATHER).weight(2).apply(SetCountLootFunction.builder(UniformLootNumberProvider.create(1, 4)))) diff --git a/src/main/java/com/minelittlepony/unicopia/datagen/providers/loot/UChestLootTableProvider.java b/src/main/java/com/minelittlepony/unicopia/datagen/providers/loot/UChestLootTableProvider.java index 0ea207e9..01baed4f 100644 --- a/src/main/java/com/minelittlepony/unicopia/datagen/providers/loot/UChestLootTableProvider.java +++ b/src/main/java/com/minelittlepony/unicopia/datagen/providers/loot/UChestLootTableProvider.java @@ -18,6 +18,8 @@ import net.minecraft.loot.function.SetPotionLootFunction; import net.minecraft.loot.provider.number.ConstantLootNumberProvider; import net.minecraft.loot.provider.number.UniformLootNumberProvider; import net.minecraft.potion.Potion; +import net.minecraft.registry.RegistryKey; +import net.minecraft.registry.RegistryKeys; import net.minecraft.util.Identifier; public class UChestLootTableProvider extends SimpleFabricLootTableProvider { @@ -26,8 +28,8 @@ public class UChestLootTableProvider extends SimpleFabricLootTableProvider { } @Override - public void accept(BiConsumer exporter) { - exporter.accept(Unicopia.id("chests/changeling_hive_trap"), LootTable.builder() + public void accept(BiConsumer, Builder> exporter) { + exporter.accept(RegistryKey.of(RegistryKeys.LOOT_TABLE, Unicopia.id("chests/changeling_hive_trap")), LootTable.builder() .pool(LootPool.builder() .rolls(ConstantLootNumberProvider.create(6)) diff --git a/src/main/java/com/minelittlepony/unicopia/entity/effect/CorruptInfluenceStatusEffect.java b/src/main/java/com/minelittlepony/unicopia/entity/effect/CorruptInfluenceStatusEffect.java index a30d7656..d7624a54 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/effect/CorruptInfluenceStatusEffect.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/effect/CorruptInfluenceStatusEffect.java @@ -24,8 +24,8 @@ import net.minecraft.world.WorldEvents; public class CorruptInfluenceStatusEffect extends StatusEffect { CorruptInfluenceStatusEffect(int color) { super(StatusEffectCategory.NEUTRAL, color); - addAttributeModifier(EntityAttributes.GENERIC_ATTACK_DAMAGE, "6D706448-6A60-4F59-BE8A-C23A6DD2C7A9", 15, EntityAttributeModifier.Operation.ADDITION); - addAttributeModifier(EntityAttributes.GENERIC_ATTACK_SPEED, "6D706448-6A60-4F59-BE8A-C23A6DD2C7A9", 10, EntityAttributeModifier.Operation.ADDITION); + addAttributeModifier(EntityAttributes.GENERIC_ATTACK_DAMAGE, "6D706448-6A60-4F59-BE8A-C23A6DD2C7A9", 15, EntityAttributeModifier.Operation.ADD_VALUE); + addAttributeModifier(EntityAttributes.GENERIC_ATTACK_SPEED, "6D706448-6A60-4F59-BE8A-C23A6DD2C7A9", 10, EntityAttributeModifier.Operation.ADD_VALUE); } @Override @@ -81,11 +81,11 @@ public class CorruptInfluenceStatusEffect extends StatusEffect { float maxHealthDifference = mob.getMaxHealth() - clone.getMaxHealth(); clone.addStatusEffect(new StatusEffectInstance(StatusEffects.STRENGTH, 900000, 2)); clone.getAttributeInstance(EntityAttributes.GENERIC_MAX_HEALTH) - .addPersistentModifier(new EntityAttributeModifier(UUID.randomUUID(), "Corruption Strength Modifier", maxHealthDifference + 1, EntityAttributeModifier.Operation.ADDITION)); + .addPersistentModifier(new EntityAttributeModifier(UUID.randomUUID(), "Corruption Strength Modifier", maxHealthDifference + 1, EntityAttributeModifier.Operation.ADD_VALUE)); } if (clone.getAttributes().hasAttribute(EntityAttributes.GENERIC_ATTACK_DAMAGE)) { clone.getAttributeInstance(EntityAttributes.GENERIC_ATTACK_DAMAGE) - .addPersistentModifier(new EntityAttributeModifier(UUID.randomUUID(), "Corruption Damage Modifier", mob.getAttributeValue(EntityAttributes.GENERIC_ATTACK_DAMAGE) + 1, EntityAttributeModifier.Operation.ADDITION)); + .addPersistentModifier(new EntityAttributeModifier(UUID.randomUUID(), "Corruption Damage Modifier", mob.getAttributeValue(EntityAttributes.GENERIC_ATTACK_DAMAGE) + 1, EntityAttributeModifier.Operation.ADD_VALUE)); } } diff --git a/src/main/java/com/minelittlepony/unicopia/entity/effect/MetamorphosisStatusEffect.java b/src/main/java/com/minelittlepony/unicopia/entity/effect/MetamorphosisStatusEffect.java index 56accf6f..9b5123fa 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/effect/MetamorphosisStatusEffect.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/effect/MetamorphosisStatusEffect.java @@ -11,34 +11,36 @@ import net.minecraft.entity.effect.StatusEffect; import net.minecraft.entity.effect.StatusEffectCategory; import net.minecraft.registry.Registries; import net.minecraft.registry.Registry; +import net.minecraft.registry.entry.RegistryEntry; import net.minecraft.util.Identifier; public class MetamorphosisStatusEffect extends StatusEffect { public static final int MAX_DURATION = 20 * 60; - private static final Map REGISTRY = new HashMap<>(); + private static final Map> REGISTRY = new HashMap<>(); - public static final StatusEffect EARTH = register(0x886F0F, Race.EARTH); - public static final StatusEffect UNICORN = register(0x88FFFF, Race.UNICORN); - public static final StatusEffect PEGASUS = register(0x00C0ff, Race.PEGASUS); - public static final StatusEffect BAT = register(0x152F13, Race.BAT); - public static final StatusEffect CHANGELING = register(0xFFFF00, Race.CHANGELING); - public static final StatusEffect KIRIN = register(0xFF8800, Race.KIRIN); - public static final StatusEffect HIPPOGRIFF = register(0xE04F77, Race.HIPPOGRIFF); + public static final RegistryEntry EARTH = register(0x886F0F, Race.EARTH); + public static final RegistryEntry UNICORN = register(0x88FFFF, Race.UNICORN); + public static final RegistryEntry PEGASUS = register(0x00C0ff, Race.PEGASUS); + public static final RegistryEntry BAT = register(0x152F13, Race.BAT); + public static final RegistryEntry CHANGELING = register(0xFFFF00, Race.CHANGELING); + public static final RegistryEntry KIRIN = register(0xFF8800, Race.KIRIN); + public static final RegistryEntry HIPPOGRIFF = register(0xE04F77, Race.HIPPOGRIFF); @Nullable - public static StatusEffect forRace(Race race) { + public static RegistryEntry forRace(Race race) { return REGISTRY.get(race); } - public static StatusEffect register(int color, Race race) { + public static RegistryEntry register(int color, Race race) { Identifier id = Race.REGISTRY.getId(race); StatusEffect effect = new MetamorphosisStatusEffect(color, race); - REGISTRY.put(race, effect); - return Registry.register(Registries.STATUS_EFFECT, + var reference = Registry.registerReference(Registries.STATUS_EFFECT, id.withPath(p -> "morph_race_" + p), effect ); + REGISTRY.put(race, reference); + return reference; } public static Race getEffectiveRace(LivingEntity entity, Race fallback) { diff --git a/src/main/java/com/minelittlepony/unicopia/entity/effect/RaceChangeStatusEffect.java b/src/main/java/com/minelittlepony/unicopia/entity/effect/RaceChangeStatusEffect.java index 210395b9..07527918 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/effect/RaceChangeStatusEffect.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/effect/RaceChangeStatusEffect.java @@ -25,34 +25,39 @@ import net.minecraft.text.Text; import net.minecraft.util.Identifier; import net.minecraft.world.World.ExplosionSourceType; import net.minecraft.registry.Registry; +import net.minecraft.registry.entry.RegistryEntry; import net.minecraft.registry.Registries; public class RaceChangeStatusEffect extends StatusEffect { public static final int STAGE_DURATION = 200; public static final int MAX_DURATION = Stage.VALUES.length * STAGE_DURATION + 1; - private static final Map REGISTRY = new HashMap<>(); + private static final Map> REGISTRY = new HashMap<>(); @Nullable - public static StatusEffect forRace(Race race) { + public static RegistryEntry forRace(Race race) { return REGISTRY.get(race); } - public static final StatusEffect EARTH = register(0x886F0F, Race.EARTH); - public static final StatusEffect UNICORN = register(0x88FFFF, Race.UNICORN); - public static final StatusEffect PEGASUS = register(0x00C0ff, Race.PEGASUS); - public static final StatusEffect BAT = register(0x152F13, Race.BAT); - public static final StatusEffect CHANGELING = register(0xFFFF00, Race.CHANGELING); - public static final StatusEffect KIRIN = register(0xFF8800, Race.KIRIN); - public static final StatusEffect HIPPOGRIFF = register(0xE04F77, Race.HIPPOGRIFF); + public static final RegistryEntry EARTH = register(0x886F0F, Race.EARTH); + public static final RegistryEntry UNICORN = register(0x88FFFF, Race.UNICORN); + public static final RegistryEntry PEGASUS = register(0x00C0ff, Race.PEGASUS); + public static final RegistryEntry BAT = register(0x152F13, Race.BAT); + public static final RegistryEntry CHANGELING = register(0xFFFF00, Race.CHANGELING); + public static final RegistryEntry KIRIN = register(0xFF8800, Race.KIRIN); + public static final RegistryEntry HIPPOGRIFF = register(0xE04F77, Race.HIPPOGRIFF); private final Race race; - public static StatusEffect register(int color, Race race) { + public static RegistryEntry register(int color, Race race) { Identifier id = race.getId(); - StatusEffect effect = new RaceChangeStatusEffect(color, race); - REGISTRY.put(race, effect); - return Registry.register(Registries.STATUS_EFFECT, id.withPath(p -> "change_race_" + id.getPath()), effect); + var reference = Registry.registerReference( + Registries.STATUS_EFFECT, + id.withPath(p -> "change_race_" + id.getPath()), + new RaceChangeStatusEffect(color, race) + ); + REGISTRY.put(race, reference); + return reference; } private RaceChangeStatusEffect(int color, Race race) { @@ -64,28 +69,23 @@ public class RaceChangeStatusEffect extends StatusEffect { return race; } - private void removeEffect(LivingEntity entity) { - entity.removeStatusEffect(this); - resetTicks(entity); - } - private void resetTicks(LivingEntity entity) { Pony.of(entity).ifPresent(pony -> pony.setTicksmetamorphising(0)); } @Override - public void applyUpdateEffect(LivingEntity entity, int amplifier) { - StatusEffectInstance state = entity.getStatusEffect(this); + public boolean applyUpdateEffect(LivingEntity entity, int amplifier) { + StatusEffectInstance state = entity.getStatusEffect(forRace(race)); if (state == null || entity.isDead()) { resetTicks(entity); - return; + return false; } Equine eq = Equine.of(entity).orElse(null); if (eq == null) { - return; + return false; } int metaTicks = 0; @@ -100,7 +100,7 @@ public class RaceChangeStatusEffect extends StatusEffect { Stage stage = Stage.forDuration(ticks / STAGE_DURATION); if (stage == Stage.INITIAL) { - return; + return true; } int progression = ticks % (stage.ordinal() * STAGE_DURATION); @@ -109,8 +109,7 @@ public class RaceChangeStatusEffect extends StatusEffect { if (progression == 0 && entity instanceof PlayerEntity player && stage == Stage.CRAWLING) { player.sendMessage(Stage.INITIAL.getMessage(race), true); } - removeEffect(entity); - return; + return false; } if (progression == 0 && stage != Stage.DEATH && entity instanceof PlayerEntity player) { @@ -133,8 +132,6 @@ public class RaceChangeStatusEffect extends StatusEffect { } if (stage == Stage.DEATH) { - removeEffect(entity); - if (eq instanceof Caster) { ((Caster)eq).getSpellSlot().clear(); } @@ -172,7 +169,11 @@ public class RaceChangeStatusEffect extends StatusEffect { eq.setSpecies(race); entity.getWorld().createExplosion(entity, null, ExplosionUtil.NON_DESTRUCTIVE, entity.getPos(), 5, true, ExplosionSourceType.MOB); } + + return false; } + + return true; } @Override diff --git a/src/main/java/com/minelittlepony/unicopia/entity/effect/UPotions.java b/src/main/java/com/minelittlepony/unicopia/entity/effect/UPotions.java index 3e8aefc5..504a7ce7 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/effect/UPotions.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/effect/UPotions.java @@ -2,20 +2,19 @@ package com.minelittlepony.unicopia.entity.effect; import java.util.Objects; -import org.spongepowered.include.com.google.common.base.Preconditions; - import com.minelittlepony.unicopia.Race; import com.minelittlepony.unicopia.Unicopia; import com.minelittlepony.unicopia.item.UItems; +import net.fabricmc.fabric.api.registry.FabricBrewingRecipeRegistryBuilder; import net.minecraft.entity.effect.StatusEffect; import net.minecraft.entity.effect.StatusEffectInstance; import net.minecraft.item.Item; import net.minecraft.item.Items; import net.minecraft.potion.Potion; import net.minecraft.potion.Potions; -import net.minecraft.recipe.BrewingRecipeRegistry; import net.minecraft.registry.Registry; +import net.minecraft.registry.entry.RegistryEntry; import net.minecraft.util.Identifier; import net.minecraft.registry.Registries; @@ -28,22 +27,25 @@ public interface UPotions { MorphingPotion MORPH_KIRIN = new MorphingPotion(Race.KIRIN).registerBaseRecipes(Potions.FIRE_RESISTANCE, Items.MAGMA_CREAM); MorphingPotion MORPH_HIPPOGRIFF = new MorphingPotion(Race.HIPPOGRIFF).registerBaseRecipes(Potions.WATER_BREATHING, UItems.CLAM_SHELL, UItems.TURRET_SHELL, UItems.SCALLOP_SHELL); - static Potion register(String name, Potion potion) { + static RegistryEntry register(String name, Potion potion) { return register(Unicopia.id(name), potion); } - static Potion register(Identifier id, Potion potion) { - return Registry.register(Registries.POTION, id, potion); + static RegistryEntry register(Identifier id, Potion potion) { + return Registry.registerReference(Registries.POTION, id, potion); } - static void addRecipe(Potion result, Potion basePotion, Item...items) { - Preconditions.checkArgument(BrewingRecipeRegistry.isBrewable(basePotion), "Base potion is not craftable. " + Registries.POTION.getId(basePotion) + " required for crafting " + Registries.POTION.getId(result)); - for (Item item : items) { - BrewingRecipeRegistry.registerPotionRecipe(basePotion, item, result); - } + static void addRecipe(RegistryEntry result, RegistryEntry basePotion, Item...items) { + FabricBrewingRecipeRegistryBuilder.BUILD.register(registry -> { + //Preconditions.checkArgument(BrewingRecipeRegistry.isBrewable(basePotion), "Base potion is not craftable. " + basePotion.getIdAsString() + " required for crafting " + result.getIdAsString()); + for (Item item : items) { + registry.registerPotionRecipe(basePotion, item, result); + } + }); + } - record MorphingPotion(Identifier id, Potion shortEffect, Potion longEffect, Potion permanentEffect) { + record MorphingPotion(Identifier id, RegistryEntry shortEffect, RegistryEntry longEffect, RegistryEntry permanentEffect) { public MorphingPotion(Race race) { this(race.getId(), Objects.requireNonNull(MetamorphosisStatusEffect.forRace(race), "No metamorphosis status effect registered for " + race.getId()), @@ -51,7 +53,7 @@ public interface UPotions { ); } - public MorphingPotion(Identifier id, StatusEffect morphEffect, StatusEffect permanentEffect) { + public MorphingPotion(Identifier id, RegistryEntry morphEffect, RegistryEntry permanentEffect) { this(id, register(id.withPath(p -> "short_morph_" + p), new Potion(id.getNamespace() + ".short_morph_" + id.getPath(), new StatusEffectInstance(morphEffect, MetamorphosisStatusEffect.MAX_DURATION))), register(id.withPath(p -> "long_morph_" + p), new Potion(id.getNamespace() + ".long_morph_" + id.getPath(), new StatusEffectInstance(morphEffect, MetamorphosisStatusEffect.MAX_DURATION * 10))), @@ -59,7 +61,7 @@ public interface UPotions { ); } - public MorphingPotion registerBaseRecipes(Potion basePotion, Item...items) { + public MorphingPotion registerBaseRecipes(RegistryEntry basePotion, Item...items) { addRecipe(shortEffect, basePotion, items); addRecipe(longEffect, shortEffect, Items.REDSTONE); addRecipe(permanentEffect, longEffect, UItems.CURING_JOKE); diff --git a/src/main/java/com/minelittlepony/unicopia/entity/mob/IgnominiousBulbEntity.java b/src/main/java/com/minelittlepony/unicopia/entity/mob/IgnominiousBulbEntity.java index 3da9137c..dbdb019d 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/mob/IgnominiousBulbEntity.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/mob/IgnominiousBulbEntity.java @@ -352,7 +352,7 @@ public class IgnominiousBulbEntity extends MobEntity { var tentacles = new HashMap>(); nbt.getList("tentacles", NbtElement.COMPOUND_TYPE).forEach(tag -> { var compound = (NbtCompound)tag; - tentacles.put(NbtSerialisable.BLOCK_POS.read(compound.getCompound("pos")), new EntityReference<>(compound.getCompound("target"))); + tentacles.put(NbtSerialisable.BLOCK_POS.read(compound.getCompound("pos"), getWorld().getRegistryManager()), new EntityReference<>(compound.getCompound("target"), getWorld().getRegistryManager())); }); this.tentacles = tentacles; } diff --git a/src/main/java/com/minelittlepony/unicopia/entity/mob/SpecterEntity.java b/src/main/java/com/minelittlepony/unicopia/entity/mob/SpecterEntity.java index 7d99db13..41dc5a4b 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/mob/SpecterEntity.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/mob/SpecterEntity.java @@ -69,7 +69,7 @@ public class SpecterEntity extends HostileEntity { super.tick(); if (getTarget() != null) { - ParticleUtils.spawnParticles(ParticleTypes.AMBIENT_ENTITY_EFFECT, this, 6); + ParticleUtils.spawnParticles(ParticleTypes.EFFECT, this, 6); if (getWorld().getGameRules().getBoolean(GameRules.DO_MOB_GRIEFING)) { if (getWorld().getBlockState(getBlockPos()).isIn(BlockTags.REPLACEABLE_BY_TREES)) { diff --git a/src/main/java/com/minelittlepony/unicopia/entity/mob/TentacleEntity.java b/src/main/java/com/minelittlepony/unicopia/entity/mob/TentacleEntity.java index 6e1d64bc..e22cd79a 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/mob/TentacleEntity.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/mob/TentacleEntity.java @@ -321,7 +321,7 @@ public class TentacleEntity extends AbstractDecorationEntity { @Override protected void updateAttachmentPosition() { visibilityBox = null; - Vec3d pos = attachmentPos.toCenterPos(); + Vec3d pos = attachedBlockPos.toCenterPos(); setPos(pos.x, pos.y, pos.z); setBoundingBox(Box.of(pos, 1, 1, 1).stretch(0, 2, 0)); } diff --git a/src/main/java/com/minelittlepony/unicopia/item/UItems.java b/src/main/java/com/minelittlepony/unicopia/item/UItems.java index 3f157d55..267a4e08 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/UItems.java +++ b/src/main/java/com/minelittlepony/unicopia/item/UItems.java @@ -107,10 +107,10 @@ public interface UItems { Item PEBBLES = register("pebbles", new AliasedBlockItem(UBlocks.ROCKS, new Item.Settings()), ItemGroups.NATURAL); Item ROCK = register("rock", new HeavyProjectileItem(new Item.Settings(), 3), ItemGroups.NATURAL); Item WEIRD_ROCK = register("weird_rock", new BluntWeaponItem(new Item.Settings(), ImmutableMultimap.of( - EntityAttributes.GENERIC_LUCK, new EntityAttributeModifier(BluntWeaponItem.LUCK_MODIFIER_ID, "Weapon modifier", 9, EntityAttributeModifier.Operation.ADDITION) + EntityAttributes.GENERIC_LUCK, new EntityAttributeModifier(BluntWeaponItem.LUCK_MODIFIER_ID, "Weapon modifier", 9, EntityAttributeModifier.Operation.ADD_VALUE) )), ItemGroups.NATURAL); Item TOM = register("tom", new BluntWeaponItem(new Item.Settings(), ImmutableMultimap.of( - EntityAttributes.GENERIC_KNOCKBACK_RESISTANCE, new EntityAttributeModifier(BluntWeaponItem.KNOCKBACK_MODIFIER_ID, "Weapon modifier", 0.9, EntityAttributeModifier.Operation.ADDITION) + EntityAttributes.GENERIC_KNOCKBACK_RESISTANCE, new EntityAttributeModifier(BluntWeaponItem.KNOCKBACK_MODIFIER_ID, "Weapon modifier", 0.9, EntityAttributeModifier.Operation.ADD_VALUE) )), ItemGroups.NATURAL); Item ROCK_STEW = register("rock_stew", new StewItem(new Item.Settings().food(FoodComponents.MUSHROOM_STEW).maxCount(1).recipeRemainder(Items.BOWL)), ItemGroups.FOOD_AND_DRINK); Item ROCK_CANDY = register("rock_candy", new Item(new Item.Settings().food(UFoodComponents.CANDY).maxCount(16)), ItemGroups.FOOD_AND_DRINK); diff --git a/src/main/java/com/minelittlepony/unicopia/item/enchantment/AttributedEnchantment.java b/src/main/java/com/minelittlepony/unicopia/item/enchantment/AttributedEnchantment.java index 4738165d..c7c3fe87 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/enchantment/AttributedEnchantment.java +++ b/src/main/java/com/minelittlepony/unicopia/item/enchantment/AttributedEnchantment.java @@ -12,6 +12,8 @@ import net.minecraft.entity.attribute.EntityAttribute; import net.minecraft.entity.attribute.EntityAttributeInstance; import net.minecraft.entity.attribute.EntityAttributeModifier; +// TODO: Replaced with EnchantmentEffectComponentTypes.ATTRIBUTES +@Deprecated public class AttributedEnchantment extends SimpleEnchantment { private final Map modifiers = new HashMap<>(); diff --git a/src/main/java/com/minelittlepony/unicopia/item/enchantment/CollaboratorEnchantment.java b/src/main/java/com/minelittlepony/unicopia/item/enchantment/CollaboratorEnchantment.java index c9bc4fd1..2f0f823c 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/enchantment/CollaboratorEnchantment.java +++ b/src/main/java/com/minelittlepony/unicopia/item/enchantment/CollaboratorEnchantment.java @@ -23,7 +23,7 @@ public class CollaboratorEnchantment extends AttributedEnchantment { } private EntityAttributeModifier getModifier(Living user, int level) { - return new EntityAttributeModifier(TEAM_STRENGTH_UUID, "Team Strength", user.getEnchants().computeIfAbsent(this, Data::new).level / 2, Operation.ADDITION); + return new EntityAttributeModifier(TEAM_STRENGTH_UUID, "Team Strength", user.getEnchants().computeIfAbsent(this, Data::new).level / 2, Operation.ADD_VALUE); } private int getTeamCollectiveLevel(Living user, int radius) { diff --git a/src/main/java/com/minelittlepony/unicopia/item/enchantment/SimpleEnchantment.java b/src/main/java/com/minelittlepony/unicopia/item/enchantment/SimpleEnchantment.java index 1a233623..d3ed46ff 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/enchantment/SimpleEnchantment.java +++ b/src/main/java/com/minelittlepony/unicopia/item/enchantment/SimpleEnchantment.java @@ -3,10 +3,10 @@ package com.minelittlepony.unicopia.item.enchantment; import com.minelittlepony.unicopia.entity.Living; import net.minecraft.enchantment.Enchantment; -import net.minecraft.enchantment.EnchantmentTarget; import net.minecraft.entity.EquipmentSlot; import net.minecraft.item.ItemStack; +@Deprecated public class SimpleEnchantment extends Enchantment { private final Options options;