Search in sources :

Example 1 with Capability

use of net.minecraftforge.common.capabilities.Capability in project MorePlanets by SteveKunG.

the class CapabilityHandlerMP method register.

public static void register() {
    CapabilityManager.INSTANCE.register(MorePlanetsCapabilityData.class, new Capability.IStorage<MorePlanetsCapabilityData>() {

        @Override
        public NBTBase writeNBT(Capability<MorePlanetsCapabilityData> capability, MorePlanetsCapabilityData instance, EnumFacing side) {
            NBTTagCompound nbt = new NBTTagCompound();
            instance.writeNBT(nbt);
            return nbt;
        }

        @Override
        public void readNBT(Capability<MorePlanetsCapabilityData> capability, MorePlanetsCapabilityData instance, EnumFacing side, NBTBase nbt) {
            instance.readNBT((NBTTagCompound) nbt);
        }
    }, MPCapData::new);
    CommonRegisterHelper.registerForgeEvent(new CapabilityHandlerMP());
}
Also used : Capability(net.minecraftforge.common.capabilities.Capability) NBTBase(net.minecraft.nbt.NBTBase) EnumFacing(net.minecraft.util.EnumFacing) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Example 2 with Capability

use of net.minecraftforge.common.capabilities.Capability in project RFTools by McJty.

the class CommonProxy method preInit.

public void preInit(FMLPreInitializationEvent e) {
    MinecraftForge.EVENT_BUS.register(new ForgeEventHandlers());
    McJtyLib.preInit(e);
    CommandHandler.registerCommands();
    reflect();
    GeneralConfig.preInit(e);
    modConfigDir = e.getModConfigurationDirectory();
    mainConfig = new Configuration(new File(modConfigDir.getPath() + File.separator + "rftools", "rftools.cfg"));
    CapabilityManager.INSTANCE.register(BuffProperties.class, new Capability.IStorage<BuffProperties>() {

        @Override
        public NBTBase writeNBT(Capability<BuffProperties> capability, BuffProperties instance, EnumFacing side) {
            throw new UnsupportedOperationException();
        }

        @Override
        public void readNBT(Capability<BuffProperties> capability, BuffProperties instance, EnumFacing side, NBTBase nbt) {
            throw new UnsupportedOperationException();
        }
    }, () -> {
        throw new UnsupportedOperationException();
    });
    CapabilityManager.INSTANCE.register(FavoriteDestinationsProperties.class, new Capability.IStorage<FavoriteDestinationsProperties>() {

        @Override
        public NBTBase writeNBT(Capability<FavoriteDestinationsProperties> capability, FavoriteDestinationsProperties instance, EnumFacing side) {
            throw new UnsupportedOperationException();
        }

        @Override
        public void readNBT(Capability<FavoriteDestinationsProperties> capability, FavoriteDestinationsProperties instance, EnumFacing side, NBTBase nbt) {
            throw new UnsupportedOperationException();
        }
    }, () -> {
        throw new UnsupportedOperationException();
    });
    CapabilityManager.INSTANCE.register(IModuleProvider.class, new Capability.IStorage<IModuleProvider>() {

        @Override
        public NBTBase writeNBT(Capability<IModuleProvider> capability, IModuleProvider instance, EnumFacing side) {
            throw new UnsupportedOperationException();
        }

        @Override
        public void readNBT(Capability<IModuleProvider> capability, IModuleProvider instance, EnumFacing side, NBTBase nbt) {
            throw new UnsupportedOperationException();
        }
    }, () -> {
        throw new UnsupportedOperationException();
    });
    readMainConfig();
    SimpleNetworkWrapper network = PacketHandler.registerMessages(RFTools.MODID, "rftools");
    RFToolsMessages.registerNetworkMessages(network);
    ModItems.init();
    ModBlocks.init();
    ModWorldgen.init();
    RFTools.screenModuleRegistry.registerBuiltins();
    ForgeChunkManager.setForcedChunkLoadingCallback(RFTools.instance, (tickets, world) -> {
    });
}
Also used : SimpleNetworkWrapper(net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper) BoosterConfiguration(mcjty.rftools.blocks.booster.BoosterConfiguration) BlockProtectorConfiguration(mcjty.rftools.blocks.blockprotector.BlockProtectorConfiguration) GeneralConfiguration(mcjty.rftools.GeneralConfiguration) SpawnerConfiguration(mcjty.rftools.blocks.spawner.SpawnerConfiguration) ModularStorageConfiguration(mcjty.rftools.blocks.storage.ModularStorageConfiguration) StorageScannerConfiguration(mcjty.rftools.blocks.storagemonitor.StorageScannerConfiguration) Configuration(net.minecraftforge.common.config.Configuration) ShieldConfiguration(mcjty.rftools.blocks.shield.ShieldConfiguration) CoalGeneratorConfiguration(mcjty.rftools.blocks.generator.CoalGeneratorConfiguration) SecurityConfiguration(mcjty.rftools.blocks.security.SecurityConfiguration) NetworkMonitorConfiguration(mcjty.rftools.items.netmonitor.NetworkMonitorConfiguration) TeleportConfiguration(mcjty.rftools.blocks.teleporter.TeleportConfiguration) MachineInfuserConfiguration(mcjty.rftools.blocks.infuser.MachineInfuserConfiguration) CrafterConfiguration(mcjty.rftools.blocks.crafter.CrafterConfiguration) EnvironmentalConfiguration(mcjty.rftools.blocks.environmental.EnvironmentalConfiguration) ElevatorConfiguration(mcjty.rftools.blocks.elevator.ElevatorConfiguration) ScannerConfiguration(mcjty.rftools.blocks.shaper.ScannerConfiguration) EndergenicConfiguration(mcjty.rftools.blocks.endergen.EndergenicConfiguration) ScreenConfiguration(mcjty.rftools.blocks.screens.ScreenConfiguration) PowerCellConfiguration(mcjty.rftools.blocks.powercell.PowerCellConfiguration) BuilderConfiguration(mcjty.rftools.blocks.builder.BuilderConfiguration) Capability(net.minecraftforge.common.capabilities.Capability) EnumFacing(net.minecraft.util.EnumFacing) FavoriteDestinationsProperties(mcjty.rftools.playerprops.FavoriteDestinationsProperties) BuffProperties(mcjty.rftools.playerprops.BuffProperties) NBTBase(net.minecraft.nbt.NBTBase) ForgeEventHandlers(mcjty.rftools.ForgeEventHandlers) IModuleProvider(mcjty.rftools.api.screens.IModuleProvider) File(java.io.File)

Example 3 with Capability

use of net.minecraftforge.common.capabilities.Capability in project MC-Prefab by Brian-Wuest.

the class ItemBlockCapability method setTileEntityCapabilities.

/**
 * Transfers the capability data from this item to the tile entity.
 * @param world The world this is affecting.
 * @param player The controlling player.
 * @param pos The block pos of the placed block.
 * @param stack The item stack to set the tile entity capability for.
 * @param side The side for which to get the capability for.
 */
protected void setTileEntityCapabilities(World world, EntityPlayer player, BlockPos pos, ItemStack stack, EnumFacing side) {
    if (world.isRemote) {
        TileEntity tileEntity = world.getTileEntity(pos);
        if (tileEntity != null) {
            for (Capability capability : this.allowedCapabilities) {
                // Get the interfaces for this capability.
                Object stackCapability = stack.getCapability(capability, side);
                Object tileEntityCapability = tileEntity.getCapability(capability, side);
                if (stackCapability != null && tileEntityCapability != null && stackCapability instanceof ITransferable && tileEntityCapability instanceof ITransferable) {
                    // transfer the capability data, it's up to the capability to transfer the data.
                    ((ITransferable) tileEntityCapability).Transfer((ITransferable) stackCapability);
                }
            }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) Capability(net.minecraftforge.common.capabilities.Capability) ITransferable(com.wuest.prefab.Capabilities.ITransferable)

Example 4 with Capability

use of net.minecraftforge.common.capabilities.Capability in project Galacticraft by micdoodle8.

the class GCCapabilities method register.

public static void register() {
    CapabilityManager.INSTANCE.register(GCPlayerStats.class, new Capability.IStorage<GCPlayerStats>() {

        @Override
        public NBTBase writeNBT(Capability<GCPlayerStats> capability, GCPlayerStats instance, EnumFacing side) {
            NBTTagCompound nbt = new NBTTagCompound();
            instance.saveNBTData(nbt);
            return nbt;
        }

        @Override
        public void readNBT(Capability<GCPlayerStats> capability, GCPlayerStats instance, EnumFacing side, NBTBase nbt) {
            instance.loadNBTData((NBTTagCompound) nbt);
        }
    }, StatsCapability::new);
    CapabilityManager.INSTANCE.register(GCPlayerStatsClient.class, new Capability.IStorage<GCPlayerStatsClient>() {

        @Override
        public NBTBase writeNBT(Capability<GCPlayerStatsClient> capability, GCPlayerStatsClient instance, EnumFacing side) {
            return null;
        }

        @Override
        public void readNBT(Capability<GCPlayerStatsClient> capability, GCPlayerStatsClient instance, EnumFacing side, NBTBase nbt) {
        }
    }, StatsClientCapability::new);
}
Also used : Capability(net.minecraftforge.common.capabilities.Capability) EnumFacing(net.minecraft.util.EnumFacing) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) NBTBase(net.minecraft.nbt.NBTBase)

Example 5 with Capability

use of net.minecraftforge.common.capabilities.Capability in project ImmersiveEngineering by BluSunrize.

the class CapabilityShader method register.

public static void register() {
    CapabilityManager.INSTANCE.register(ShaderWrapper.class, new Capability.IStorage<ShaderWrapper>() {

        @Override
        public NBTBase writeNBT(Capability<ShaderWrapper> capability, ShaderWrapper instance, EnumFacing side) {
            NBTTagCompound nbt = new NBTTagCompound();
            ItemStack shader = instance.getShaderItem();
            if (!shader.isEmpty())
                shader.writeToNBT(nbt);
            else
                nbt.setString("IE:NoShader", "");
            nbt.setString("IE:ShaderType", instance.getShaderType());
            return nbt;
        }

        @Override
        public void readNBT(Capability<ShaderWrapper> capability, ShaderWrapper instance, EnumFacing side, NBTBase nbt) {
            NBTTagCompound tags = (NBTTagCompound) nbt;
            instance.setShaderType(tags.getString("IE:ShaderType"));
            if (!tags.hasKey("IE:NoShader"))
                instance.setShaderItem(new ItemStack(tags));
        }
    }, new Callable<ShaderWrapper>() {

        @Override
        public ShaderWrapper call() {
            return new ShaderWrapper_Direct("");
        }
    });
}
Also used : Capability(net.minecraftforge.common.capabilities.Capability) NBTBase(net.minecraft.nbt.NBTBase) EnumFacing(net.minecraft.util.EnumFacing) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack)

Aggregations

Capability (net.minecraftforge.common.capabilities.Capability)14 EnumFacing (net.minecraft.util.EnumFacing)8 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)7 NBTBase (net.minecraft.nbt.NBTBase)5 TileEntity (net.minecraft.tileentity.TileEntity)5 Nonnull (javax.annotation.Nonnull)4 Nullable (javax.annotation.Nullable)4 ItemStack (net.minecraft.item.ItemStack)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Block (net.minecraft.block.Block)3 BlockPos (net.minecraft.util.math.BlockPos)3 World (net.minecraft.world.World)3 ICapabilityProvider (net.minecraftforge.common.capabilities.ICapabilityProvider)3 Collectors (java.util.stream.Collectors)2 IBlockState (net.minecraft.block.state.IBlockState)2 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 Direction (net.minecraft.util.Direction)2 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)2 IBPPartBlock (com.bluepowermod.api.multipart.IBPPartBlock)1