diff --git a/Fabric/src/main/java/vazkii/botania/api/BotaniaFabricCapabilities.java b/Fabric/src/main/java/vazkii/botania/api/BotaniaFabricCapabilities.java index 53cca912ec..8ee56377ab 100644 --- a/Fabric/src/main/java/vazkii/botania/api/BotaniaFabricCapabilities.java +++ b/Fabric/src/main/java/vazkii/botania/api/BotaniaFabricCapabilities.java @@ -3,7 +3,6 @@ import net.fabricmc.fabric.api.lookup.v1.block.BlockApiLookup; import net.fabricmc.fabric.api.lookup.v1.item.ItemApiLookup; import net.minecraft.core.Direction; -import net.minecraft.resources.ResourceLocation; import net.minecraft.util.Unit; import vazkii.botania.api.block.ExoflameHeatable; @@ -21,23 +20,33 @@ import vazkii.botania.api.mana.spark.SparkAttachable; public final class BotaniaFabricCapabilities { - public static final ItemApiLookup AVATAR_WIELDABLE = ItemApiLookup.get(new ResourceLocation(BotaniaAPI.MODID, "avatar_wieldable"), AvatarWieldable.class, Unit.class); - public static final ItemApiLookup BLOCK_PROVIDER = ItemApiLookup.get(new ResourceLocation(BotaniaAPI.MODID, "block_provider"), BlockProvider.class, Unit.class); - public static final ItemApiLookup COORD_BOUND_ITEM = ItemApiLookup.get(new ResourceLocation(BotaniaAPI.MODID, "coord_bound_item"), - CoordBoundItem.class, Unit.class); - public static final ItemApiLookup MANA_ITEM = ItemApiLookup.get(new ResourceLocation(BotaniaAPI.MODID, "mana_item"), - ManaItem.class, Unit.class); - public static final ItemApiLookup RELIC = ItemApiLookup.get(new ResourceLocation(BotaniaAPI.MODID, "relic"), - Relic.class, Unit.class); + public static final ItemApiLookup AVATAR_WIELDABLE = + ItemApiLookup.get(AvatarWieldable.ID, AvatarWieldable.class, Unit.class); + public static final ItemApiLookup BLOCK_PROVIDER = + ItemApiLookup.get(BlockProvider.ID, BlockProvider.class, Unit.class); + public static final ItemApiLookup COORD_BOUND_ITEM = + ItemApiLookup.get(CoordBoundItem.ID, CoordBoundItem.class, Unit.class); + public static final ItemApiLookup MANA_ITEM = + ItemApiLookup.get(ManaItem.ID, ManaItem.class, Unit.class); + public static final ItemApiLookup RELIC = + ItemApiLookup.get(Relic.ID, Relic.class, Unit.class); - public static final BlockApiLookup EXOFLAME_HEATABLE = BlockApiLookup.get(new ResourceLocation(BotaniaAPI.MODID, "exoflame_heatable"), ExoflameHeatable.class, Unit.class); - public static final BlockApiLookup HORN_HARVEST = BlockApiLookup.get(new ResourceLocation(BotaniaAPI.MODID, "horn_harvestable"), HornHarvestable.class, Unit.class); - public static final BlockApiLookup HOURGLASS_TRIGGER = BlockApiLookup.get(new ResourceLocation(BotaniaAPI.MODID, "hourglass_trigger"), HourglassTrigger.class, Unit.class); - public static final BlockApiLookup MANA_GHOST = BlockApiLookup.get(new ResourceLocation(BotaniaAPI.MODID, "mana_ghost"), ManaCollisionGhost.class, Unit.class); - public static final BlockApiLookup MANA_RECEIVER = BlockApiLookup.get(new ResourceLocation(BotaniaAPI.MODID, "mana_receiver"), ManaReceiver.class, Direction.class); - public static final BlockApiLookup SPARK_ATTACHABLE = BlockApiLookup.get(new ResourceLocation(BotaniaAPI.MODID, "spark_attachable"), SparkAttachable.class, Direction.class); - public static final BlockApiLookup MANA_TRIGGER = BlockApiLookup.get(new ResourceLocation(BotaniaAPI.MODID, "mana_trigger"), ManaTrigger.class, Unit.class); - public static final BlockApiLookup WANDABLE = BlockApiLookup.get(new ResourceLocation(BotaniaAPI.MODID, "wandable"), Wandable.class, Unit.class); + public static final BlockApiLookup EXOFLAME_HEATABLE = + BlockApiLookup.get(ExoflameHeatable.ID, ExoflameHeatable.class, Unit.class); + public static final BlockApiLookup HORN_HARVEST = + BlockApiLookup.get(HornHarvestable.ID, HornHarvestable.class, Unit.class); + public static final BlockApiLookup HOURGLASS_TRIGGER = + BlockApiLookup.get(HourglassTrigger.ID, HourglassTrigger.class, Unit.class); + public static final BlockApiLookup MANA_GHOST = + BlockApiLookup.get(ManaCollisionGhost.ID, ManaCollisionGhost.class, Unit.class); + public static final BlockApiLookup MANA_RECEIVER = + BlockApiLookup.get(ManaReceiver.ID, ManaReceiver.class, Direction.class); + public static final BlockApiLookup SPARK_ATTACHABLE = + BlockApiLookup.get(SparkAttachable.ID, SparkAttachable.class, Direction.class); + public static final BlockApiLookup MANA_TRIGGER = + BlockApiLookup.get(ManaTrigger.ID, ManaTrigger.class, Unit.class); + public static final BlockApiLookup WANDABLE = + BlockApiLookup.get(Wandable.ID, Wandable.class, Unit.class); private BotaniaFabricCapabilities() {} } diff --git a/Fabric/src/main/java/vazkii/botania/fabric/internal_caps/CCAInternalEntityComponents.java b/Fabric/src/main/java/vazkii/botania/fabric/internal_caps/CCAInternalEntityComponents.java index a13dcaf190..9c3a001fd5 100644 --- a/Fabric/src/main/java/vazkii/botania/fabric/internal_caps/CCAInternalEntityComponents.java +++ b/Fabric/src/main/java/vazkii/botania/fabric/internal_caps/CCAInternalEntityComponents.java @@ -23,16 +23,14 @@ import vazkii.botania.common.internal_caps.*; -import static vazkii.botania.common.lib.ResourceLocationHelper.prefix; - public class CCAInternalEntityComponents implements EntityComponentInitializer { - public static final ComponentKey TNT_ETHICAL = ComponentRegistryV3.INSTANCE.getOrCreate(prefix("tnt_ethical"), CCAEthicalComponent.class); - public static final ComponentKey GHOST_RAIL = ComponentRegistryV3.INSTANCE.getOrCreate(prefix("ghost_rail"), CCASpectralRailComponent.class); - public static final ComponentKey INTERNAL_ITEM = ComponentRegistryV3.INSTANCE.getOrCreate(prefix("iitem"), CCAItemFlagsComponent.class); - public static final ComponentKey KEPT_ITEMS = ComponentRegistryV3.INSTANCE.getOrCreate(prefix("kept_items"), CCAKeptItemsComponent.class); - public static final ComponentKey LOONIUM_DROP = ComponentRegistryV3.INSTANCE.getOrCreate(prefix("loonium_drop"), CCALooniumComponent.class); - public static final ComponentKey NARSLIMMUS = ComponentRegistryV3.INSTANCE.getOrCreate(prefix("narslimmus"), CCANarslimmusComponent.class); - public static final ComponentKey TIGERSEYE = ComponentRegistryV3.INSTANCE.getOrCreate(prefix("tigerseye_pacified"), CCATigerseyeComponent.class); + public static final ComponentKey TNT_ETHICAL = ComponentRegistryV3.INSTANCE.getOrCreate(EthicalComponent.ID, CCAEthicalComponent.class); + public static final ComponentKey GHOST_RAIL = ComponentRegistryV3.INSTANCE.getOrCreate(SpectralRailComponent.ID, CCASpectralRailComponent.class); + public static final ComponentKey INTERNAL_ITEM = ComponentRegistryV3.INSTANCE.getOrCreate(ItemFlagsComponent.ID, CCAItemFlagsComponent.class); + public static final ComponentKey KEPT_ITEMS = ComponentRegistryV3.INSTANCE.getOrCreate(KeptItemsComponent.ID, CCAKeptItemsComponent.class); + public static final ComponentKey LOONIUM_DROP = ComponentRegistryV3.INSTANCE.getOrCreate(LooniumComponent.ID, CCALooniumComponent.class); + public static final ComponentKey NARSLIMMUS = ComponentRegistryV3.INSTANCE.getOrCreate(NarslimmusComponent.ID, CCANarslimmusComponent.class); + public static final ComponentKey TIGERSEYE = ComponentRegistryV3.INSTANCE.getOrCreate(TigerseyeComponent.ID, CCATigerseyeComponent.class); @Override public void registerEntityComponentFactories(EntityComponentFactoryRegistry registry) { diff --git a/Fabric/src/main/java/vazkii/botania/fabric/mixin/ItemPredicateFabricMixin.java b/Fabric/src/main/java/vazkii/botania/fabric/mixin/ItemPredicateFabricMixin.java index f36d2c11ba..b23cdbd779 100644 --- a/Fabric/src/main/java/vazkii/botania/fabric/mixin/ItemPredicateFabricMixin.java +++ b/Fabric/src/main/java/vazkii/botania/fabric/mixin/ItemPredicateFabricMixin.java @@ -8,31 +8,22 @@ */ package vazkii.botania.fabric.mixin; -import com.google.common.collect.ImmutableSet; - import net.minecraft.advancements.critereon.ItemPredicate; -import net.minecraft.world.item.Item; -import net.minecraft.world.item.Items; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.ModifyVariable; - -import vazkii.botania.common.item.BotaniaItems; - -import java.util.HashSet; -import java.util.Set; @Mixin(ItemPredicate.class) public abstract class ItemPredicateFabricMixin { - @ModifyVariable(at = @At("HEAD"), method = "(Lnet/minecraft/tags/TagKey;Ljava/util/Set;Lnet/minecraft/advancements/critereon/MinMaxBounds$Ints;Lnet/minecraft/advancements/critereon/MinMaxBounds$Ints;[Lnet/minecraft/advancements/critereon/EnchantmentPredicate;[Lnet/minecraft/advancements/critereon/EnchantmentPredicate;Lnet/minecraft/world/item/alchemy/Potion;Lnet/minecraft/advancements/critereon/NbtPredicate;)V", argsOnly = true) - private static Set addBotaniaShears(Set set) { - if (set != null && set.contains(Items.SHEARS)) { - set = new HashSet<>(set); - set.add(BotaniaItems.manasteelShears); - set.add(BotaniaItems.elementiumShears); - set = ImmutableSet.copyOf(set); - } - return set; - } + // TODO: probably worth dropping in favor of conventional item tag #c:tools/shears instead of trying to hack into record + +// @ModifyVariable(at = @At("HEAD"), method = "(Lnet/minecraft/tags/TagKey;Ljava/util/Set;Lnet/minecraft/advancements/critereon/MinMaxBounds$Ints;Lnet/minecraft/advancements/critereon/MinMaxBounds$Ints;[Lnet/minecraft/advancements/critereon/EnchantmentPredicate;[Lnet/minecraft/advancements/critereon/EnchantmentPredicate;Lnet/minecraft/world/item/alchemy/Potion;Lnet/minecraft/advancements/critereon/NbtPredicate;)V", argsOnly = true) +// private static Set addBotaniaShears(Set set) { +// if (set != null && set.contains(Items.SHEARS)) { +// set = new HashSet<>(set); +// set.add(BotaniaItems.manasteelShears); +// set.add(BotaniaItems.elementiumShears); +// set = ImmutableSet.copyOf(set); +// } +// return set; +// } } diff --git a/NeoForge/src/main/java/vazkii/botania/api/BotaniaForgeCapabilities.java b/NeoForge/src/main/java/vazkii/botania/api/BotaniaForgeCapabilities.java index ca64afba8d..62754d991d 100644 --- a/NeoForge/src/main/java/vazkii/botania/api/BotaniaForgeCapabilities.java +++ b/NeoForge/src/main/java/vazkii/botania/api/BotaniaForgeCapabilities.java @@ -1,9 +1,10 @@ package vazkii.botania.api; -import net.neoforged.neoforge.common.capabilities.Capability; -import net.neoforged.neoforge.common.capabilities.CapabilityManager; -import net.neoforged.neoforge.common.capabilities.CapabilityToken; - +import net.minecraft.core.Direction; +import net.minecraft.resources.ResourceLocation; +import net.neoforged.neoforge.capabilities.BlockCapability; +import net.neoforged.neoforge.capabilities.ItemCapability; +import org.jetbrains.annotations.NotNull; import vazkii.botania.api.block.ExoflameHeatable; import vazkii.botania.api.block.HornHarvestable; import vazkii.botania.api.block.HourglassTrigger; @@ -19,20 +20,40 @@ import vazkii.botania.api.mana.spark.SparkAttachable; public final class BotaniaForgeCapabilities { - public static final Capability AVATAR_WIELDABLE = CapabilityManager.get(new CapabilityToken<>() {}); - public static final Capability BLOCK_PROVIDER = CapabilityManager.get(new CapabilityToken<>() {}); - public static final Capability COORD_BOUND_ITEM = CapabilityManager.get(new CapabilityToken<>() {}); - public static final Capability MANA_ITEM = CapabilityManager.get(new CapabilityToken<>() {}); - public static final Capability RELIC = CapabilityManager.get(new CapabilityToken<>() {}); - - public static final Capability EXOFLAME_HEATABLE = CapabilityManager.get(new CapabilityToken<>() {}); - public static final Capability HORN_HARVEST = CapabilityManager.get(new CapabilityToken<>() {}); - public static final Capability HOURGLASS_TRIGGER = CapabilityManager.get(new CapabilityToken<>() {}); - public static final Capability MANA_GHOST = CapabilityManager.get(new CapabilityToken<>() {}); - public static final Capability MANA_RECEIVER = CapabilityManager.get(new CapabilityToken<>() {}); - public static final Capability SPARK_ATTACHABLE = CapabilityManager.get(new CapabilityToken<>() {}); - public static final Capability MANA_TRIGGER = CapabilityManager.get(new CapabilityToken<>() {}); - public static final Capability WANDABLE = CapabilityManager.get(new CapabilityToken<>() {}); + public static final ItemCapability AVATAR_WIELDABLE = + ItemCapability.createVoid(AvatarWieldable.ID, AvatarWieldable.class); + + public static final ItemCapability BLOCK_PROVIDER = + ItemCapability.createVoid(BlockProvider.ID, BlockProvider.class); + public static final ItemCapability COORD_BOUND_ITEM = + ItemCapability.createVoid(CoordBoundItem.ID, CoordBoundItem.class); + public static final ItemCapability MANA_ITEM = + ItemCapability.createVoid(ManaItem.ID, ManaItem.class); + public static final ItemCapability RELIC = + ItemCapability.createVoid(Relic.ID, Relic.class); + + public static final BlockCapability EXOFLAME_HEATABLE = + BlockCapability.createVoid(ExoflameHeatable.ID, ExoflameHeatable.class); + + public static final BlockCapability HORN_HARVEST = + BlockCapability.createVoid(HornHarvestable.ID, HornHarvestable.class); + public static final BlockCapability HOURGLASS_TRIGGER = + BlockCapability.createVoid(HourglassTrigger.ID, HourglassTrigger.class); + public static final BlockCapability MANA_GHOST = + BlockCapability.createVoid(ManaCollisionGhost.ID, ManaCollisionGhost.class); + public static final BlockCapability MANA_RECEIVER = + BlockCapability.createSided(ManaReceiver.ID, ManaReceiver.class); + + public static final BlockCapability SPARK_ATTACHABLE = + BlockCapability.createSided(SparkAttachable.ID, SparkAttachable.class); + public static final BlockCapability MANA_TRIGGER = + BlockCapability.createVoid(ManaTrigger.ID, ManaTrigger.class); + public static final BlockCapability WANDABLE = + BlockCapability.createVoid(Wandable.ID, Wandable.class); + + private static @NotNull ResourceLocation prefix(String path) { + return new ResourceLocation(BotaniaAPI.MODID, path); + } private BotaniaForgeCapabilities() {} } diff --git a/NeoForge/src/main/java/vazkii/botania/forge/internal_caps/ForgeInternalEntityCapabilities.java b/NeoForge/src/main/java/vazkii/botania/forge/internal_caps/ForgeInternalEntityCapabilities.java index 95a5a84762..c908da97dc 100644 --- a/NeoForge/src/main/java/vazkii/botania/forge/internal_caps/ForgeInternalEntityCapabilities.java +++ b/NeoForge/src/main/java/vazkii/botania/forge/internal_caps/ForgeInternalEntityCapabilities.java @@ -1,5 +1,7 @@ package vazkii.botania.forge.internal_caps; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Mob; import net.minecraft.world.entity.item.ItemEntity; @@ -10,23 +12,45 @@ import net.minecraft.world.entity.vehicle.AbstractMinecart; import net.neoforged.bus.api.SubscribeEvent; import net.neoforged.fml.common.Mod; -import net.neoforged.neoforge.common.capabilities.*; +import net.neoforged.neoforge.attachment.AttachmentType; +import net.neoforged.neoforge.attachment.IAttachmentHolder; +import net.neoforged.neoforge.common.util.INBTSerializable; import net.neoforged.neoforge.event.AttachCapabilitiesEvent; +import net.neoforged.neoforge.registries.DeferredHolder; +import net.neoforged.neoforge.registries.DeferredRegister; +import net.neoforged.neoforge.registries.NeoForgeRegistries; +import vazkii.botania.api.BotaniaAPI; import vazkii.botania.common.internal_caps.*; import vazkii.botania.common.lib.LibMisc; import vazkii.botania.forge.CapabilityUtil; +import java.util.function.Supplier; + import static vazkii.botania.common.lib.ResourceLocationHelper.prefix; public final class ForgeInternalEntityCapabilities { - public static final Capability TNT_ETHICAL = CapabilityManager.get(new CapabilityToken<>() {}); - public static final Capability GHOST_RAIL = CapabilityManager.get(new CapabilityToken<>() {}); - public static final Capability INTERNAL_ITEM = CapabilityManager.get(new CapabilityToken<>() {}); - public static final Capability KEPT_ITEMS = CapabilityManager.get(new CapabilityToken<>() {}); - public static final Capability LOONIUM_DROP = CapabilityManager.get(new CapabilityToken<>() {}); - public static final Capability NARSLIMMUS = CapabilityManager.get(new CapabilityToken<>() {}); - public static final Capability TIGERSEYE = CapabilityManager.get(new CapabilityToken<>() {}); + private static final DeferredRegister> ATTACHMENT_TYPES = DeferredRegister.create(NeoForgeRegistries.Keys.ATTACHMENT_TYPES, BotaniaAPI.MODID); + public static final Supplier> TNT_ETHICAL = ATTACHMENT_TYPES.register( + ForgeEthicalComponent.ID.getPath(), + AttachmentType.serializable(ForgeEthicalComponent::new)::build); + public static final Supplier> GHOST_RAIL = + registerComponentAttachmentType(ForgeSpectralRailComponent.ID, ForgeSpectralRailComponent::new); + public static final Supplier> INTERNAL_ITEM = + registerComponentAttachmentType(ForgeItemFlagsComponent.ID, ForgeItemFlagsComponent::new); + public static final Supplier> KEPT_ITEMS = ATTACHMENT_TYPES.register( + ForgeKeptItemsComponent.ID.getPath(), + AttachmentType.serializable(ForgeKeptItemsComponent::new)::build); + public static final Supplier> LOONIUM_DROP = + registerComponentAttachmentType(ForgeLooniumComponent.ID, ForgeLooniumComponent::new); + public static final Supplier> NARSLIMMUS = + registerComponentAttachmentType(ForgeNarslimmusComponent.ID, ForgeNarslimmusComponent::new); + public static final Supplier> TIGERSEYE = + registerComponentAttachmentType(ForgeTigerseyeComponent.ID, ForgeTigerseyeComponent::new); + + private static > DeferredHolder, AttachmentType> registerComponentAttachmentType(ResourceLocation componentId, Supplier componentSupplier) { + return ATTACHMENT_TYPES.register(componentId.getPath(), AttachmentType.serializable(componentSupplier)::build); + } @Mod.EventBusSubscriber(modid = LibMisc.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD) public static class ModBusEvents { @@ -73,4 +97,28 @@ public static void attachCapabilities(AttachCapabilitiesEvent evt) { } private ForgeInternalEntityCapabilities() {} + + public static class ForgeEthicalComponent extends EthicalComponent implements INBTSerializable { + public ForgeEthicalComponent(IAttachmentHolder entity) { + super((PrimedTnt) entity); + } + } + + public static class ForgeSpectralRailComponent extends SpectralRailComponent implements INBTSerializable { + } + + public static class ForgeItemFlagsComponent extends ItemFlagsComponent implements INBTSerializable { + } + + public static class ForgeKeptItemsComponent extends KeptItemsComponent implements INBTSerializable { + } + + public static class ForgeLooniumComponent extends LooniumComponent implements INBTSerializable { + } + + public static class ForgeNarslimmusComponent extends NarslimmusComponent implements INBTSerializable { + } + + public static class ForgeTigerseyeComponent extends TigerseyeComponent implements INBTSerializable { + } } diff --git a/NeoForge/src/main/java/vazkii/botania/forge/mixin/BuiltInRegistriesForgeAccessor.java b/NeoForge/src/main/java/vazkii/botania/forge/mixin/BuiltInRegistriesForgeAccessor.java deleted file mode 100644 index be2dbfe52a..0000000000 --- a/NeoForge/src/main/java/vazkii/botania/forge/mixin/BuiltInRegistriesForgeAccessor.java +++ /dev/null @@ -1,19 +0,0 @@ -package vazkii.botania.forge.mixin; - -import net.minecraft.core.DefaultedRegistry; -import net.minecraft.core.Registry; -import net.minecraft.core.registries.BuiltInRegistries; -import net.minecraft.resources.ResourceKey; - -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Invoker; - -@Mixin(BuiltInRegistries.class) -public interface BuiltInRegistriesForgeAccessor { - @Invoker("registerDefaulted") - static DefaultedRegistry callRegisterDefaulted(ResourceKey> registryName, - String defaultId, - BuiltInRegistries.RegistryBootstrap bootstrap) { - throw new IllegalStateException(); - } -} diff --git a/NeoForge/src/main/java/vazkii/botania/forge/xplat/ForgeXplatImpl.java b/NeoForge/src/main/java/vazkii/botania/forge/xplat/ForgeXplatImpl.java index 537d9ac440..e51d97884b 100644 --- a/NeoForge/src/main/java/vazkii/botania/forge/xplat/ForgeXplatImpl.java +++ b/NeoForge/src/main/java/vazkii/botania/forge/xplat/ForgeXplatImpl.java @@ -17,7 +17,6 @@ import net.minecraft.tags.*; import net.minecraft.world.InteractionHand; import net.minecraft.world.MenuProvider; -import net.minecraft.world.WorldlyContainerHolder; import net.minecraft.world.effect.MobEffect; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.LivingEntity; @@ -53,14 +52,13 @@ import net.neoforged.api.distmarker.Dist; import net.neoforged.fml.ModList; import net.neoforged.fml.loading.FMLLoader; +import net.neoforged.neoforge.capabilities.Capabilities; import net.neoforged.neoforge.client.event.RegisterClientReloadListenersEvent; import net.neoforged.neoforge.common.CommonHooks; import net.neoforged.neoforge.common.NeoForge; import net.neoforged.neoforge.common.NeoForgeMod; import net.neoforged.neoforge.common.Tags; -import net.neoforged.neoforge.common.capabilities.Capabilities; import net.neoforged.neoforge.common.extensions.IMenuTypeExtension; -import net.neoforged.neoforge.common.util.LazyOptional; import net.neoforged.neoforge.data.loading.DatagenModLoader; import net.neoforged.neoforge.energy.IEnergyStorage; import net.neoforged.neoforge.event.AddReloadListenerEvent; @@ -69,7 +67,6 @@ import net.neoforged.neoforge.fluids.capability.IFluidHandler; import net.neoforged.neoforge.items.IItemHandler; import net.neoforged.neoforge.items.ItemHandlerHelper; -import net.neoforged.neoforge.items.wrapper.SidedInvWrapper; import net.neoforged.neoforge.network.NetworkDirection; import net.neoforged.neoforge.network.NetworkHooks; import net.neoforged.neoforge.network.PacketDistributor; @@ -98,7 +95,6 @@ import vazkii.botania.common.handler.EquipmentHandler; import vazkii.botania.common.internal_caps.*; import vazkii.botania.common.lib.LibMisc; -import vazkii.botania.forge.CapabilityUtil; import vazkii.botania.forge.block.ForgeSpecialFlowerBlock; import vazkii.botania.forge.integration.curios.CurioIntegration; import vazkii.botania.forge.internal_caps.ForgeInternalEntityCapabilities; @@ -110,11 +106,13 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.function.BiFunction; import java.util.function.Consumer; import java.util.function.Supplier; public class ForgeXplatImpl implements XplatAbstractions { + @Override public boolean isForge() { return true; @@ -149,89 +147,90 @@ public String getBotaniaVersion() { @Nullable @Override public AvatarWieldable findAvatarWieldable(ItemStack stack) { - return stack.getCapability(BotaniaForgeCapabilities.AVATAR_WIELDABLE).orElse(null); + return stack.getCapability(BotaniaForgeCapabilities.AVATAR_WIELDABLE); } @Nullable @Override public BlockProvider findBlockProvider(ItemStack stack) { - return stack.getCapability(BotaniaForgeCapabilities.BLOCK_PROVIDER).orElse(null); + return stack.getCapability(BotaniaForgeCapabilities.BLOCK_PROVIDER); } @Nullable @Override public CoordBoundItem findCoordBoundItem(ItemStack stack) { - return stack.getCapability(BotaniaForgeCapabilities.COORD_BOUND_ITEM).orElse(null); + return stack.getCapability(BotaniaForgeCapabilities.COORD_BOUND_ITEM); } @Nullable @Override public ManaItem findManaItem(ItemStack stack) { - return stack.getCapability(BotaniaForgeCapabilities.MANA_ITEM).orElse(null); + return stack.getCapability(BotaniaForgeCapabilities.MANA_ITEM); } @Nullable @Override public Relic findRelic(ItemStack stack) { - return stack.getCapability(BotaniaForgeCapabilities.RELIC).orElse(null); + return stack.getCapability(BotaniaForgeCapabilities.RELIC); } @Nullable @Override public ExoflameHeatable findExoflameHeatable(Level level, BlockPos pos, BlockState state, @Nullable BlockEntity be) { - return CapabilityUtil.findCapability(BotaniaForgeCapabilities.EXOFLAME_HEATABLE, level, pos, state, be); + return level.getCapability(BotaniaForgeCapabilities.EXOFLAME_HEATABLE, pos, state, be, null); } @Nullable @Override public HornHarvestable findHornHarvestable(Level level, BlockPos pos, BlockState state, @Nullable BlockEntity be) { - return CapabilityUtil.findCapability(BotaniaForgeCapabilities.HORN_HARVEST, level, pos, state, be); + return level.getCapability(BotaniaForgeCapabilities.HORN_HARVEST, pos, state, be, null); } @Nullable @Override public HourglassTrigger findHourglassTrigger(Level level, BlockPos pos, BlockState state, @Nullable BlockEntity be) { - return CapabilityUtil.findCapability(BotaniaForgeCapabilities.HOURGLASS_TRIGGER, level, pos, state, be); + return level.getCapability(BotaniaForgeCapabilities.HOURGLASS_TRIGGER, pos, state, be, null); } @Nullable @Override - public ManaCollisionGhost findManaGhost(Level level, BlockPos pos, BlockState state, @org.jetbrains.annotations.Nullable BlockEntity be) { - return CapabilityUtil.findCapability(BotaniaForgeCapabilities.MANA_GHOST, level, pos, state, be); + public ManaCollisionGhost findManaGhost(Level level, BlockPos pos, BlockState state, @Nullable BlockEntity be) { + return level.getCapability(BotaniaForgeCapabilities.MANA_GHOST, pos, state, be, null); } @Nullable @Override public ManaReceiver findManaReceiver(Level level, BlockPos pos, BlockState state, @Nullable BlockEntity be, @Nullable Direction direction) { - return CapabilityUtil.findCapability(BotaniaForgeCapabilities.MANA_RECEIVER, level, pos, state, be, direction); + return level.getCapability(BotaniaForgeCapabilities.MANA_RECEIVER, pos, state, be, direction); } @Nullable @Override public SparkAttachable findSparkAttachable(Level level, BlockPos pos, BlockState blockState, @Nullable BlockEntity be, Direction direction) { - return CapabilityUtil.findCapability(BotaniaForgeCapabilities.SPARK_ATTACHABLE, level, pos, blockState, be, direction); + return level.getCapability(BotaniaForgeCapabilities.SPARK_ATTACHABLE, pos, blockState, be, direction); } @Nullable @Override - public ManaTrigger findManaTrigger(Level level, BlockPos pos, BlockState state, @org.jetbrains.annotations.Nullable BlockEntity be) { - return CapabilityUtil.findCapability(BotaniaForgeCapabilities.MANA_TRIGGER, level, pos, state, be); + public ManaTrigger findManaTrigger(Level level, BlockPos pos, BlockState state, @Nullable BlockEntity be) { + return level.getCapability(BotaniaForgeCapabilities.MANA_TRIGGER, pos, state, be, null); } @Nullable @Override public Wandable findWandable(Level level, BlockPos pos, BlockState state, @Nullable BlockEntity be) { - return CapabilityUtil.findCapability(BotaniaForgeCapabilities.WANDABLE, level, pos, state, be); + return level.getCapability(BotaniaForgeCapabilities.WANDABLE, pos, state, be, null); } @Override public boolean isFluidContainer(ItemEntity item) { - return item.getItem().getCapability(Capabilities.FLUID_HANDLER_ITEM).isPresent(); + return item.getItem().getCapability(Capabilities.FluidHandler.ITEM) != null; } @Override public boolean extractFluidFromItemEntity(ItemEntity item, Fluid fluid) { - return item.getItem().getCapability(Capabilities.FLUID_HANDLER_ITEM) + // TODO: Refactor code. I just want to get this to compile first. + return Optional.ofNullable(item.getItem().getCapability(Capabilities.FluidHandler.ITEM)) .map(h -> { var extracted = h.drain(new FluidStack(fluid, FluidType.BUCKET_VOLUME), IFluidHandler.FluidAction.SIMULATE); @@ -248,7 +247,8 @@ public boolean extractFluidFromItemEntity(ItemEntity item, Fluid fluid) { @Override public boolean extractFluidFromPlayerItem(Player player, InteractionHand hand, Fluid fluid) { var stack = player.getItemInHand(hand); - return stack.getCapability(Capabilities.FLUID_HANDLER_ITEM) + // TODO: Refactor code. I just want to get this to compile first. + return Optional.ofNullable(stack.getCapability(Capabilities.FluidHandler.ITEM)) .map(h -> { var extracted = h.drain(new FluidStack(fluid, FluidType.BUCKET_VOLUME), IFluidHandler.FluidAction.SIMULATE); @@ -274,9 +274,8 @@ public boolean insertFluidIntoPlayerItem(Player player, InteractionHand hand, Fl ItemStack toFill = stack.copy(); toFill.setCount(1); - var maybeFluidHandler = toFill.getCapability(Capabilities.FLUID_HANDLER_ITEM); - if (maybeFluidHandler.isPresent()) { - var fluidHandler = maybeFluidHandler.orElseThrow(IllegalStateException::new); + var fluidHandler = toFill.getCapability(Capabilities.FluidHandler.ITEM); + if (fluidHandler != null) { var fluidToFill = new FluidStack(fluid, FluidType.BUCKET_VOLUME); int filled = fluidHandler.fill(fluidToFill, IFluidHandler.FluidAction.SIMULATE); @@ -300,74 +299,49 @@ public boolean insertFluidIntoPlayerItem(Player player, InteractionHand hand, Fl @Override public boolean hasInventory(Level level, BlockPos pos, Direction sideOfPos) { - var state = level.getBlockState(pos); - var be = level.getBlockEntity(pos); - return be != null && be.getCapability(Capabilities.ITEM_HANDLER, sideOfPos).isPresent() - || state.getBlock() instanceof WorldlyContainerHolder wch - && wch.getContainer(state, level, pos).getSlotsForFace(sideOfPos).length > 0; + return level.getCapability(Capabilities.ItemHandler.BLOCK, pos, sideOfPos) != null; } @Override public ItemStack insertToInventory(Level level, BlockPos pos, Direction sideOfPos, ItemStack toInsert, boolean simulate) { - var be = level.getBlockEntity(pos); - LazyOptional cap = LazyOptional.empty(); - if (be != null) { - cap = be.getCapability(Capabilities.ITEM_HANDLER, sideOfPos); - } else { - // check vanilla interface for blocks not covered by forge capabilities, e.g. composter - var state = level.getBlockState(pos); - if (state.getBlock() instanceof WorldlyContainerHolder wch) { - cap = LazyOptional.of(() -> new SidedInvWrapper(wch.getContainer(state, level, pos), sideOfPos)); - } - } - - return cap.map(handler -> ItemHandlerHelper.insertItemStacked(handler, toInsert, simulate)) - .orElse(toInsert); + IItemHandler itemHandler = level.getCapability(Capabilities.ItemHandler.BLOCK, pos, sideOfPos); + return itemHandler != null ? ItemHandlerHelper.insertItemStacked(itemHandler, toInsert, simulate) : toInsert; } @Override public EthicalComponent ethicalComponent(PrimedTnt tnt) { - return tnt.getCapability(ForgeInternalEntityCapabilities.TNT_ETHICAL).orElseThrow(IllegalStateException::new); + return tnt.getData(ForgeInternalEntityCapabilities.TNT_ETHICAL); } @Override public SpectralRailComponent ghostRailComponent(AbstractMinecart cart) { - return cart.getCapability(ForgeInternalEntityCapabilities.GHOST_RAIL).orElseThrow(IllegalStateException::new); + return cart.getData(ForgeInternalEntityCapabilities.GHOST_RAIL); } @Override public ItemFlagsComponent itemFlagsComponent(ItemEntity item) { - // If missing, just give a fresh instance - works around Create's Ponder fake world - return item.getCapability(ForgeInternalEntityCapabilities.INTERNAL_ITEM).orElseGet(ItemFlagsComponent::new); + return item.getData(ForgeInternalEntityCapabilities.INTERNAL_ITEM); } @Override public KeptItemsComponent keptItemsComponent(Player player, boolean reviveCaps) { - if (reviveCaps) { - // See the javadoc on reviveCaps for why this is necessary - player.reviveCaps(); - } - var ret = player.getCapability(ForgeInternalEntityCapabilities.KEPT_ITEMS).orElseThrow(IllegalStateException::new); - if (reviveCaps) { - player.invalidateCaps(); - } - return ret; + return player.getData(ForgeInternalEntityCapabilities.KEPT_ITEMS); } @Nullable @Override public LooniumComponent looniumComponent(LivingEntity entity) { - return entity.getCapability(ForgeInternalEntityCapabilities.LOONIUM_DROP).orElse(null); + return entity.getData(ForgeInternalEntityCapabilities.LOONIUM_DROP); } @Override public NarslimmusComponent narslimmusComponent(Slime slime) { - return slime.getCapability(ForgeInternalEntityCapabilities.NARSLIMMUS).orElseThrow(IllegalStateException::new); + return slime.getData(ForgeInternalEntityCapabilities.NARSLIMMUS); } @Override public TigerseyeComponent tigersEyeComponent(Creeper creeper) { - return creeper.getCapability(ForgeInternalEntityCapabilities.TIGERSEYE).orElseThrow(IllegalStateException::new); + return creeper.getData(ForgeInternalEntityCapabilities.TIGERSEYE); } @Override @@ -514,12 +488,12 @@ public void openMenu(ServerPlayer player, MenuProvider menu, Consumer storage = LazyOptional.empty(); + IEnergyStorage storage = level.getCapability(Capabilities.EnergyStorage.BLOCK, pos, e.getOpposite()); - if (be.getCapability(Capabilities.ENERGY, e.getOpposite()).isPresent()) { - storage = be.getCapability(Capabilities.ENERGY, e.getOpposite()); - } else if (be.getCapability(Capabilities.ENERGY, null).isPresent()) { - storage = be.getCapability(Capabilities.ENERGY, null); + if (storage == null) { + storage = level.getCapability(Capabilities.EnergyStorage.BLOCK, pos, null); } - if (storage.isPresent()) { - energy -= storage.orElseThrow(NullPointerException::new).receiveEnergy(energy, false); + if (storage != null) { + energy -= storage.receiveEnergy(energy, false); if (energy <= 0) { return 0; @@ -592,10 +559,11 @@ public int transferEnergyToNeighbors(Level level, BlockPos pos, int energy) { return energy; } + // TODO: Maybe switch to level and block position? @Override public boolean isRedStringContainerTarget(BlockEntity be) { for (Direction dir : Direction.values()) { - if (be.getCapability(Capabilities.ITEM_HANDLER, dir).isPresent()) { + if (be.getLevel().getCapability(Capabilities.ItemHandler.BLOCK, be.getBlockPos(), be.getBlockState(), be, dir) != null) { return true; } } @@ -609,7 +577,8 @@ public RedStringContainerBlockEntity newRedStringContainer(BlockPos pos, BlockSt @Override public BlockSetType registerBlockSetType(String name, boolean canOpenByHand, SoundType soundType, SoundEvent doorClose, SoundEvent doorOpen, SoundEvent trapdoorClose, SoundEvent trapdoorOpen, SoundEvent pressurePlateClickOff, SoundEvent pressurePlateClickOn, SoundEvent buttonClickOff, SoundEvent buttonClickOn) { - return BlockSetType.register(new BlockSetType("botania:" + name, canOpenByHand, soundType, doorClose, doorOpen, trapdoorClose, trapdoorOpen, pressurePlateClickOff, pressurePlateClickOn, buttonClickOff, buttonClickOn)); + // TODO: There are a bunch of new parameters that need to be incorporated into the API. + return BlockSetType.register(new BlockSetType("botania:" + name, canOpenByHand, canOpenByHand, canOpenByHand, BlockSetType.PressurePlateSensitivity.EVERYTHING, soundType, doorClose, doorOpen, trapdoorClose, trapdoorOpen, pressurePlateClickOff, pressurePlateClickOn, buttonClickOff, buttonClickOn)); } @Override diff --git a/NeoForge/src/main/resources/botania_forge.mixins.json b/NeoForge/src/main/resources/botania_forge.mixins.json index 18f8d1c3f5..e591000e0e 100644 --- a/NeoForge/src/main/resources/botania_forge.mixins.json +++ b/NeoForge/src/main/resources/botania_forge.mixins.json @@ -5,13 +5,12 @@ "package": "vazkii.botania.forge.mixin", "mixins": [ "AbstractFurnaceBlockEntityForgeAccessor", - "BotaniaGrassBlockForgeMixin", - "BuiltInRegistriesForgeAccessor" + "BotaniaGrassBlockForgeMixin" ], "client": [ - "client.ModelBakeryForgeAccessor", "client.ItemBlockWithSpecialRendererForgeMixin", - "client.ItemManasteelArmorForgeMixin" + "client.ItemManasteelArmorForgeMixin", + "client.ModelBakeryForgeAccessor" ], "injectors": { "defaultRequire": 1 diff --git a/Xplat/src/main/java/vazkii/botania/api/block/ExoflameHeatable.java b/Xplat/src/main/java/vazkii/botania/api/block/ExoflameHeatable.java index fbe80237c7..5a8c12e368 100644 --- a/Xplat/src/main/java/vazkii/botania/api/block/ExoflameHeatable.java +++ b/Xplat/src/main/java/vazkii/botania/api/block/ExoflameHeatable.java @@ -8,11 +8,16 @@ */ package vazkii.botania.api.block; +import net.minecraft.resources.ResourceLocation; +import vazkii.botania.api.BotaniaAPI; + /** * A Block Entity that has this component can be heated by an Exoflame flower. * NOTE: Do not attach this component to subclasses of AbstractFurnaceBlockEntity, as Botania already does so. */ public interface ExoflameHeatable { + ResourceLocation ID = new ResourceLocation(BotaniaAPI.MODID, "exoflame_heatable"); + /** * Can this BlockEntity smelt its contents. If true, the Exoflame is allowed * to fuel it. diff --git a/Xplat/src/main/java/vazkii/botania/api/block/HornHarvestable.java b/Xplat/src/main/java/vazkii/botania/api/block/HornHarvestable.java index 5e8ff92a49..f0244966ca 100644 --- a/Xplat/src/main/java/vazkii/botania/api/block/HornHarvestable.java +++ b/Xplat/src/main/java/vazkii/botania/api/block/HornHarvestable.java @@ -9,11 +9,13 @@ package vazkii.botania.api.block; import net.minecraft.core.BlockPos; +import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; import org.jetbrains.annotations.Nullable; +import vazkii.botania.api.BotaniaAPI; /** * Blocks with this capability can express custom logic when being @@ -21,6 +23,8 @@ */ @FunctionalInterface public interface HornHarvestable { + ResourceLocation ID = new ResourceLocation(BotaniaAPI.MODID, "horn_harvestable"); + /** * Returns true if this block can be uprooted. * Note that the stack param can be empty if it's a drum breaking it. diff --git a/Xplat/src/main/java/vazkii/botania/api/block/HourglassTrigger.java b/Xplat/src/main/java/vazkii/botania/api/block/HourglassTrigger.java index 1be03e9dbf..a34d055eae 100644 --- a/Xplat/src/main/java/vazkii/botania/api/block/HourglassTrigger.java +++ b/Xplat/src/main/java/vazkii/botania/api/block/HourglassTrigger.java @@ -8,7 +8,9 @@ */ package vazkii.botania.api.block; +import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.block.entity.BlockEntity; +import vazkii.botania.api.BotaniaAPI; /** * A block with this capability will receive a custom callback when a Hovering @@ -16,6 +18,8 @@ */ public interface HourglassTrigger { + ResourceLocation ID = new ResourceLocation(BotaniaAPI.MODID, "hourglass_trigger"); + void onTriggeredByHourglass(BlockEntity hourglass); } diff --git a/Xplat/src/main/java/vazkii/botania/api/block/Wandable.java b/Xplat/src/main/java/vazkii/botania/api/block/Wandable.java index cc4d30a83d..022cb492b4 100644 --- a/Xplat/src/main/java/vazkii/botania/api/block/Wandable.java +++ b/Xplat/src/main/java/vazkii/botania/api/block/Wandable.java @@ -9,16 +9,20 @@ package vazkii.botania.api.block; import net.minecraft.core.Direction; +import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import org.jetbrains.annotations.Nullable; +import vazkii.botania.api.BotaniaAPI; /** * Any block with this component can be used with the Wand for the Forest for some purpose. */ public interface Wandable { + ResourceLocation ID = new ResourceLocation(BotaniaAPI.MODID, "wandable"); + /** * Called when the block is used by a wand. * diff --git a/Xplat/src/main/java/vazkii/botania/api/item/AvatarWieldable.java b/Xplat/src/main/java/vazkii/botania/api/item/AvatarWieldable.java index 5333d15ba5..86321ad67f 100644 --- a/Xplat/src/main/java/vazkii/botania/api/item/AvatarWieldable.java +++ b/Xplat/src/main/java/vazkii/botania/api/item/AvatarWieldable.java @@ -10,6 +10,7 @@ import net.minecraft.resources.ResourceLocation; +import vazkii.botania.api.BotaniaAPI; import vazkii.botania.api.block.Avatar; /** @@ -17,6 +18,8 @@ */ public interface AvatarWieldable { + ResourceLocation ID = new ResourceLocation(BotaniaAPI.MODID, "avatar_wieldable"); + /** * Called on update of the avatar tile. */ diff --git a/Xplat/src/main/java/vazkii/botania/api/item/BlockProvider.java b/Xplat/src/main/java/vazkii/botania/api/item/BlockProvider.java index f2f2991d1a..9debfc113d 100644 --- a/Xplat/src/main/java/vazkii/botania/api/item/BlockProvider.java +++ b/Xplat/src/main/java/vazkii/botania/api/item/BlockProvider.java @@ -8,9 +8,11 @@ */ package vazkii.botania.api.item; +import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.Block; +import vazkii.botania.api.BotaniaAPI; /** * An Item that has this capability can provide blocks to other items that use them. @@ -21,6 +23,8 @@ */ public interface BlockProvider { + ResourceLocation ID = new ResourceLocation(BotaniaAPI.MODID, "block_provider"); + /** * Provides the requested item. The doit paremeter specifies whether this is * just a test (false) or if the item should actually be removed (true). diff --git a/Xplat/src/main/java/vazkii/botania/api/item/CoordBoundItem.java b/Xplat/src/main/java/vazkii/botania/api/item/CoordBoundItem.java index f110b53118..269a103474 100644 --- a/Xplat/src/main/java/vazkii/botania/api/item/CoordBoundItem.java +++ b/Xplat/src/main/java/vazkii/botania/api/item/CoordBoundItem.java @@ -9,10 +9,12 @@ package vazkii.botania.api.item; import net.minecraft.core.BlockPos; +import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.Level; import org.jetbrains.annotations.Nullable; +import vazkii.botania.api.BotaniaAPI; import vazkii.botania.api.block.Bound; /** @@ -23,6 +25,8 @@ */ public interface CoordBoundItem { + ResourceLocation ID = new ResourceLocation(BotaniaAPI.MODID, "coord_bound_item"); + @Nullable BlockPos getBinding(Level world); diff --git a/Xplat/src/main/java/vazkii/botania/api/item/Relic.java b/Xplat/src/main/java/vazkii/botania/api/item/Relic.java index 9e74542202..397cce98c1 100644 --- a/Xplat/src/main/java/vazkii/botania/api/item/Relic.java +++ b/Xplat/src/main/java/vazkii/botania/api/item/Relic.java @@ -12,6 +12,7 @@ import net.minecraft.world.entity.player.Player; import org.jetbrains.annotations.Nullable; +import vazkii.botania.api.BotaniaAPI; import java.util.UUID; @@ -21,6 +22,8 @@ */ public interface Relic { + ResourceLocation ID = new ResourceLocation(BotaniaAPI.MODID, "relic"); + /** * Binds to the UUID passed in. */ diff --git a/Xplat/src/main/java/vazkii/botania/api/mana/ManaCollisionGhost.java b/Xplat/src/main/java/vazkii/botania/api/mana/ManaCollisionGhost.java index d701c0ed56..6ad2feea3c 100644 --- a/Xplat/src/main/java/vazkii/botania/api/mana/ManaCollisionGhost.java +++ b/Xplat/src/main/java/vazkii/botania/api/mana/ManaCollisionGhost.java @@ -8,10 +8,15 @@ */ package vazkii.botania.api.mana; +import net.minecraft.resources.ResourceLocation; +import vazkii.botania.api.BotaniaAPI; + /** * Any Block or Block Entity with this capability has custom collision logic for bursts. */ public interface ManaCollisionGhost { + ResourceLocation ID = new ResourceLocation(BotaniaAPI.MODID, "mana_ghost"); + enum Behaviour { /** * Skip all collision logic, the burst acts as if this block did not exist diff --git a/Xplat/src/main/java/vazkii/botania/api/mana/ManaItem.java b/Xplat/src/main/java/vazkii/botania/api/mana/ManaItem.java index 1697537b85..7d2f5547c8 100644 --- a/Xplat/src/main/java/vazkii/botania/api/mana/ManaItem.java +++ b/Xplat/src/main/java/vazkii/botania/api/mana/ManaItem.java @@ -8,14 +8,18 @@ */ package vazkii.botania.api.mana; +import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.entity.BlockEntity; +import vazkii.botania.api.BotaniaAPI; /** * An item that has this capability can contain mana. */ public interface ManaItem { + ResourceLocation ID = new ResourceLocation(BotaniaAPI.MODID, "mana_item"); + /** * Gets the amount of mana this item contains */ diff --git a/Xplat/src/main/java/vazkii/botania/api/mana/ManaReceiver.java b/Xplat/src/main/java/vazkii/botania/api/mana/ManaReceiver.java index 5e7904b3b1..2d0286d199 100644 --- a/Xplat/src/main/java/vazkii/botania/api/mana/ManaReceiver.java +++ b/Xplat/src/main/java/vazkii/botania/api/mana/ManaReceiver.java @@ -9,12 +9,16 @@ package vazkii.botania.api.mana; import net.minecraft.core.BlockPos; +import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.Level; +import vazkii.botania.api.BotaniaAPI; /** * Any Block or Block Entity with this capability can hold and receive mana from mana bursts. */ public interface ManaReceiver { + ResourceLocation ID = new ResourceLocation(BotaniaAPI.MODID, "mana_receiver"); + Level getManaReceiverLevel(); BlockPos getManaReceiverPos(); diff --git a/Xplat/src/main/java/vazkii/botania/api/mana/ManaTrigger.java b/Xplat/src/main/java/vazkii/botania/api/mana/ManaTrigger.java index 88f8c4ef94..304153a8f8 100644 --- a/Xplat/src/main/java/vazkii/botania/api/mana/ManaTrigger.java +++ b/Xplat/src/main/java/vazkii/botania/api/mana/ManaTrigger.java @@ -8,6 +8,8 @@ */ package vazkii.botania.api.mana; +import net.minecraft.resources.ResourceLocation; +import vazkii.botania.api.BotaniaAPI; import vazkii.botania.api.internal.ManaBurst; /** @@ -16,6 +18,8 @@ */ public interface ManaTrigger { + ResourceLocation ID = new ResourceLocation(BotaniaAPI.MODID, "mana_trigger"); + void onBurstCollision(ManaBurst burst); } diff --git a/Xplat/src/main/java/vazkii/botania/api/mana/spark/SparkAttachable.java b/Xplat/src/main/java/vazkii/botania/api/mana/spark/SparkAttachable.java index 51f294bbed..053fe40995 100644 --- a/Xplat/src/main/java/vazkii/botania/api/mana/spark/SparkAttachable.java +++ b/Xplat/src/main/java/vazkii/botania/api/mana/spark/SparkAttachable.java @@ -8,7 +8,9 @@ */ package vazkii.botania.api.mana.spark; +import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.ItemStack; +import vazkii.botania.api.BotaniaAPI; /** * A block entity with this capability can have a mana spark attached to it. @@ -16,6 +18,8 @@ */ public interface SparkAttachable { + ResourceLocation ID = new ResourceLocation(BotaniaAPI.MODID, "spark_attachable"); + /** * Can this block have a Spark attached to it. Note that this will not * unattach the Spark if it's changed later. diff --git a/Xplat/src/main/java/vazkii/botania/common/internal_caps/EthicalComponent.java b/Xplat/src/main/java/vazkii/botania/common/internal_caps/EthicalComponent.java index 9dc8fa0de6..f55d760f2b 100644 --- a/Xplat/src/main/java/vazkii/botania/common/internal_caps/EthicalComponent.java +++ b/Xplat/src/main/java/vazkii/botania/common/internal_caps/EthicalComponent.java @@ -8,15 +8,24 @@ */ package vazkii.botania.common.internal_caps; +import com.mojang.serialization.Codec; import net.minecraft.nbt.CompoundTag; +import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.item.PrimedTnt; import vazkii.botania.common.helper.EthicalTntHelper; +import static vazkii.botania.common.lib.ResourceLocationHelper.prefix; + public class EthicalComponent extends SerializableComponent { + public static final ResourceLocation ID = prefix("tnt_ethical"); protected static final String TAG_UNETHICAL = "botania:unethical"; protected boolean unethical; + public EthicalComponent() { + // for deserialization + } + public EthicalComponent(PrimedTnt entity) { if (!entity.level().isClientSide()) { EthicalTntHelper.addTrackedTntEntity(entity); diff --git a/Xplat/src/main/java/vazkii/botania/common/internal_caps/ItemFlagsComponent.java b/Xplat/src/main/java/vazkii/botania/common/internal_caps/ItemFlagsComponent.java index 3e7d5b5fde..c77e34dcf3 100644 --- a/Xplat/src/main/java/vazkii/botania/common/internal_caps/ItemFlagsComponent.java +++ b/Xplat/src/main/java/vazkii/botania/common/internal_caps/ItemFlagsComponent.java @@ -9,9 +9,13 @@ package vazkii.botania.common.internal_caps; import net.minecraft.nbt.CompoundTag; +import net.minecraft.resources.ResourceLocation; + +import static vazkii.botania.common.lib.ResourceLocationHelper.prefix; // Component for misc internal Botania flags public class ItemFlagsComponent extends SerializableComponent { + public static final ResourceLocation ID = prefix("iitem"); public boolean elvenPortalSpawned = false; public boolean apothecarySpawned = false; public boolean manaInfusionSpawned = false; diff --git a/Xplat/src/main/java/vazkii/botania/common/internal_caps/KeptItemsComponent.java b/Xplat/src/main/java/vazkii/botania/common/internal_caps/KeptItemsComponent.java index 997575384c..6850ac906b 100644 --- a/Xplat/src/main/java/vazkii/botania/common/internal_caps/KeptItemsComponent.java +++ b/Xplat/src/main/java/vazkii/botania/common/internal_caps/KeptItemsComponent.java @@ -11,13 +11,17 @@ import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.ListTag; import net.minecraft.nbt.Tag; +import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.ItemStack; import java.util.ArrayList; import java.util.Collection; import java.util.List; +import static vazkii.botania.common.lib.ResourceLocationHelper.prefix; + public class KeptItemsComponent extends SerializableComponent { + public static final ResourceLocation ID = prefix("kept_items"); private final List stacks = new ArrayList<>(); public void addAll(Collection stack) { diff --git a/Xplat/src/main/java/vazkii/botania/common/internal_caps/LooniumComponent.java b/Xplat/src/main/java/vazkii/botania/common/internal_caps/LooniumComponent.java index 9792468309..9b78403f43 100644 --- a/Xplat/src/main/java/vazkii/botania/common/internal_caps/LooniumComponent.java +++ b/Xplat/src/main/java/vazkii/botania/common/internal_caps/LooniumComponent.java @@ -9,11 +9,15 @@ package vazkii.botania.common.internal_caps; import net.minecraft.nbt.CompoundTag; +import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.ItemStack; import java.util.Objects; +import static vazkii.botania.common.lib.ResourceLocationHelper.prefix; + public class LooniumComponent extends SerializableComponent { + public static final ResourceLocation ID = prefix("loonium_drop"); protected static final String TAG_TODROP = "toDrop"; protected static final String TAG_DROP_NOTHING = "dropNothing"; protected static final String TAG_SLOW_DESPAWN = "slowDespawn"; diff --git a/Xplat/src/main/java/vazkii/botania/common/internal_caps/NarslimmusComponent.java b/Xplat/src/main/java/vazkii/botania/common/internal_caps/NarslimmusComponent.java index 7fe7ab0d42..e1fd787cc3 100644 --- a/Xplat/src/main/java/vazkii/botania/common/internal_caps/NarslimmusComponent.java +++ b/Xplat/src/main/java/vazkii/botania/common/internal_caps/NarslimmusComponent.java @@ -9,9 +9,13 @@ package vazkii.botania.common.internal_caps; import net.minecraft.nbt.CompoundTag; +import net.minecraft.resources.ResourceLocation; + +import static vazkii.botania.common.lib.ResourceLocationHelper.prefix; public class NarslimmusComponent extends SerializableComponent { public static final String TAG_WORLD_SPAWNED = "botania:world_spawned"; + public static final ResourceLocation ID = prefix("narslimmus"); private boolean naturalSpawned = false; @Override diff --git a/Xplat/src/main/java/vazkii/botania/common/internal_caps/SerializableComponent.java b/Xplat/src/main/java/vazkii/botania/common/internal_caps/SerializableComponent.java index 70650692eb..26e64a3d74 100644 --- a/Xplat/src/main/java/vazkii/botania/common/internal_caps/SerializableComponent.java +++ b/Xplat/src/main/java/vazkii/botania/common/internal_caps/SerializableComponent.java @@ -3,20 +3,27 @@ import net.minecraft.nbt.CompoundTag; import org.jetbrains.annotations.NotNull; +import vazkii.botania.common.annotations.SoftImplement; public abstract class SerializableComponent { + // Fabric CCA interface + @SoftImplement("Component") public abstract void readFromNbt(CompoundTag tag); + @SoftImplement("Component") public abstract void writeToNbt(CompoundTag tag); + // NeoForge interface @NotNull + @SoftImplement("INBTSerializer") public final CompoundTag serializeNBT() { var ret = new CompoundTag(); writeToNbt(ret); return ret; } - public final void deserializeNBT(CompoundTag nbt) { + @SoftImplement("INBTSerializer") + public final void deserializeNBT(@NotNull CompoundTag nbt) { readFromNbt(nbt); } } diff --git a/Xplat/src/main/java/vazkii/botania/common/internal_caps/SpectralRailComponent.java b/Xplat/src/main/java/vazkii/botania/common/internal_caps/SpectralRailComponent.java index 628da37d7e..78c2ed4315 100644 --- a/Xplat/src/main/java/vazkii/botania/common/internal_caps/SpectralRailComponent.java +++ b/Xplat/src/main/java/vazkii/botania/common/internal_caps/SpectralRailComponent.java @@ -10,9 +10,13 @@ import net.minecraft.nbt.CompoundTag; +import net.minecraft.resources.ResourceLocation; import vazkii.botania.common.block.SpectralRailBlock; +import static vazkii.botania.common.lib.ResourceLocationHelper.prefix; + public class SpectralRailComponent extends SerializableComponent { + public static final ResourceLocation ID = prefix("ghost_rail"); public int floatTicks = 0; @Override diff --git a/Xplat/src/main/java/vazkii/botania/common/internal_caps/TigerseyeComponent.java b/Xplat/src/main/java/vazkii/botania/common/internal_caps/TigerseyeComponent.java index 30ce650d51..9ac8dfca70 100644 --- a/Xplat/src/main/java/vazkii/botania/common/internal_caps/TigerseyeComponent.java +++ b/Xplat/src/main/java/vazkii/botania/common/internal_caps/TigerseyeComponent.java @@ -9,8 +9,12 @@ package vazkii.botania.common.internal_caps; import net.minecraft.nbt.CompoundTag; +import net.minecraft.resources.ResourceLocation; + +import static vazkii.botania.common.lib.ResourceLocationHelper.prefix; public class TigerseyeComponent extends SerializableComponent { + public static final ResourceLocation ID = prefix("tigerseye_pacified"); private static final String TAG_PACIFIED = "botania:tigerseye_pacified"; private boolean pacified = false;